如果firewall_allowed_ports
在:
- name: port {{ item }} allowed in firewall
ufw:
rule: allow
port: "{{ item }}"
proto: tcp
with_items:
- 22
- "{{ firewall_allowed_ports }}"
Run Code Online (Sandbox Code Playgroud)
未定义,则发生此错误:
fatal: [host.example.com]: FAILED! => {"failed": true, "msg": "the field 'args'
has an invalid value, which appears to include a variable that is undefined.
Run Code Online (Sandbox Code Playgroud)
尝试解决问题
"{{ firewall_allowed_ports | }}"
Run Code Online (Sandbox Code Playgroud)
结果是:
fatal: [host.example.com]: FAILED! => {"failed": true, "msg": "template error
while templating string: expected token 'name', got 'end of print statement'.
String: {{ firewall_allowed_ports | }}"}
Run Code Online (Sandbox Code Playgroud)
jsc*_*ott 22
使用default([])
如果创建一个空列表firewall_allowed_ports
是不明确的。在with_items
空的时候会跳过它。
- name: port {{ item }} allowed in firewall
ufw:
rule: allow
port: "{{ item }}"
proto: tcp
with_items:
- 22
- "{{ firewall_allowed_ports | default([]) }}"
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
41143 次 |
最近记录: |