【问题标题】:The task includes an option with an undefined variable该任务包括一个带有未定义变量的选项
【发布时间】:2020-01-17 00:45:49
【问题描述】:

我有以下 vars 文件和 Ansible 任务,它允许防火墙上特定源 IP 的某些端口。

但由于某种原因,每当我运行任务时,我都会收到此错误:

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

即使我能够使用 debug Ansible 模块回显这些变量,所以基本上我只是无法在此任务中专门使用这些变量。

Ansible 任务:

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

变量文件:

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"

【问题讨论】:

    标签: loops variables ansible centos7 firewalld


    【解决方案1】:

    with_nested 的缩进是错误的。正确的语法是

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

    【讨论】:

    • 即使是 yaml 文件中的小空间也会有所作为。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-03
    相关资源
    最近更新 更多