Ansible, set_fact using if then else statement

前端 未结 2 1850
孤城傲影
孤城傲影 2021-02-08 16:19

I am trying to set a variable in Ansible with set_fact at runtime based upon another variable. If uses first value no matter what the actual value is. Here is my code example:

2条回答
  •  醉梦人生
    2021-02-08 17:09

    One of the simple way to set fact based condition example as follows:

      - name: Set facts for delete operation results
        set_fact:
            tr_result: "{{ '{\"status\": \"SUCCESS\"}' if (op_result['output'] == 'Deleted') else '{\"status\" : \"FAILED\"}' }}"
    

    Note: Assume op_result is a dict & already defined.

    Code has been tested and working well.

提交回复
热议问题