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
647cd014
Commit
647cd014
authored
Feb 27, 2013
by
Daniel Hokka Zakrisson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move all inventory script code into the script parser
parent
7749b345
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
16 deletions
+17
-16
lib/ansible/inventory/__init__.py
+2
-15
lib/ansible/inventory/ini.py
+3
-0
lib/ansible/inventory/script.py
+12
-1
No files found.
lib/ansible/inventory/__init__.py
View file @
647cd014
...
...
@@ -35,7 +35,7 @@ class Inventory(object):
Host inventory for ansible.
"""
__slots__
=
[
'host_list'
,
'groups'
,
'_restriction'
,
'_also_restriction'
,
'_subset'
,
'_is_script'
,
__slots__
=
[
'host_list'
,
'groups'
,
'_restriction'
,
'_also_restriction'
,
'_subset'
,
'parser'
,
'_vars_per_host'
,
'_vars_per_group'
,
'_hosts_cache'
,
'_groups_list'
]
def
__init__
(
self
,
host_list
=
C
.
DEFAULT_HOST_LIST
):
...
...
@@ -60,9 +60,6 @@ class Inventory(object):
self
.
_also_restriction
=
None
self
.
_subset
=
None
# whether the inventory file is a script
self
.
_is_script
=
False
if
type
(
host_list
)
in
[
str
,
unicode
]:
if
host_list
.
find
(
","
)
!=
-
1
:
host_list
=
host_list
.
split
(
","
)
...
...
@@ -82,7 +79,6 @@ class Inventory(object):
all
.
add_host
(
Host
(
x
))
elif
os
.
path
.
exists
(
host_list
):
if
utils
.
is_executable
(
host_list
):
self
.
_is_script
=
True
self
.
parser
=
InventoryScript
(
filename
=
host_list
)
self
.
groups
=
self
.
parser
.
groups
.
values
()
else
:
...
...
@@ -280,16 +276,7 @@ class Inventory(object):
vars
.
update
(
updated
)
vars
.
update
(
host
.
get_variables
())
if
self
.
_is_script
:
cmd
=
[
self
.
host_list
,
"--host"
,
hostname
]
try
:
sp
=
subprocess
.
Popen
(
cmd
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
except
OSError
,
e
:
raise
errors
.
AnsibleError
(
"problem running
%
s (
%
s)"
%
(
' '
.
join
(
cmd
),
e
))
(
out
,
err
)
=
sp
.
communicate
()
results
=
utils
.
parse_json
(
out
)
vars
.
update
(
results
)
vars
.
update
(
self
.
parser
.
get_host_variables
(
host
))
return
vars
def
add_group
(
self
,
group
):
...
...
lib/ansible/inventory/ini.py
View file @
647cd014
...
...
@@ -173,3 +173,6 @@ class InventoryParser(object):
group
.
set_variable
(
k
,
re
.
sub
(
r"^['\"]|['\"]$"
,
''
,
v
))
else
:
group
.
set_variable
(
k
,
v
)
def
get_host_variables
(
self
,
host
):
return
{}
lib/ansible/inventory/script.py
View file @
647cd014
...
...
@@ -29,7 +29,8 @@ class InventoryScript(object):
def
__init__
(
self
,
filename
=
C
.
DEFAULT_HOST_LIST
):
cmd
=
[
filename
,
"--list"
]
self
.
filename
=
filename
cmd
=
[
self
.
filename
,
"--list"
]
try
:
sp
=
subprocess
.
Popen
(
cmd
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
except
OSError
,
e
:
...
...
@@ -77,3 +78,13 @@ class InventoryScript(object):
if
child_name
in
groups
:
groups
[
group_name
]
.
add_child_group
(
groups
[
child_name
])
return
groups
def
get_host_variables
(
self
,
host
):
""" Runs <script> --host <hostname> to determine additional host variables """
cmd
=
[
self
.
filename
,
"--host"
,
host
.
name
]
try
:
sp
=
subprocess
.
Popen
(
cmd
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
except
OSError
,
e
:
raise
errors
.
AnsibleError
(
"problem running
%
s (
%
s)"
%
(
' '
.
join
(
cmd
),
e
))
(
out
,
err
)
=
sp
.
communicate
()
return
utils
.
parse_json
(
out
)
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