Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove inline comments from inventory tokenizing. #3067

Merged
merged 1 commit into from
May 30, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/ansible/inventory/ini.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def _parse_base_groups(self):

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:
Expand All @@ -78,7 +78,7 @@ def _parse_base_groups(self):
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]
Expand Down
8 changes: 8 additions & 0 deletions test/inventory_dir/3comments
Original file line number Diff line number Diff line change
@@ -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: ' "