I need to write a playbook using jinja2 tamplate inorder to write firewalld rule in ansible. For that I wrote
---
- name: Firewalld check
hosts: localhost
become: yes
tasks:
- name: Allow ICMP traffic
firewalld:
rich_rule: rule family='ipv4' source address=" {{ source }} " protocol value="icmp" accept
permanent: no
state: enabled
in template and
---
- name: Firewalld config
hosts: localhost
become: yes
vars:
source:
- 172.16.2.114
- 172.16.2.115
tasks:
- name: Rules
template:
src: playtem.yml.j2
dest: playbook.yml
in playbook. The output I expected is
---
- name: Firewalld check
hosts: localhost
become: yes
tasks:
- name: Allow ICMP traffic
firewalld:
rich_rule: rule family='ipv4' source address="172.16.2.114" protocol value="icmp" accept
permanent: no
state: enabled
- name: Allow ICMP traffic
firewalld:
rich_rule: rule family='ipv4' source address="172.16.2.115" protocol value="icmp" accept
permanent: no
state: enabled
but the outcome which came is
---
- name: Firewalld check
hosts: localhost
become: yes
tasks:
- name: Allow ICMP traffic
firewalld:
rich_rule: rule family='ipv4' source address=" [u'172.16.2.114', u'172.16.2.115'] " protocol value="icmp" accept
permanent: no
state: enabled
So could anyone help me to solve this problem please?