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
58ad9342
Commit
58ad9342
authored
12 years ago
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1024 from tima/groups-pb
Made $groups and $group_names variables accessible in with_items
parents
1829d519
9d5a79f5
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
11 deletions
+17
-11
lib/ansible/inventory/__init__.py
+13
-1
lib/ansible/runner/__init__.py
+4
-10
No files found.
lib/ansible/inventory/__init__.py
View file @
58ad9342
...
@@ -35,7 +35,7 @@ class Inventory(object):
...
@@ -35,7 +35,7 @@ class Inventory(object):
"""
"""
__slots__
=
[
'host_list'
,
'groups'
,
'_restriction'
,
'_also_restriction'
,
'_subset'
,
'_is_script'
,
__slots__
=
[
'host_list'
,
'groups'
,
'_restriction'
,
'_also_restriction'
,
'_subset'
,
'_is_script'
,
'parser'
,
'_vars_per_host'
,
'_vars_per_group'
,
'_hosts_cache'
]
'parser'
,
'_vars_per_host'
,
'_vars_per_group'
,
'_hosts_cache'
,
'_groups_list'
]
def
__init__
(
self
,
host_list
=
C
.
DEFAULT_HOST_LIST
):
def
__init__
(
self
,
host_list
=
C
.
DEFAULT_HOST_LIST
):
...
@@ -49,6 +49,7 @@ class Inventory(object):
...
@@ -49,6 +49,7 @@ class Inventory(object):
self
.
_vars_per_host
=
{}
self
.
_vars_per_host
=
{}
self
.
_vars_per_group
=
{}
self
.
_vars_per_group
=
{}
self
.
_hosts_cache
=
{}
self
.
_hosts_cache
=
{}
self
.
_groups_list
=
{}
# the inventory object holds a list of groups
# the inventory object holds a list of groups
self
.
groups
=
[]
self
.
groups
=
[]
...
@@ -215,6 +216,17 @@ class Inventory(object):
...
@@ -215,6 +216,17 @@ class Inventory(object):
continue
continue
return
results
return
results
def
groups_list
(
self
):
if
not
self
.
_groups_list
:
groups
=
{}
for
g
in
self
.
groups
:
groups
[
g
.
name
]
=
[
h
.
name
for
h
in
g
.
get_hosts
()]
ancestors
=
g
.
get_ancestors
()
for
a
in
ancestors
:
groups
[
a
.
name
]
=
[
h
.
name
for
h
in
a
.
get_hosts
()]
self
.
_groups_list
=
groups
return
self
.
_groups_list
def
get_groups
(
self
):
def
get_groups
(
self
):
return
self
.
groups
return
self
.
groups
...
...
This diff is collapsed.
Click to expand it.
lib/ansible/runner/__init__.py
View file @
58ad9342
...
@@ -250,17 +250,15 @@ class Runner(object):
...
@@ -250,17 +250,15 @@ class Runner(object):
inject
.
update
(
self
.
module_vars
)
inject
.
update
(
self
.
module_vars
)
inject
.
update
(
self
.
setup_cache
[
host
])
inject
.
update
(
self
.
setup_cache
[
host
])
inject
[
'hostvars'
]
=
self
.
setup_cache
inject
[
'hostvars'
]
=
self
.
setup_cache
inject
[
'group_names'
]
=
host_variables
.
get
(
'group_names'
,
[])
inject
[
'groups'
]
=
self
.
inventory
.
groups_list
()
# allow with_items to work in playbooks...
# allow with_items to work in playbooks...
# apt and yum are converted into a single call, others run in a loop
# apt and yum are converted into a single call, others run in a loop
items
=
self
.
module_vars
.
get
(
'items'
,
[])
items
=
self
.
module_vars
.
get
(
'items'
,
[])
if
isinstance
(
items
,
basestring
)
and
items
.
startswith
(
"$"
):
if
isinstance
(
items
,
basestring
)
and
items
.
startswith
(
"$"
):
items
=
items
.
replace
(
"$"
,
""
)
items
=
utils
.
varLookup
(
items
,
inject
)
if
items
in
inject
:
items
=
inject
[
items
]
else
:
raise
errors
.
AnsibleError
(
"unbound variable in with_items:
%
s"
%
items
)
if
type
(
items
)
!=
list
:
if
type
(
items
)
!=
list
:
raise
errors
.
AnsibleError
(
"with_items only takes a list:
%
s"
%
items
)
raise
errors
.
AnsibleError
(
"with_items only takes a list:
%
s"
%
items
)
...
@@ -321,11 +319,7 @@ class Runner(object):
...
@@ -321,11 +319,7 @@ class Runner(object):
# 'hostvars' variable contains variables for each host name
# 'hostvars' variable contains variables for each host name
# ... and is set elsewhere
# ... and is set elsewhere
# 'inventory_hostname' is also set elsewhere
# 'inventory_hostname' is also set elsewhere
group_hosts
=
{}
inject
[
'groups'
]
=
self
.
inventory
.
groups_list
()
for
g
in
self
.
inventory
.
groups
:
group_hosts
[
g
.
name
]
=
[
h
.
name
for
h
in
g
.
hosts
]
inject
[
'groups'
]
=
group_hosts
# allow module args to work as a dictionary
# allow module args to work as a dictionary
# though it is usually a string
# though it is usually a string
new_args
=
""
new_args
=
""
...
...
This diff is collapsed.
Click to expand it.
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