diff --git a/action_plugins/look_at_environment.py b/action_plugins/look_at_environment.py new file mode 100644 index 0000000000..26a4ff23aa --- /dev/null +++ b/action_plugins/look_at_environment.py @@ -0,0 +1,21 @@ +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + +from ansible.plugins.action import ActionBase + +import os + + +class ActionModule(ActionBase): + + def run(self, tmp=None, task_vars=None): + result = super(ActionModule, self).run(tmp, task_vars) + result['changed'] = result['failed'] = False + result['msg'] = '' + env_dict = dict(os.environ) + result['printenv'] = '\n'.join( + '{0}={1}'.format(k, v) for k, v in env_dict.items() + ) + result['environment'] = env_dict + result['cwd'] = os.getcwd() + return result diff --git a/print_environment.yml b/print_environment.yml new file mode 100644 index 0000000000..37c79ee759 --- /dev/null +++ b/print_environment.yml @@ -0,0 +1,18 @@ +--- +- hosts: localhost + gather_facts: False + connection: local + vars: + running_env: [] + write_env_file: False + tasks: + - look_at_environment: + register: result + + - copy: + content: "{{ result.printenv }}" + dest: inner_env.txt + when: write_env_file + + - set_stats: + data: "{{ result }}"