Hello
Thanks for visiting RvKmR.blogspot.in
In this blog post, I am explaining about ansible inventory.
While working with ansible we need to provide inventory to ansible commands.
We may have ansible inventory structure as like below. There can be some tasks that you wish to perform on all of the inventory. But it is difficult to collect or merge these into one file.
Lets do it ...
level1/
├── level2-0
│ └── inventory
│ ├── server01
│ ├── server02
│ ├── server03
│ ├── server04
│ ├── server05
│ ├── server06
│ ├── server07
│ ├── server08
│ ├── server09
│ └── server10
├── level2-1
│ └── inventory
│ ├── server11
│ ├── server12
│ ├── server13
│ ├── server14
│ ├── server15
│ ├── server16
│ ├── server17
│ ├── server18
│ ├── server19
│ └── server20
└── level2-2
└── inventory
├── server21
├── server22
├── server23
├── server24
├── server25
├── server26
├── server27
├── server28
├── server29
└── server30
But we may need it in like all={[file1,file2......file30]}
So for that we can do that it like as below. Your inventory will be in host.ini
echo "all={[" >> host.ini;
ls -l level1/*/inventory/ | awk '{print $9","}' | grep -v '^$' | grep -v '^,'>> host.ini;
echo "]}" >> host.ini
Thanks for visiting RvKmR.blogspot.in
In this blog post, I am explaining about ansible inventory.
While working with ansible we need to provide inventory to ansible commands.
We may have ansible inventory structure as like below. There can be some tasks that you wish to perform on all of the inventory. But it is difficult to collect or merge these into one file.
Lets do it ...
level1/
├── level2-0
│ └── inventory
│ ├── server01
│ ├── server02
│ ├── server03
│ ├── server04
│ ├── server05
│ ├── server06
│ ├── server07
│ ├── server08
│ ├── server09
│ └── server10
├── level2-1
│ └── inventory
│ ├── server11
│ ├── server12
│ ├── server13
│ ├── server14
│ ├── server15
│ ├── server16
│ ├── server17
│ ├── server18
│ ├── server19
│ └── server20
└── level2-2
└── inventory
├── server21
├── server22
├── server23
├── server24
├── server25
├── server26
├── server27
├── server28
├── server29
└── server30
But we may need it in like all={[file1,file2......file30]}
So for that we can do that it like as below. Your inventory will be in host.ini
echo "all={[" >> host.ini;
ls -l level1/*/inventory/ | awk '{print $9","}' | grep -v '^$' | grep -v '^,'>> host.ini;
echo "]}" >> host.ini
Comments
Post a Comment