Home Ansible creating a inventory list
Post
Cancel

Ansible creating a inventory list

Create a inventory.yml file in your users ansible file

1
vim inventory.yml

And use the layout below.

  • All yaml files start with —
  • all: – All server will be in this group.
  • children: –Is saying that there a another group within all:
  • linux: – This is the group name that you want to call your group.
  • host: – Is the hosts that belong to this group.

In the example below:

  • All server are in the all: group.
  • The all: group has a group inside it called linux.
  • The group linux also have it’s own groups call ubuntu and centos.
  • www is another group that is sits in line with the linux group
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
---
all:
  children:
    linux:
      children:
        debian:
          hosts:
            example1.domain.com:
            example2.domain.com:
            
        rhel:
          hosts:
            example3.vog.com
    www:
     hosts:
       example2.domain.com:
       example3.domain.com:

To view the host user the following command

1
ansible linux --list-hosts -i inventory.yml

Further reading

This post is licensed under CC BY 4.0 by the author.