It should be like this and it will work for sure .
- name: Enable TCP and UDP ports
firewalld:
port: "{{item.port}}"/"{{item.protocol}}"
immediate: true
permanent: true
state: enabled
with_items:
- { port: "5301,1302,5903,5672", protocol: tcp }
- { port: "25238,55692", protocol: udp}
tags: port
Ravi
On Thu, Dec 20, 2018 at 1:22 PM Tony Chia <[email protected]> wrote:
> Hi Prashant,
>
> It looks like your "with_items" is not lined up correctly with firewalld
> so the list is not passed to {{item.port}}
>
> i.e. try this
>
> - name: Enable TCP and UDP ports
> firewalld:
> port: '{{item.port}}/{{item.protocol}}'
> immediate: true
> permanent: true
> state: enabled
> with_items:
> - { port: "5301,1302,5903,5672", protocol: tcp }
> - { port: "25238,55692", protocol: udp}
> tags: port
>
>
> On Wednesday, December 19, 2018 at 10:41:41 PM UTC-8, Prashant Jaiswal
> wrote:
>>
>> Hi,
>>
>> While running a playbook to enable multiple TCP & UDP ports on a remote
>> m/c I am getting some syntax error which I can't figure it out. The error
>> says FAILED! => {"msg": "The task includes an option with an undefined
>> variable. The error was: 'item' is undefined\n\nThe error appears to have
>> been in '/etc/ansible/playbooks/enable_firewall_ports.yml': line 13, column
>> 7, but may\nbe elsewhere in the file depending on the exact syntax
>> problem.\n\nThe offending line appears to be:\n\n\n - name: Enable TCP
>> and UDP ports\n ^ here\n"}
>>
>>
>> Below is the code
>>
>>
>> ---
>> - hosts: test
>> become : True
>> become_user : root
>> become_method : sudo
>> tasks:
>> - name: Start and enable firewalld
>> service:
>> name: firewalld
>> state: started
>> enabled: yes
>>
>> - name: Enable TCP and UDP ports
>> firewalld:
>> port: '{{item.port}}/{{item.protocol}}'
>> with_items:
>> - { port: "5301,1302,5903,5672", protocol: tcp }
>> - { port: "25238,55692", protocol: udp}
>> immediate: true
>> permanent: true
>> state: enabled
>> tags: port
>>
>> - name: Bounce firewalld
>> service: name=firewalld state=restarted
>>
>>
>>
>> Any suggestions ?
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/6e77644f-e023-4b7e-b6aa-94ad5247caf2%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/6e77644f-e023-4b7e-b6aa-94ad5247caf2%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/CAGfYbJwt4O1Tfx-BkzWwEwoYqCgPNpU1Z6QHokw1BRYCKBqMZA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.