Ansible - Post - 5 - Ansible Group Creation:
In this blog post, we will see how to create the ansible groups, Ansible groups are used for grouping servers / systems under one group , so the set of servers can be targeted at the same time.
First lets run vagrant up to ensure that the servers are up and running.
Logon to the acs (ansible control server ) box
Change directory to demo1 and create the inventory file as below, you can see that I have given the password in open text which is not advisable, just for testing purposes I have given the open password here, you can use private key file or the ansible vault to secure the password, which will see later in the upcoming posts.
web1 ansible_ssh_host=192.168.33.20 ansible_ssh_user=vagrant ansible_ssh_pass=vagrant
db1 ansible_ssh_host=192.168.33.30 ansible_ssh_user=vagrant ansible_ssh_pass=vagrant
The square brackets indicate the groups , anything below the square bracket is considered as a server/system, if you want to group the groups, you need to use the children keyword inside the square brackets, then ansible will read them as groups instead of systems.
If you have common parameters that apply to a group, you can use the vars keyword for the group and move the parameters there, here I have moved the login credential parametrs under the [datacentre:vars]
Now let’s try pinging the servers in the group datacentre and db1.
ansible datacenter -i inventory -m ping
ansible db1 -i inventory -m ping
It works as expected.
Thanks for viewing the post, please post your comments below.
Please Like & Follow us on Facebook & Twitter,