【问题标题】:Bad source address when trying to configure UFW via ansible playbook尝试通过 ansible playbook 配置 UFW 时源地址错误
【发布时间】:2019-09-12 13:54:46
【问题描述】:

我是 Ansible 的新手。我正在尝试编写一个剧本来配置 UFW。我的任务是这样写的:

 - name: Allow SSH in UFW
    ufw:
      rule: allow
      port: 22
      proto: tcp
      from_ip:
        - "{{ item }}"
    with_items:
      - 192.168.0.0/24
      - 10.200.3.0/24
      - 10.200.2.0/24

我在运行 playbook 时得到的结果是:

failed: [192.168.255.20] (item=192.168.0.0/24) => {"changed": false, "item": "192.168.0.0/24", "msg": "ERROR: Bad source address\n"}
failed: [192.168.255.20] (item=10.200.3.0/24) => {"changed": false, "item": "10.200.3.0/24", "msg": "ERROR: Bad source address\n"}
failed: [192.168.255.20] (item=10.200.2.0/24) => {"changed": false, "item": "10.200.2.0/24", "msg": "ERROR: Bad source address\n"}

我在 Ansible UFW 文档或 UFW 本身中找不到任何会阻止它工作的东西。如果我删除“with_items”循环并分别输入每个 IP 子网,它们都可以工作,但这可能会导致一些非常长的剧本。谁能告诉我我做错了什么?

我使用的文档在这里:https://docs.ansible.com/ansible/latest/modules/ufw_module.html?highlight=ufw

编辑:包括以详细模式运行的文本:

failed: [192.168.255.20] (item=10.200.2.0/24) => {
    "changed": false,
    "invocation": {
        "module_args": {
            "app": null,
            "comment": null,
            "default": null,
            "delete": false,
            "direction": null,
            "from_ip": "['10.200.2.0/24']",
            "from_port": null,
            "insert": null,
            "interface": null,
            "log": false,
            "logging": null,
            "port": 22,
            "proto": "tcp",
            "route": false,
            "rule": "allow",
            "state": null,
            "to_ip": "any",
            "to_port": "22"
        }
    },
    "item": "10.200.2.0/24",
    "msg": "ERROR: Bad source address\n"

【问题讨论】:

  • 首先,修正缩进。其次,使用高 verbosity 运行 ansible 并使用 deubgger
  • 添加调试器:on_failed 以 [WARNING] 结尾:忽略无效属性:调试器。

标签: ansible yaml ufw


【解决方案1】:

问题是您将列表/数组传递给from_ip,而它需要一个字符串。试试这个:

  - name: Allow SSH in UFW
    ufw:
      rule: allow
      port: 22
      proto: tcp
      from_ip: "{{ item }}"
    with_items:
      - 192.168.0.0/24
      - 10.200.3.0/24
      - 10.200.2.0/24

【讨论】:

    猜你喜欢
    • 2021-12-18
    • 1970-01-01
    • 1970-01-01
    • 2023-01-13
    • 2020-09-08
    • 1970-01-01
    • 2022-06-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多