You just need to follow below steps:
$ sudo apt-get update && sudo apt-get install software-properties-common
$ sudo apt-add-repository ppa:ansible/ansible
$ sudo apt-get update && sudo apt-get install ansible
Configuring Ansible Hosts
Ansible keeps track of all of the servers that it knows about through a “hosts” file. We need to set up this file first before we can begin to communicate with our other computers.
Open the file with root privileges like this:
You will see a file that has a lot of example configurations, none of which will actually work for us since these hosts are made up. So to start, let’s comment out all of the lines in this file by adding a “#” before each line.
We will keep these examples in the file to help us with configuration if we want to implement more complex scenarios in the future.
Once all of the lines are commented out, we can begin adding our actual hosts.
The hosts file is fairly flexible and can be configured in a few different ways. The syntax we are going to use though looks something like this:
Example hosts file
The group_name is an organizational tag that lets you refer to any servers listed under it with one word. The alias is just a name to refer to that server.
So in our scenario, we are imagining that we have three servers we are going to control with Ansible. These servers are accessible from the Ansible droplet by typing:
You should not be prompted for a password if you have set this up correctly. We will assume that our droplets’ IP addresses are 172.0.12.1, 172.0.12.2, and 172.0.12.3. We will set this up so that we can refer to these individually as host1, host2, and host3, or as a group as droplets.
This is the block that we should add to our hosts file to accomplish this:
[droplets]
host1 ansible_ssh_host=172.0.12.1
host2 ansible_ssh_host=172.0.12.2
host3 ansible_ssh_host=172.0.10.3
Hosts can be in multiple groups and groups can configure parameters for all of their members. Let’s try this out now.
With our current settings, if we tried to connect to any of these hosts with Ansible, the command would fail (assuming you are not operating as the root user). This is because your SSH key is embedded for the root user on the remote systems and Ansible will by default try to connect as your current user. A connection attempt will get this error:
Ansible connection error
On my Ansible computer, I’m using a user called demo. Ansible will try to connect to each host with ssh demo@server. This will not work if the demo user is not on the remote system.
We can create a file that tells all of the servers in the “droplets” group to connect using the root user.
To do this, we will create a directory in the Ansible configuration structure called group_vars. Within this folder, we can create YAML-formatted files for each group we want to configure:
We can put our configuration in here. YAML files start with “—”, so make sure you don’t forget that part.
/etc/ansible/group_vars/droplets
Save and close this file when you are finished.
If you want to specify configuration details for every server, regardless of group association, you can put those details in a file at /etc/ansible/group_vars/all. Individual hosts can be configured by creating files under a directory at /etc/ansible/host_vars.
Thanks for the information.
ReplyDeletehttps://www.igrowsoft.com/sap-grc-training-in-hyderabad.php