The task includes an option with an undefined variable

3amer_92 picture 3amer_92 · Sep 16, 2019 · Viewed 9.9k times · Source

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:

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"

Answer

Vladimir Botka picture Vladimir Botka · Sep 16, 2019

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 }}"