Skip to content

Instantly share code, notes, and snippets.

@juanpablocs
Last active June 3, 2018 18:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juanpablocs/98c72cb52f1555d121f50393926a538b to your computer and use it in GitHub Desktop.
Save juanpablocs/98c72cb52f1555d121f50393926a538b to your computer and use it in GitHub Desktop.
create first connection with ansible and ubuntu

Install Ansible

add repository

sudo apt-add-repository ppa:ansible/ansible
sudo apt-get update
sudo apt-get install ansible

Add server to ansible host

vim /etc/ansible/hosts

add your server (optional group) and replace your-ip, your-user

[mygroup]
your-ip ansible_user=your-user

Ssh key add to server

ssh-copy-id your-user@your-ip

Test connection

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: 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment