I have an Ansible role where I need to create an inventory file on the remote machine. I want to use the current inventory file, but with one single group removed.
For example, if I have the following inventory:
[operator]
host1.example.com
[control]
host2.example.com
host3.example.com
[compute]
host4.example.com some_var=value
host5.example.com
# some comment
[foo:children]
control
compute
[bar:vars]
var1=value
#var2=value
Then I need something that copies this:
- hosts: operator
tasks:
- name: Create inventory
...
With the following result on host1.example.com
:
[control]
host2.example.com
host3.example.com
[compute]
host4.example.com some_var=value
host5.example.com
# some comment
[foo:children]
control
compute
[bar:vars]
var1=value
#var2=value
Split the current inventory file into two:
operator
group only,Copy only the latter to the target system.
You know that you can point to a directory containing multiple files as your inventory, right?