如果启用了ufw,如何运行ansible任务?
只有在Ubuntu服务器上启用了ufw时,我才需要运行一些任务 伪代码看起来像:如果启用了ufw,如何运行ansible任务?,ansible,ufw,Ansible,Ufw,只有在Ubuntu服务器上启用了ufw时,我才需要运行一些任务 伪代码看起来像: - name: detect if ufw is enabled magical_module: ??? register: ufw_is_enabled - name: my task when: ufw_is_enabled 我只看到这种非合法的解决方案: 远程执行ufs状态 分析输出: 启用ufw时可能有一些文件?在这种情况下,可以使用stat模块。还有其他解决方案吗?大致如下:
- name: detect if ufw is enabled
magical_module: ???
register: ufw_is_enabled
- name: my task
when: ufw_is_enabled
我只看到这种非合法的解决方案:
- 远程执行
ufs状态
- 分析输出:
启用ufw时可能有一些文件?在这种情况下,可以使用
stat
模块。还有其他解决方案吗?大致如下:
- name: check whether ufw status is active
shell: ufw status
changed_when: False
ignore_errors: True
register: ufw_check
- debug:
msg: "{{ ufw_check }}"
- name: do something if ufw is enabled
shell: echo
when: "'inactive' not in ufw_check.stdout"
确保使用been:True
,因为这是必需的
要使用UFW模块管理系统
例如,您可以在希望禁用UFW的系统上禁用UFW:
- name: Disable UFW on hosts
ufw:
state: disabled # unloads firewall and disables firewall on boot.
- name: Disable UFW on hosts
ufw:
state: disabled # unloads firewall and disables firewall on boot.