Reputation: 41
I want to assign a value to a variable based on my env name. If env=e1, some variable name "var" should get the value as "x". If env=e2, "var" should get the value as "y".
Let me know your suggestions!
Upvotes: 3
Views: 9474
Reputation: 111
Say you have an env var called FOO.
- hosts: localhost
gather_facts: "False"
vars:
my_env_var: "{{ lookup('env','FOO') }}"
tasks:
- name: "set e1"
set_fact:
my_ansible_var: "x"
when: my_env_var == "e1"
- name: "set e2"
set_fact:
my_ansible_var: "y"
when: my_env_var == "e2"
You can now reference the {{ my_ansible_var }} value anywhere it is needed.
Upvotes: 3