mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Merge pull request #3067 from pol/devel
Remove inline comments from inventory tokenizing.
This commit is contained in:
commit
b8630d2bc4
2 changed files with 10 additions and 2 deletions
|
@ -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]
|
||||
|
|
8
test/inventory_dir/3comments
Normal file
8
test/inventory_dir/3comments
Normal file
|
@ -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: ' "
|
Loading…
Reference in a new issue