Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
ansible
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
ansible
Commits
94a7fb60
Commit
94a7fb60
authored
Mar 05, 2014
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow escaped comments in inventory files.
parent
4e8ed921
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
1 deletions
+34
-1
lib/ansible/inventory/ini.py
+2
-1
lib/ansible/utils/__init__.py
+9
-0
test/units/TestUtils.py
+23
-0
No files found.
lib/ansible/inventory/ini.py
View file @
94a7fb60
...
@@ -23,6 +23,7 @@ from ansible.inventory.group import Group
...
@@ -23,6 +23,7 @@ from ansible.inventory.group import Group
from
ansible.inventory.expand_hosts
import
detect_range
from
ansible.inventory.expand_hosts
import
detect_range
from
ansible.inventory.expand_hosts
import
expand_hostname_range
from
ansible.inventory.expand_hosts
import
expand_hostname_range
from
ansible
import
errors
from
ansible
import
errors
from
ansible
import
utils
import
shlex
import
shlex
import
re
import
re
import
ast
import
ast
...
@@ -65,7 +66,7 @@ class InventoryParser(object):
...
@@ -65,7 +66,7 @@ class InventoryParser(object):
active_group_name
=
'ungrouped'
active_group_name
=
'ungrouped'
for
line
in
self
.
lines
:
for
line
in
self
.
lines
:
line
=
line
.
split
(
"#"
)[
0
]
.
strip
()
line
=
utils
.
before_comment
(
line
)
.
strip
()
if
line
.
startswith
(
"["
)
and
line
.
endswith
(
"]"
):
if
line
.
startswith
(
"["
)
and
line
.
endswith
(
"]"
):
active_group_name
=
line
.
replace
(
"["
,
""
)
.
replace
(
"]"
,
""
)
active_group_name
=
line
.
replace
(
"["
,
""
)
.
replace
(
"]"
,
""
)
if
line
.
find
(
":vars"
)
!=
-
1
or
line
.
find
(
":children"
)
!=
-
1
:
if
line
.
find
(
":vars"
)
!=
-
1
or
line
.
find
(
":children"
)
!=
-
1
:
...
...
lib/ansible/utils/__init__.py
View file @
94a7fb60
...
@@ -1071,3 +1071,12 @@ def random_password(length=20, chars=C.DEFAULT_PASSWORD_CHARS):
...
@@ -1071,3 +1071,12 @@ def random_password(length=20, chars=C.DEFAULT_PASSWORD_CHARS):
password
.
append
(
new_char
)
password
.
append
(
new_char
)
return
''
.
join
(
password
)
return
''
.
join
(
password
)
def
before_comment
(
msg
):
''' what's the part of a string before a comment? '''
msg
=
msg
.
replace
(
"
\
#"
,
"**NOT_A_COMMENT**"
)
msg
=
msg
.
split
(
"#"
)[
0
]
msg
=
msg
.
replace
(
"**NOT_A_COMMENT**"
,
"#"
)
return
msg
test/units/TestUtils.py
View file @
94a7fb60
...
@@ -16,6 +16,29 @@ sys.setdefaultencoding("utf8")
...
@@ -16,6 +16,29 @@ sys.setdefaultencoding("utf8")
class
TestUtils
(
unittest
.
TestCase
):
class
TestUtils
(
unittest
.
TestCase
):
def
test_before_comment
(
self
):
''' see if we can detect the part of a string before a comment. Used by INI parser in inventory '''
input
=
"before # comment"
expected
=
"before "
actual
=
ansible
.
utils
.
before_comment
(
input
)
assert
expected
==
actual
input
=
"before
\
# not a comment"
expected
=
"before # not a comment"
actual
=
ansible
.
utils
.
before_comment
(
input
)
assert
expected
==
actual
input
=
""
expected
=
""
actual
=
ansible
.
utils
.
before_comment
(
input
)
assert
expected
==
actual
input
=
"#"
expected
=
""
actual
=
ansible
.
utils
.
before_comment
(
input
)
assert
expected
==
actual
#####################################
#####################################
### check_conditional tests
### check_conditional tests
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment