changed 6 years ago
Linked with GitHub

Defining env vars with Ansible

Bash mode

- shell: |
    FOO=foo
    BAR=bar
    ./run.sh

Official way

- shell: ./run.sh  # or command:
  environment:
      FOO: foo
      BAR: bar

Advantages:

  • you could define environment at playbook or block levels and it would be inhereted by each task
  • easy to read, we can even use yaml anchors to avoid repetition if needed

Challenges:

  • If we already have an environment used and we want to add or override it we need to merge the dictionary using jinja2

Also valid:

- shell: ./run.sh
  environment: a_dict_var
Select a repo