Ansible Day 2 - Inventory File

Ansible Day 2 - Inventory File

In the previous article we went through the "configuration file". In this configuration file, you can look for a key=value called, "inventory" under "[defaults]" section, which let the ansible know, from where it will read the inventory details.


Example -> of the entry from "ansible.cfg"

# (pathlist) Comma separated list of Ansible inventory sources
inventory=/etc/ansible/hosts        

This dictionary ( key and value) let you know, which file or directory (the files, within the directory, containing the system details), ansible will look upon to work within



In the "Ansible Day 1 - Configuration File" article, we have gone through, why ansible is acting so, now lets go through, on which system, ansible acting upon. This is where the "inventory" details comes in.



Ansible Inventory type:

Although you can pass the host names at the command line, its always good to have inventory files.


The default location for this file is "/etc/ansible/hosts", which you can update in your "ansible.cfg", as shown in the above example.
Or you can update your related "ansible.cfg" file.
Or you can use "-i <path>" options.


Ansible have two type of Inventory:

Static inventory

  • You can create a Static inventory updating the details about the systems you want your ansible to work upon.


Dynamic inventory

  • You can also create a dynamic inventory. So that it can manage your dynamic infrastructure.



Organising inventory in a directory

You can also create a directory, having multiple inventory files. (Which can have both static inventory or dynamic inventory too.)


inventory/
  openstack.yml          # configure inventory plugin to get hosts 
  dynamic-inventory.py   # add additional hosts with script
  on-prem                # add static hosts and groups
  parent-groups          # add static hosts and groups        


And later you can use as:

ansible-playbook your_play.yml -i inventory        


Few commands of jargon would be new for now , which we will cover in upcoming articles.




Ansible inventory file type:

Now that we got some idea, I.e having both dynamic and static type of inventory file, lets have a quick understanding of the "inventory file format".


The inventory file can be composed in two different format.

An ini type of format:

Example

mail.example.com

[webservers]
foo.example.com
bar.example.com

[dbservers]
one.example.com
two.example.com
three.example.com        

And, A YAML type of format:

Example

ungrouped:
  hosts:
    mail.example.com:
webservers:
  hosts:
    foo.example.com:
    bar.example.com:
dbservers:
  hosts:
    one.example.com:
    two.example.com:
    three.example.com:        

Keeping inventory Simple

Remember, this is just day 2, lets start with a simple way...


Reaching out just 6 hosts (level1)

vi /etc/ansible/hosts (You can further create your own dynamic inventory file too.)

192.168.11.11
192.168.11.12
192.168.11.13
192.168.11.21
192.168.11.22
192.168.11.23
192.168.11.24        

From the above entries, we have just configured 7 hosts. ( nothing else).



要查看或添加评论,请登录

Amit Mund的更多文章

  • Trick Question 1

    Trick Question 1

    Question: What is the difference between the following two code. vs Answer(s) Few of the best answers from the comment…

  • python code - know your time

    python code - know your time

    Some time, its good know, how much time your code is taking..

  • python code - json dump

    python code - json dump

    A sample code, to walk through to understand the "os.walk" method to traverse through the directory and sub-directories…

  • Ansible Day 1 - Configuration File (ansible.cfg)

    Ansible Day 1 - Configuration File (ansible.cfg)

    ansible.cfg If your search string is ansible, then probably you do know what ansible is.

  • Linux Day 1 - Understanding ls -l output part 1

    Linux Day 1 - Understanding ls -l output part 1

    ls probably the first linux command we might be using. In most of the case it get explained in just 1 following line:…

  • Lets Learn

    Lets Learn

    Sharing is the best way of learning. I believe in this, because we have awesome people like you, who will guide me…

    1 条评论

社区洞察

其他会员也浏览了