Add option to remove group from inventory
Added `-d` option to inventory-manage.py that will remove provided group from the inventory. It won't touch conf.d so you need to remove entry from there before re-running dynamic_inventory Depends-On: https://review.opendev.org/c/openstack/openstack-ansible-galera_server/+/791107 Change-Id: I665ae5ce999c36d8d999ed5f9d659095a900d9eb Closes-Bug: #1642051
This commit is contained in:
parent
9a5bef9a8c
commit
13fcd09b0b
@ -43,6 +43,15 @@ Use the host's name as an argument.
|
|||||||
|
|
||||||
.. _`dynamic inventory functionality`: https://docs.ansible.com/ansible/intro_dynamic_inventory.html
|
.. _`dynamic inventory functionality`: https://docs.ansible.com/ansible/intro_dynamic_inventory.html
|
||||||
|
|
||||||
|
Removing a group
|
||||||
|
~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
A host group can be removed with the ``--remove-group/-d`` parameter.
|
||||||
|
|
||||||
|
Use the groups's name as an argument. You can repeat argument multiple times
|
||||||
|
to remove several groups at once.
|
||||||
|
|
||||||
|
|
||||||
Exporting host information
|
Exporting host information
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
@ -58,6 +58,14 @@ def args():
|
|||||||
action='append',
|
action='append',
|
||||||
default=[]
|
default=[]
|
||||||
)
|
)
|
||||||
|
exclusive_action.add_argument(
|
||||||
|
'-d',
|
||||||
|
'--remove-group',
|
||||||
|
help='group name to remove from inventory, this can be used multiple'
|
||||||
|
' times.',
|
||||||
|
action='append',
|
||||||
|
default=[]
|
||||||
|
)
|
||||||
exclusive_action.add_argument(
|
exclusive_action.add_argument(
|
||||||
'-l',
|
'-l',
|
||||||
'--list-host',
|
'--list-host',
|
||||||
@ -310,6 +318,16 @@ def remove_ip_addresses(inventory, filepath=None):
|
|||||||
filesys.save_inventory(inventory_json, filepath)
|
filesys.save_inventory(inventory_json, filepath)
|
||||||
|
|
||||||
|
|
||||||
|
def remove_inventory_group(remove_group, inventory, filepath=None):
|
||||||
|
for group in remove_group:
|
||||||
|
inventory.pop(group, None)
|
||||||
|
|
||||||
|
if filepath is not None:
|
||||||
|
inventory_json = json.dumps(inventory, indent=2,
|
||||||
|
separators=(',', ': '))
|
||||||
|
filesys.save_inventory(inventory_json, filepath)
|
||||||
|
|
||||||
|
|
||||||
def remove_inventory_item(remove_item, inventory, filepath=None):
|
def remove_inventory_item(remove_item, inventory, filepath=None):
|
||||||
"""Removes inventory item from the inventory dictionary
|
"""Removes inventory item from the inventory dictionary
|
||||||
|
|
||||||
@ -350,6 +368,9 @@ def main():
|
|||||||
elif user_args['clear_ips'] is True:
|
elif user_args['clear_ips'] is True:
|
||||||
remove_ip_addresses(inventory, filepath)
|
remove_ip_addresses(inventory, filepath)
|
||||||
print('Success. . .')
|
print('Success. . .')
|
||||||
|
elif user_args['remove_group']:
|
||||||
|
remove_inventory_group(user_args['remove_group'], inventory, filepath)
|
||||||
|
print('Success. . .')
|
||||||
else:
|
else:
|
||||||
remove_inventory_item(user_args['remove_item'], inventory, filepath)
|
remove_inventory_item(user_args['remove_item'], inventory, filepath)
|
||||||
print('Success. . .')
|
print('Success. . .')
|
||||||
|
Loading…
Reference in New Issue
Block a user