Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mitogen
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
mitogen
Commits
7080751f
Commit
7080751f
authored
Feb 28, 2018
by
David Wilson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ansible: support environment: too.
parent
f74a56da
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
4 deletions
+35
-4
ansible_mitogen/helpers.py
ansible_mitogen/helpers.py
+14
-4
ansible_mitogen/mixins.py
ansible_mitogen/mixins.py
+4
-0
examples/playbook/environment.yml
examples/playbook/environment.yml
+17
-0
No files found.
ansible_mitogen/helpers.py
View file @
7080751f
...
...
@@ -96,7 +96,7 @@ def monkey_fail_json(self, **kwargs):
raise
ModuleError
(
kwargs
.
get
(
'msg'
),
kwargs
)
def
run_module
(
module
,
raw_params
=
None
,
args
=
None
):
def
run_module
(
module
,
raw_params
=
None
,
args
=
None
,
env
=
None
):
"""
Set up the process environment in preparation for running an Ansible
module. This monkey-patches the Ansible libraries in various places to
...
...
@@ -114,6 +114,10 @@ def run_module(module, raw_params=None, args=None):
'ANSIBLE_MODULE_ARGS'
:
args
})
if
env
:
original_env
=
os
.
environ
.
copy
()
os
.
environ
.
update
((
k
,
str
(
v
))
for
k
,
v
in
env
.
iteritems
())
try
:
mod
=
__import__
(
module
,
{},
{},
[
''
])
# Ansible modules begin execution on import. Thus the above __import__
...
...
@@ -123,16 +127,22 @@ def run_module(module, raw_params=None, args=None):
# explicitly.
mod
.
main
()
except
(
Exit
,
ModuleError
),
e
:
return
json
.
dumps
(
e
.
dct
)
result
=
json
.
dumps
(
e
.
dct
)
if
env
:
os
.
environ
.
clear
()
os
.
environ
.
update
(
original_env
)
return
result
def
_async_main
(
job_id
,
module
,
raw_params
,
args
):
def
_async_main
(
job_id
,
module
,
raw_params
,
args
,
env
):
"""
Implementation for the thread that implements asynchronous module
execution.
"""
try
:
rc
=
run_module
(
module
,
raw_params
,
args
)
rc
=
run_module
(
module
,
raw_params
,
args
,
env
)
except
Exception
,
e
:
rc
=
mitogen
.
core
.
CallError
(
e
)
...
...
ansible_mitogen/mixins.py
View file @
7080751f
...
...
@@ -165,11 +165,15 @@ class ActionModuleMixin(ansible.plugins.action.ActionBase):
else
:
helper
=
ansible_mitogen
.
helpers
.
run_module
env
=
{}
self
.
_compute_environment_string
(
env
)
# replaces 110 lines
js
=
self
.
call
(
helper
,
get_command_module_name
(
module_name
),
args
=
cast
(
module_args
),
env
=
cast
(
env
),
)
data
=
self
.
_parse_returned_data
({
...
...
examples/playbook/environment.yml
0 → 100644
View file @
7080751f
---
# Ensure environment: is preserved during call.
-
hosts
:
all
gather_facts
:
false
tasks
:
-
shell
:
echo $SOME_ENV
environment
:
SOME_ENV
:
123
register
:
result
-
debug
:
msg={{result}}
-
assert
:
that
:
"
result.stdout
==
'123'"
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