You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
mitogen/tests/ansible/lib/modules/custom_python_run_script.py

35 lines
657 B
Python

#!/usr/bin/env python
# I am an Ansible new-style Python module. I run the script provided in the
# parameter.
from ansible.module_utils.basic import AnsibleModule
import sys
def execute(s, gbls, lcls):
if sys.version_info > (3,):
exec(s, gbls, lcls)
else:
exec('exec s in gbls, lcls')
def main():
module = AnsibleModule(argument_spec={
'script': {
'type': 'str'
}
})
lcls = {
'module': module,
'result': {}
}
execute(module.params['script'], globals(), lcls)
del lcls['module']
module.exit_json(**lcls['result'])
if __name__ == '__main__':
main()