ansible中,如何通过firewalld模块,将默认区设置为trusted
时间: 2025-01-04 17:40:20 浏览: 7
在Ansible中,如果你想要使用`firewalld`模块来配置防火墙并把默认区域设为"trusted",首先需要确保你已经安装了`ansible firewall`插件,并且对firewalld有基本了解。以下是一个示例 playbook 的片段:
```yaml
---
- name: Set default zone to trusted in firewalld
become: yes
vars:
firewall_zone: "trusted"
tasks:
- name: Ensure firewalld is installed and running
apt:
name: firewalld
state: present
- name: Check if firewalld is running
service:
name: firewalld
state: started
enabled: yes
- name: Set the default zone as trusted
firewalld:
zone: "{{ firewall_zone }}"
state: present
immutable: no
when: ansible_os_family == 'RedHat' or ansible_os_family == 'Fedora'
- name: Set the default zone as trusted (Debian-based systems)
command: |
set-zones-trusted --permanent trusted
when: ansible_os_family == 'Debian' or ansible_os_family == 'Ubuntu'
```
这个playbook会检查firewalld是否安装并运行,然后针对不同的操作系统家族(如Red Hat系和Debian系),分别调整默认zone为trusted。请注意,`set-zones-trusted --permanent trusted`命令只适用于Debian/Ubuntu系列系统。
阅读全文