Skip to content

Instantly share code, notes, and snippets.

@yokodev
Last active November 29, 2019 22:51
Show Gist options
  • Save yokodev/c18e756ba2247b253962043566fa7b49 to your computer and use it in GitHub Desktop.
Save yokodev/c18e756ba2247b253962043566fa7b49 to your computer and use it in GitHub Desktop.
Ansible First steps
1)Download and install ansible
*sudo apt install python-argcomplete
*sudo activate-global-python-argcomplete
*Login-logout
2)Create a local folder with ansible.cfg and hosts files
3)Modify ansible.cfg so the inventory now points to the new local folder instead of the default place (/ect/ansible/hosts)
[defaults]
inventory = /any/local/path/hosts
4)Modify hosts file and add as many servers you would like to interact with
[pdbs]
terrahost-db1
terrahost-db2
terrahost-db3
[ptomcats]
terrahost-tomcat1
terrahost-tomcat2
terrahost-tomcat3
5)Create ssh key file on your main node(from which you plan to control everything)
6)Copy the sshkey (.pub) to all the servers you plan to interact with. So in the remote server this file would be under ~/.ssh/authorized_keys file
Make sure the pub key is an entry in this file.
Terraform{
https://stackoverflow.com/questions/38645002/how-to-add-an-ssh-key-to-an-gcp-instance-using-terraform
}
7)At this point there should be no problems sshing into any server from the master node.
8)Make sure Python is installed on your servers otherwise you might get odd results.
sudo apt-get install python-minimal -y
Small Test
From the same local folder where your ansible.cfg file is run the following
9) ansible -m ping all
You should see something like this
terrahost-db2 | SUCCESS => {
"changed": false,
"ping": "pong"
}
terrahost-tomcat2 | SUCCESS => {
"changed": false,
"ping": "pong"
}
terrahost-db1 | SUCCESS => {
"changed": false,
"ping": "pong"
}
terrahost-tomcat1 | SUCCESS => {
"changed": false,
"ping": "pong"
}
That's it
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment