mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-25 22:30:22 -07:00
Allow for updating host vars in add_host
This commit is contained in:
parent
1688139cb5
commit
52aea868df
1 changed files with 12 additions and 7 deletions
|
@ -56,20 +56,25 @@ class ActionModule(object):
|
||||||
new_name, new_port = new_name.split(":")
|
new_name, new_port = new_name.split(":")
|
||||||
args['ansible_ssh_port'] = new_port
|
args['ansible_ssh_port'] = new_port
|
||||||
|
|
||||||
# create host and get inventory
|
# redefine inventory and get group "all"
|
||||||
new_host = Host(new_name)
|
|
||||||
inventory = self.runner.inventory
|
inventory = self.runner.inventory
|
||||||
|
allgroup = inventory.get_group('all')
|
||||||
|
|
||||||
|
# check if host in cache, add if not
|
||||||
|
if new_name in inventory._hosts_cache:
|
||||||
|
new_host = inventory._hosts_cache[new_name]
|
||||||
|
else:
|
||||||
|
new_host = Host(new_name)
|
||||||
|
# only groups can be added directly to inventory
|
||||||
|
inventory._hosts_cache[new_name] = new_host
|
||||||
|
allgroup.add_host(new_host)
|
||||||
|
|
||||||
# Add any variables to the new_host
|
# Add any variables to the new_host
|
||||||
for k in args.keys():
|
for k in args.keys():
|
||||||
if not k in [ 'name', 'hostname', 'groupname', 'groups' ]:
|
if not k in [ 'name', 'hostname', 'groupname', 'groups' ]:
|
||||||
new_host.set_variable(k, args[k])
|
new_host.set_variable(k, args[k])
|
||||||
|
|
||||||
|
|
||||||
# add the new host to the 'all' group
|
|
||||||
allgroup = inventory.get_group('all')
|
|
||||||
allgroup.add_host(new_host)
|
|
||||||
|
|
||||||
groupnames = args.get('groupname', args.get('groups', ''))
|
groupnames = args.get('groupname', args.get('groups', ''))
|
||||||
# add it to the group if that was specified
|
# add it to the group if that was specified
|
||||||
if groupnames != '':
|
if groupnames != '':
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue