Skip to content

Ansible

Usage

Pinging all hosts:

ansible -i hosts all -m ping

Ping specific group:

ansible -i hosts <group_name> -m ping

Execute commands on all hosts

ansible -i hosts -a "/bin/echo hello"

Execute playbook

ansible-playbook -i hosts playbook.yaml

Using pip to install the requests library

ansible -i hosts all -m pip "name=requests"

Sample Hosts file

[production]
test_machine ansible_host=1.1.1.1 ansible_user=ubuntu ansible_port=22 ansible_ssh_private_key=<path_to_key>