Set Ansible role defaults conditionally

烂漫一生 提交于 2019-12-13 22:05:57

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!