Я пытаюсь установить входную переменную на основе фактов.
if input protocol = to TCP/UDP
then service name will be TCP-443/UDP-443
else service name will be ALL
Я могу выполнить свое требование с помощью приведенного ниже метода, но я хотел бы упростить то же самое, может ли кто-нибудь помочь мне здесь
- name: setting fact for service name
set_fact:
servicename: TCP-{{port}}
when: >
protocol == "TCP" or protocol == "tcp"
- name: setting fact for service name
set_fact:
servicename: UDP-{{ port }}
when: >
protocol == "UDP" or protocol == "udp"
- name: setting fact for service name
set_fact:
servicename: "ALL"
when: >
protocol == "all" or protocol == "ALL"
- name: setting fact for service name
set_fact:
protocolname: "tcp_udp_sctp"
when: >
protocol == "TCP" or protocol == "tcp"
- name: setting fact for service name
set_fact:
protocolname: "tcp_udp_sctp"
when: >
protocol == "UDP" or protocol == "udp"
- name: setting fact for service name
set_fact:
protocolname: "ALL"
when: >
protocol == "all" or protocol == "ALL"
Эквивалент выглядит следующим образом, я думаю
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"