问题
Pseudocode:
If env is de, set variable name to hello else if env is prod, set variable name to bye.
I tried https://serverfault.com/questions/715769/ansible-change-default-value-according-to-a-condition
- name: setting variable
set_fact: name="hello"
when: "{{ env }}" == "de"
- name: setting variable
set_fact: name="bye"
when: "{{ env }}" == "prod"
ERROR! The default/main.yml file for role 'trial' must contain a dictionary of variables
回答1:
As per my requirement, it needs to be done in role.So it is done as follows:
name: "{% if env == 'de' %}hello{% elif env == 'prod' %}bye{% endif %}"
来源:https://stackoverflow.com/questions/40082655/set-ansible-role-defaults-conditionally