我在一些debian:stable机器上部署了一个Ansible剧本,目的是更新包索引缓存,安装ufw并以不可知的和版本不可知的方式设置它。
- name: Update all apt package index cache (apt update)
apt: update_cache=yes
- name: Install a latest ufw
apt:
name: ufw
state: latest
- name: Setup firewall with ufw
ufw:
rule: allow
port: 22,25,80,443在Bash中,我也经常使用ufw --force enable,但是我没有找到如何用不明飞行物文件中的Ansible语法将它添加到剧本中。
如果有的话,我应该如何正确地添加ufw --force enable?
发布于 2018-12-18 00:26:02
如果您只想运行shell命令,可以使用Ansible shell或command模块。
至于ufw,我认为它直接编辑规则文件。查看源代码,它在操作之前和之后运行,以检查这些文件是否更改了内容。
grep '^### tuple' /lib/ufw/user.rules /lib/ufw/user6.rules /etc/ufw/user.rules /etc/ufw/user6.rules就启用或禁用而言,这就是state操作的目的。
如果你说state: enabled,它会做ufw -f enable
if command == 'state':
states = {'enabled': 'enable', 'disabled': 'disable',
'reloaded': 'reload', 'reset': 'reset'}
execute(cmd + [['-f'], [states[value]]])https://unix.stackexchange.com/questions/488015
复制相似问题