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
38abd5e2
Commit
38abd5e2
authored
Mar 05, 2014
by
Richard C Isaacson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Break this out into a reusable function and document regex shortcomings.
parent
49bd8b0b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
21 deletions
+37
-21
lib/ansible/inventory/ini.py
+2
-21
lib/ansible/utils/__init__.py
+35
-0
No files found.
lib/ansible/inventory/ini.py
View file @
38abd5e2
...
@@ -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
import
ansible.utils
as
utils
import
shlex
import
shlex
import
re
import
re
import
ast
import
ast
...
@@ -68,27 +69,7 @@ class InventoryParser(object):
...
@@ -68,27 +69,7 @@ class InventoryParser(object):
# Split off any comments that are not contained in a variable.
# Split off any comments that are not contained in a variable.
if
"#"
in
line
:
if
"#"
in
line
:
split_line
=
line
.
split
(
"#"
)
line
=
utils
.
split_unquoted_hash
(
line
)
instances
=
len
(
split_line
)
-
1
if
instances
>
0
:
marker
=
0
while
marker
<
instances
:
if
(
"=
\"
"
in
split_line
[
marker
]
and
"
\"
"
in
split_line
[
marker
+
1
])
or
(
"='"
in
split_line
[
marker
]
and
"'"
in
split_line
[
marker
+
1
]):
marker
+=
1
else
:
if
marker
==
0
:
line
=
split_line
[
marker
]
else
:
# We have multiple fragments that we need to combine back together.
# rekram is us reversing that work we did with marker.
rekram
=
0
new_line
=
split_line
[
rekram
]
while
marker
>
rekram
:
rekram
+=
1
new_line
=
new_line
+
"#"
+
split_line
[
rekram
]
line
=
new_line
break
# Clean up the end of the line.
# Clean up the end of the line.
line
=
line
.
strip
()
line
=
line
.
strip
()
...
...
lib/ansible/utils/__init__.py
View file @
38abd5e2
...
@@ -1071,3 +1071,37 @@ def random_password(length=20, chars=C.DEFAULT_PASSWORD_CHARS):
...
@@ -1071,3 +1071,37 @@ 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
split_unquoted_hash
(
line
):
'''
Carve off comments from a line which are not contained in quotes and a part of an assignment.
'''
# We would really like to have this using a regex to make it less code. For instance:
# line = re.split('(?<!=["|\'].*)#(?!.*?["|\']).*', line)[0]
# this has the problem that it comes back with a "sre_constants.error: look-behind requires fixed-width pattern"
if
"#"
in
line
:
split_line
=
line
.
split
(
"#"
)
instances
=
len
(
split_line
)
-
1
if
instances
>
0
:
marker
=
0
while
marker
<
instances
:
if
(
"=
\"
"
in
split_line
[
marker
]
and
"
\"
"
in
split_line
[
marker
+
1
])
or
(
"='"
in
split_line
[
marker
]
and
"'"
in
split_line
[
marker
+
1
]):
marker
+=
1
else
:
if
marker
==
0
:
line
=
split_line
[
marker
]
else
:
# We have multiple fragments that we need to combine back together.
# rekram is us reversing that work we did with marker.
rekram
=
0
new_line
=
split_line
[
rekram
]
while
marker
>
rekram
:
rekram
+=
1
new_line
=
new_line
+
"#"
+
split_line
[
rekram
]
line
=
new_line
break
return
line
\ No newline at end of file
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