我想允许使用ufw从某些主机/组到服务器的连接 模组 这是我的清单文件
[web]
foo.domain
bar.domain
[db]
foo.anotherdomain
[production:children]
web
db
这是我的剧本
- name: gather all hosts facts
user: root
hosts: all
- name : allow access from web group to database
ufw:
rule: allow
src: "{{ hostvars['web']['ansible_default_ipv4'].address }}"
port: 5432
comment: allow postgres from web
但是我得到这个错误
fatal: [142.93.128.240]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: \"hostvars['web}}']\" is undefined\n\nThe error appears to have been in '/home/reza/labs/testtask.yml': line 10, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n tasks:\n - debug: msg=\"{{hostvars['web}}']['ansible_default_ipv4'].address}}\"\n ^ here\nWe could be wrong, but this one looks like it might be an issue with\nmissing quotes. Always quote template expression brackets when they\nstart a value. For instance:\n\n with_items:\n - {{ foo }}\n\nShould be written as:\n\n with_items:\n - \"{{ foo }}\"\n"}
我如何遍历组或单个主机的所有成员并选择一个变量值(在这种情况下为主机ip)?