我想使用Ansible 配置UFW以允许从IP地址列表连接到端口80:
tasks:
- name: Allow port 80 HTTP
action: shell ufw allow from {{item}} to any 80/tcp
with_items: allowed_ips
Run Code Online (Sandbox Code Playgroud)
IP地址列表作为哈希存储在YAML文件中,在我的playbook vars/目录中:
---
allowed_ips:
xxx.xxx.xxx.xxx
xxx.xxx.xxx.xxx
Run Code Online (Sandbox Code Playgroud)
我正在使用with_items将IP地址拉入命令,但是当Ansible运行playbook时,它会连接IP地址,在每个IP之间插入一个空格:
ufw allow from xxx.xxx.xxx.xxx xxx.xxx.xxx.xxx to any 80/tcp
Run Code Online (Sandbox Code Playgroud)
ufw不接受这种语法,所以我想ufw为每个IP地址运行一次.我怎样才能做到这一点?
Ansible 1.6有一个管理模块ufw.http://docs.ansible.com/ufw_module.html它支持您尝试实现的列表.
ufw: rule=allow src={{ item }} port=80 proto=tcp
with_items:
- 10.0.0.0/8
- 172.16.0.0/12
- 192.168.0.0/16
Run Code Online (Sandbox Code Playgroud)
或者,您可以尝试https://galaxy.ansible.com,其中包含几个即用型角色ufw,其中一些还支持IP列表.
| 归档时间: |
|
| 查看次数: |
3304 次 |
| 最近记录: |