|
|
@ -161,13 +161,16 @@ class InventoryData(object):
|
|
|
|
def add_group(self, group):
|
|
|
|
def add_group(self, group):
|
|
|
|
''' adds a group to inventory if not there already '''
|
|
|
|
''' adds a group to inventory if not there already '''
|
|
|
|
|
|
|
|
|
|
|
|
if group not in self.groups:
|
|
|
|
if group:
|
|
|
|
g = Group(group)
|
|
|
|
if group not in self.groups:
|
|
|
|
self.groups[group] = g
|
|
|
|
g = Group(group)
|
|
|
|
self._groups_dict_cache = {}
|
|
|
|
self.groups[group] = g
|
|
|
|
display.debug("Added group %s to inventory" % group)
|
|
|
|
self._groups_dict_cache = {}
|
|
|
|
|
|
|
|
display.debug("Added group %s to inventory" % group)
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
display.debug("group %s already in inventory" % group)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
display.debug("group %s already in inventory" % group)
|
|
|
|
raise AnsibleError("Invalid empty/false group name provided: %s" % group)
|
|
|
|
|
|
|
|
|
|
|
|
def remove_group(self, group):
|
|
|
|
def remove_group(self, group):
|
|
|
|
|
|
|
|
|
|
|
@ -183,38 +186,41 @@ class InventoryData(object):
|
|
|
|
def add_host(self, host, group=None, port=None):
|
|
|
|
def add_host(self, host, group=None, port=None):
|
|
|
|
''' adds a host to inventory and possibly a group if not there already '''
|
|
|
|
''' adds a host to inventory and possibly a group if not there already '''
|
|
|
|
|
|
|
|
|
|
|
|
g = None
|
|
|
|
if host:
|
|
|
|
if group:
|
|
|
|
g = None
|
|
|
|
if group in self.groups:
|
|
|
|
if group:
|
|
|
|
g = self.groups[group]
|
|
|
|
if group in self.groups:
|
|
|
|
else:
|
|
|
|
g = self.groups[group]
|
|
|
|
raise AnsibleError("Could not find group %s in inventory" % group)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if host not in self.hosts:
|
|
|
|
|
|
|
|
h = Host(host, port)
|
|
|
|
|
|
|
|
self.hosts[host] = h
|
|
|
|
|
|
|
|
if self.current_source: # set to 'first source' in which host was encountered
|
|
|
|
|
|
|
|
self.set_variable(host, 'inventory_file', self.current_source)
|
|
|
|
|
|
|
|
self.set_variable(host, 'inventory_dir', basedir(self.current_source))
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
self.set_variable(host, 'inventory_file', None)
|
|
|
|
|
|
|
|
self.set_variable(host, 'inventory_dir', None)
|
|
|
|
|
|
|
|
display.debug("Added host %s to inventory" % (host))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# set default localhost from inventory to avoid creating an implicit one. Last localhost defined 'wins'.
|
|
|
|
|
|
|
|
if host in C.LOCALHOST:
|
|
|
|
|
|
|
|
if self.localhost is None:
|
|
|
|
|
|
|
|
self.localhost = self.hosts[host]
|
|
|
|
|
|
|
|
display.vvvv("Set default localhost to %s" % h)
|
|
|
|
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
display.warning("A duplicate localhost-like entry was found (%s). First found localhost was %s" % (h, self.localhost.name))
|
|
|
|
raise AnsibleError("Could not find group %s in inventory" % group)
|
|
|
|
else:
|
|
|
|
|
|
|
|
h = self.hosts[host]
|
|
|
|
if host not in self.hosts:
|
|
|
|
|
|
|
|
h = Host(host, port)
|
|
|
|
|
|
|
|
self.hosts[host] = h
|
|
|
|
|
|
|
|
if self.current_source: # set to 'first source' in which host was encountered
|
|
|
|
|
|
|
|
self.set_variable(host, 'inventory_file', self.current_source)
|
|
|
|
|
|
|
|
self.set_variable(host, 'inventory_dir', basedir(self.current_source))
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
self.set_variable(host, 'inventory_file', None)
|
|
|
|
|
|
|
|
self.set_variable(host, 'inventory_dir', None)
|
|
|
|
|
|
|
|
display.debug("Added host %s to inventory" % (host))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# set default localhost from inventory to avoid creating an implicit one. Last localhost defined 'wins'.
|
|
|
|
|
|
|
|
if host in C.LOCALHOST:
|
|
|
|
|
|
|
|
if self.localhost is None:
|
|
|
|
|
|
|
|
self.localhost = self.hosts[host]
|
|
|
|
|
|
|
|
display.vvvv("Set default localhost to %s" % h)
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
display.warning("A duplicate localhost-like entry was found (%s). First found localhost was %s" % (h, self.localhost.name))
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
h = self.hosts[host]
|
|
|
|
|
|
|
|
|
|
|
|
if g:
|
|
|
|
if g:
|
|
|
|
g.add_host(h)
|
|
|
|
g.add_host(h)
|
|
|
|
self._groups_dict_cache = {}
|
|
|
|
self._groups_dict_cache = {}
|
|
|
|
display.debug("Added host %s to group %s" % (host, group))
|
|
|
|
display.debug("Added host %s to group %s" % (host, group))
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
raise AnsibleError("Invalid empty host name provided: %s" % host)
|
|
|
|
|
|
|
|
|
|
|
|
def remove_host(self, host):
|
|
|
|
def remove_host(self, host):
|
|
|
|
|
|
|
|
|
|
|
|