From e09436ee0c2dcba6054ddaefeaa9a3712fcb0aa4 Mon Sep 17 00:00:00 2001 From: Chris Meyers Date: Tue, 27 Jan 2015 14:56:03 -0500 Subject: [PATCH] inventory_import behave more like ansible ``` mkdir inv echo foo > inv/hosts mkdir inv/host_vars touch inv/host_vars/foo touch inv/host_vars/foo.yml ``` ``` ansible -i ./inv -c local -m ping all ``` ``` tower-mange inventory_import --inventory-id=1 ./inv ``` The tower command above now throws an error similar to ansible: `Multiple variable files found. There should only be one.` --- awx/main/management/commands/inventory_import.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/awx/main/management/commands/inventory_import.py b/awx/main/management/commands/inventory_import.py index 8455f92bef..09c8f24c4b 100644 --- a/awx/main/management/commands/inventory_import.py +++ b/awx/main/management/commands/inventory_import.py @@ -55,12 +55,16 @@ class MemObject(object): def load_vars(self, base_path): all_vars = {} + files_found = 0 for suffix in ('', '.yml', '.yaml', '.json'): path = ''.join([base_path, suffix]) if not os.path.exists(path): continue if not os.path.isfile(path): continue + files_found += 1 + if files_found > 1: + raise RuntimeError('Multiple variable files found. There should only be one. %s ' % self.name) vars_name = os.path.basename(os.path.dirname(path)) logger.debug('Loading %s from %s', vars_name, path) try: