How to write dynamic variable in Ansible playbook

前端 未结 3 362
一整个雨季
一整个雨季 2021-01-30 10:51

Based on extra vars parameter I Need to write variable value in ansible playbook

ansible-playbook playbook.yml -e \"param1=value1 param         


        
3条回答
  •  情歌与酒
    2021-01-30 11:34

    my_var: the variable declared

    VAR: the variable, whose value is to be checked

    param_1, param_2: values of the variable VAR

    value_1, value_2, value_3: the values to be assigned to my_var according to the values of my_var

    my_var: "{{ 'value_1' if VAR == 'param_1' else 'value_2' if VAR == 'param_2' else 'value_3' }}"
    

提交回复
热议问题