有条件的事实

时间:2019-05-28 19:02:58

标签: ansible ansible-facts

我试图设置基于事实的输入变量。

Calculation

我可以通过以下方法达到我的要求,但我想简化一下,有人可以在这里帮助我

if input protocol = to TCP/UDP 
  then service name will be TCP-443/UDP-443 
else service name will be ALL

1 个答案:

答案 0 :(得分:1)

我认为等价如下

  vars:
    port: 443
  tasks:
    - name: setting fact for service name
      set_fact:
        servicename: "{{ protocol|upper }}-{{ port }}"
        protocolname: "tcp_udp_sctp"
      when: protocol|upper == "TCP" or
            protocol|upper == "UDP"

    - name: setting fact for service name
      set_fact:
        servicename: "ALL"
        protocolname: "ALL"
      when: protocol|upper == "ALL"