From 7306f93cf9be6ed701ce16c9e1fd16ca748602df Mon Sep 17 00:00:00 2001 From: Michael DeHaan Date: Sun, 14 Jul 2013 14:15:52 -0400 Subject: [PATCH] Allow hostname:portnum in inventory files to be used as shorthand for the importer. --- awx/main/management/commands/inventory_import.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/awx/main/management/commands/inventory_import.py b/awx/main/management/commands/inventory_import.py index e2a1fb17fb..84b2a76c87 100644 --- a/awx/main/management/commands/inventory_import.py +++ b/awx/main/management/commands/inventory_import.py @@ -98,11 +98,20 @@ class MemHost(object): LOGGER.debug("adding host name: %s" % name) assert name is not None assert inventory_base is not None - # FIXME: set ansible_ssh_port if ":" in name + + # set ansible_ssh_port if ":" in name self.name = name self.variables = {} self.inventory_base = inventory_base - + + if name.find(":") != -1: + tokens = name.split(":") + self.name = tokens[0] + self.variables['ansible_ssh_port'] = tokens[1] + + if "[" in name: + raise ImportException("block ranges like host[0:50].example.com are not yet supported by the importer") + host_vars = os.path.join(inventory_base, 'host_vars', name) if os.path.exists(host_vars): LOGGER.debug("loading host_vars")