Ansible is an automation
tool which works for multiple systems in a infrastructure at the same time. So
we should have system lists to manage it. We call that as inventory. Ansible
inventory file has the list of all managed hosts names one line per host.
By default, this ansible
host inventory file is located under /etc/ansible/hosts. Hence if you run a
Ansible playbook or Ansible Ad-hoc commands, that will look the hosts groups
under the default group file. You can specify a different inventory file using
the “-i <path>” option on the
command line as shown below.
ansible-playbook –i /opt/database_server install.yml
To authenticate to remote
servers we may need to enable password less authentication between control and
slave machines or we may need to pass password from cli.
Hosts
group declaration:
We can declare the different
groups in single host inventory file. For example, if you have database and web
servers, then we can declare the list of server names under each groups.
[database-servers]
host1.database
host2.database
[web-servers]
Web1.webapp
Web2.webapp
Note: A host can be in more
than one group.
Inventory
file parameters
By default ansible works on
SSH port number 22. If you have different port to connect the
hosts, then
define the hosts as below.
Web1.webapp:2209
We can also define the
connection type and also user depends on target hosts.
[web-servers]
Web1.webapp
ansible_connection=ssh ansible_user=vagrant
Web2.webapp
ansible_connection=ssh ansible_user=vagrant
ansible.cfg file
The ansible configuration
file has many parameters like inventory file location, library location,
modules and etc. All these default values are commented. If you wanted to
change the default behaviour of any parameter, Just uncomment and change the
value.
Changes can be made and used in a configuration
file which will be searched for in the following order:
- ANSIBLE_CONFIG (environment variable if
set)
- ansible.cfg (in the current directory)
- ~/.ansible.cfg (in the home directory)
- /etc/ansible/ansible.cfg
<< Previous Next >>
No comments:
Post a Comment