parent
def848f118
commit
15d68b3c32
@ -0,0 +1,50 @@
|
||||
# issue #309: ensure process environment is restored after a module runs.
|
||||
|
||||
|
||||
- name: integration/runner/environment_isolation.yml
|
||||
hosts: test-targets
|
||||
any_errors_fatal: true
|
||||
gather_facts: true
|
||||
tasks:
|
||||
|
||||
# ---
|
||||
# Verify custom env setting is cleared out.
|
||||
# ---
|
||||
|
||||
# Verify sane state first.
|
||||
- custom_python_detect_environment:
|
||||
register: out
|
||||
- assert:
|
||||
that: not out.env.evil_key is defined
|
||||
|
||||
- shell: echo 'hi'
|
||||
environment:
|
||||
evil_key: evil
|
||||
|
||||
# Verify environment was cleaned up.
|
||||
- custom_python_detect_environment:
|
||||
register: out
|
||||
- assert:
|
||||
that: not out.env.evil_key is defined
|
||||
|
||||
|
||||
# ---
|
||||
# Verify non-explicit module env mutations are cleared out.
|
||||
# ---
|
||||
|
||||
# Verify sane state first.
|
||||
- custom_python_detect_environment:
|
||||
register: out
|
||||
- assert:
|
||||
that: not out.env.evil_key is defined
|
||||
|
||||
- custom_python_modify_environ:
|
||||
key: evil_key
|
||||
val: evil
|
||||
|
||||
# Verify environment was cleaned up.
|
||||
- custom_python_detect_environment:
|
||||
register: out
|
||||
- assert:
|
||||
that: not out.env.evil_key is defined
|
||||
|
@ -0,0 +1,22 @@
|
||||
#!/usr/bin/python
|
||||
# I am an Ansible new-style Python module. I modify the process environment and
|
||||
# don't clean up after myself.
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
|
||||
import os
|
||||
import pwd
|
||||
import socket
|
||||
import sys
|
||||
|
||||
|
||||
def main():
|
||||
module = AnsibleModule(argument_spec={
|
||||
'key': {'type': str},
|
||||
'val': {'type': str}
|
||||
})
|
||||
os.environ[module.params['key']] = module.params['val']
|
||||
module.exit_json(msg='Muahahaha!')
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
Loading…
Reference in New Issue