Skip to content

Instantly share code, notes, and snippets.

@agaffney
Last active October 9, 2018 15:24
Show Gist options
  • Save agaffney/e12fa01adeb2a4698ee7db8e60fecfe2 to your computer and use it in GitHub Desktop.
Save agaffney/e12fa01adeb2a4698ee7db8e60fecfe2 to your computer and use it in GitHub Desktop.
Ansible tasks to source remote file and return resulting env vars
- name: Source file and return env vars
shell: >
. /path/to/foo.env;
{{ ansible_python_interpreter | default('python') }} -c
'from __future__ import print_function; import os, json; print(json.dumps(dict(os.environ)))'
register: source_env_vars_output
- name: Create var from JSON
set_fact:
source_env_vars: '{{ source_env_vars_output.stdout | from_json }}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment