add repository
sudo apt-add-repository ppa:ansible/ansible
sudo apt-get update
sudo apt-get install ansible
vim /etc/ansible/hosts
add your server (optional group) and replace your-ip
, your-user
[mygroup]
your-ip ansible_user=your-user
ssh-copy-id your-user@your-ip
To test that a server responds correctly use the ping module. Connect to mygroup
or all
(replace mygroup
for another name)
ansible -m ping mygroup
output success
your-ip | SUCCESS => {
"changed": false,
"ping": "pong"
}
The shell module lets us send a terminal command to the remote host and retrieve the results. For instance, to find out the memory usage on our mygroup
, we could use:
ansible -m shell -a 'free -m' mygroup
output
your-ip | SUCCESS | rc=0 >>
total used free shared buff/cache available
Mem: 992 96 324 12 570 719
Swap: