Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The task includes an option with an undefined variable

I have the below vars file and Ansible task which allows some ports for a specific source IPs on the firewall.

But for some reason, whenever I run the task I got this error:

FAILED! => {"msg": "The task includes an option with an undefined variable.

Even though I'm able to echo out these variables using debug Ansible module, so basically I'm just unable to use these variable specifically in this task.

Ansible Task:

---
- name:
  firewalld:
    permanent: yes
    port: "{{ item.0 }}"
    state: enabled
    zone: public
    source: "{{ item.1 }}"
    with_nested: 
      - "{{ ports }}"
      - "{{ ips }}"

Vars File:

ports:
  - "8000/tcp"
  - "9997/tcp"
  - "8181/tcp"
  - "8080/tcp"
  - "8191/tcp"
  - "8088/tcp"
  - "8065/tcp"
  
ips:
  - "192.168.210.30/32"
  - "192.168.210.35/32"
  - "192.168.210.40/32"
  - "192.168.210.31/32"
  - "192.168.210.36/32"
  - "192.168.210.41/32"
  - "192.168.210.42/32"
  - "192.168.210.37/32"
like image 606
3amer_92 Avatar asked Oct 19 '25 23:10

3amer_92


1 Answers

The indentation of with_nested is wrong. Correct syntax is

- name:
  firewalld:
    permanent: yes
    port: "{{ item.0 }}"
    state: enabled
    zone: public
    source: "{{ item.1 }}"
  with_nested: 
    - "{{ ports }}"
    - "{{ ips }}"
like image 125
Vladimir Botka Avatar answered Oct 22 '25 18:10

Vladimir Botka



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!