From ba78360c528df5c42cbb5a6c6b2e1f01ab9eace6 Mon Sep 17 00:00:00 2001 From: Pol Llovet Date: Thu, 30 May 2013 14:12:23 -0600 Subject: [PATCH] Remove inline comments from inventory tokenizing. --- lib/ansible/inventory/ini.py | 4 ++-- test/inventory_dir/3comments | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 test/inventory_dir/3comments diff --git a/lib/ansible/inventory/ini.py b/lib/ansible/inventory/ini.py index 78d5743fa3..314f2c7cd9 100644 --- a/lib/ansible/inventory/ini.py +++ b/lib/ansible/inventory/ini.py @@ -65,7 +65,7 @@ class InventoryParser(object): for line in self.lines: if line.startswith("["): - active_group_name = line.replace("[","").replace("]","").strip() + active_group_name = line.split("#")[0].replace("[","").replace("]","").strip() if line.find(":vars") != -1 or line.find(":children") != -1: active_group_name = active_group_name.rsplit(":", 1)[0] if active_group_name not in self.groups: @@ -78,7 +78,7 @@ class InventoryParser(object): elif line.startswith("#") or line == '': pass elif active_group_name: - tokens = shlex.split(line) + tokens = shlex.split(line.split("#")[0]) if len(tokens) == 0: continue hostname = tokens[0] diff --git a/test/inventory_dir/3comments b/test/inventory_dir/3comments new file mode 100644 index 0000000000..02ff6ec000 --- /dev/null +++ b/test/inventory_dir/3comments @@ -0,0 +1,8 @@ +[major-god] # group with inline comments +zeus var_a=1 # host with inline comments +# A comment +thor + +[minor-god] # group with inline comment and unbalanced quotes: ' " +morpheus # host with inline comments and unbalanced quotes: ' " +# A comment with unbalanced quotes: ' "