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
7490044b
Commit
7490044b
authored
Jun 22, 2015
by
James Cammarata
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement play_hosts magic variable (and ansible_current_hosts)
Fixes #8073
parent
cb5f630f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
0 deletions
+22
-0
lib/ansible/plugins/strategies/__init__.py
+12
-0
lib/ansible/plugins/strategies/linear.py
+1
-0
lib/ansible/vars/__init__.py
+9
-0
No files found.
lib/ansible/plugins/strategies/__init__.py
View file @
7490044b
...
@@ -104,6 +104,17 @@ class StrategyBase:
...
@@ -104,6 +104,17 @@ class StrategyBase:
def
get_failed_hosts
(
self
,
play
):
def
get_failed_hosts
(
self
,
play
):
return
[
host
for
host
in
self
.
_inventory
.
get_hosts
(
play
.
hosts
)
if
host
.
name
in
self
.
_tqm
.
_failed_hosts
]
return
[
host
for
host
in
self
.
_inventory
.
get_hosts
(
play
.
hosts
)
if
host
.
name
in
self
.
_tqm
.
_failed_hosts
]
def
add_tqm_variables
(
self
,
vars
,
play
):
'''
Base class method to add extra variables/information to the list of task
vars sent through the executor engine regarding the task queue manager state.
'''
new_vars
=
vars
.
copy
()
new_vars
[
'ansible_current_hosts'
]
=
self
.
get_hosts_remaining
(
play
)
new_vars
[
'ansible_failed_hosts'
]
=
self
.
get_failed_hosts
(
play
)
return
new_vars
def
_queue_task
(
self
,
host
,
task
,
task_vars
,
connection_info
):
def
_queue_task
(
self
,
host
,
task
,
task_vars
,
connection_info
):
''' handles queueing the task up to be sent to a worker '''
''' handles queueing the task up to be sent to a worker '''
...
@@ -374,6 +385,7 @@ class StrategyBase:
...
@@ -374,6 +385,7 @@ class StrategyBase:
for
host
in
self
.
_notified_handlers
[
handler_name
]:
for
host
in
self
.
_notified_handlers
[
handler_name
]:
if
not
handler
.
has_triggered
(
host
):
if
not
handler
.
has_triggered
(
host
):
task_vars
=
self
.
_variable_manager
.
get_vars
(
loader
=
self
.
_loader
,
play
=
iterator
.
_play
,
host
=
host
,
task
=
handler
)
task_vars
=
self
.
_variable_manager
.
get_vars
(
loader
=
self
.
_loader
,
play
=
iterator
.
_play
,
host
=
host
,
task
=
handler
)
task_vars
=
self
.
add_tqm_variables
(
task_vars
,
play
=
iterator
.
_play
)
self
.
_queue_task
(
host
,
handler
,
task_vars
,
connection_info
)
self
.
_queue_task
(
host
,
handler
,
task_vars
,
connection_info
)
handler
.
flag_for_host
(
host
)
handler
.
flag_for_host
(
host
)
self
.
_process_pending_results
(
iterator
)
self
.
_process_pending_results
(
iterator
)
...
...
lib/ansible/plugins/strategies/linear.py
View file @
7490044b
...
@@ -188,6 +188,7 @@ class StrategyModule(StrategyBase):
...
@@ -188,6 +188,7 @@ class StrategyModule(StrategyBase):
else
:
else
:
debug
(
"getting variables"
)
debug
(
"getting variables"
)
task_vars
=
self
.
_variable_manager
.
get_vars
(
loader
=
self
.
_loader
,
play
=
iterator
.
_play
,
host
=
host
,
task
=
task
)
task_vars
=
self
.
_variable_manager
.
get_vars
(
loader
=
self
.
_loader
,
play
=
iterator
.
_play
,
host
=
host
,
task
=
task
)
task_vars
=
self
.
add_tqm_variables
(
task_vars
,
play
=
iterator
.
_play
)
templar
=
Templar
(
loader
=
self
.
_loader
,
variables
=
task_vars
)
templar
=
Templar
(
loader
=
self
.
_loader
,
variables
=
task_vars
)
debug
(
"done getting variables"
)
debug
(
"done getting variables"
)
...
...
lib/ansible/vars/__init__.py
View file @
7490044b
...
@@ -227,6 +227,15 @@ class VariableManager:
...
@@ -227,6 +227,15 @@ class VariableManager:
if
self
.
_inventory
is
not
None
:
if
self
.
_inventory
is
not
None
:
all_vars
[
'inventory_dir'
]
=
self
.
_inventory
.
basedir
()
all_vars
[
'inventory_dir'
]
=
self
.
_inventory
.
basedir
()
if
play
:
# add the list of hosts in the play, as adjusted for limit/filters
# FIXME: play_hosts should be deprecated in favor of ansible_play_hosts,
# however this would take work in the templating engine, so for now
# we'll add both so we can give users something transitional to use
host_list
=
[
x
.
name
for
x
in
self
.
_inventory
.
get_hosts
()]
all_vars
[
'play_hosts'
]
=
host_list
all_vars
[
'ansible_play_hosts'
]
=
host_list
# the 'omit' value alows params to be left out if the variable they are based on is undefined
# the 'omit' value alows params to be left out if the variable they are based on is undefined
all_vars
[
'omit'
]
=
self
.
_omit_token
all_vars
[
'omit'
]
=
self
.
_omit_token
...
...
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