From bf2a724873f5e3d8b97257c9318b6b82d7b381f5 Mon Sep 17 00:00:00 2001 From: Alan Rominger Date: Fri, 28 Aug 2020 23:10:22 -0400 Subject: [PATCH 1/2] Add playbook to get environment out --- print_environment.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 print_environment.yml diff --git a/print_environment.yml b/print_environment.yml new file mode 100644 index 0000000000..b33c803c46 --- /dev/null +++ b/print_environment.yml @@ -0,0 +1,13 @@ +--- +- hosts: localhost + gather_facts: false + connection: local + vars: + running_env: [] + tasks: + - command: printenv + register: result + + - set_stats: + data: + printenv: "{{ result.stdout }}" From 920c77992d72cf31dd725928d679807e84f800a0 Mon Sep 17 00:00:00 2001 From: Alan Rominger Date: Mon, 31 Aug 2020 12:16:43 -0400 Subject: [PATCH 2/2] Use an action plugin to get more accurate data --- action_plugins/look_at_environment.py | 21 +++++++++++++++++++++ print_environment.yml | 13 +++++++++---- 2 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 action_plugins/look_at_environment.py 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 index b33c803c46..37c79ee759 100644 --- a/print_environment.yml +++ b/print_environment.yml @@ -1,13 +1,18 @@ --- - hosts: localhost - gather_facts: false + gather_facts: False connection: local vars: running_env: [] + write_env_file: False tasks: - - command: printenv + - look_at_environment: register: result + - copy: + content: "{{ result.printenv }}" + dest: inner_env.txt + when: write_env_file + - set_stats: - data: - printenv: "{{ result.stdout }}" + data: "{{ result }}"