Ansible模块介绍——防火墙模块

本文涉及的产品
云防火墙,500元 1000GB
简介: Ansible模块介绍——防火墙模块

防火墙模块

firewalld 模块

  • State 指防火墙策略状态enable disable present absent
  • service 指定服务
  • immediate 立即启用
  • port 端口 port=80/tcp
  • permanent 永久生效

示例

首先开启防火墙

[root@master ~]# ansible webservers -m service -a 'name=firewalld state=started enabled=true'

1、允许http服务

[root@master ~]# ansible webservers -m firewalld -a 'service=http permanent=true immediate=true state=enabled'

2、允许端口

[root@master ~]# ansible webservers -m firewalld -a 'port=80/tcp permanent=true immediate=true state=enabled'

3、富规则

[root@master ~]# ansible webservers -m firewalld -a 'rich_rule="rule family=ipv4 source address=192.168.150.0/24 service name=http accept" permanent=true immediate=true state=enabled'

4、端口转发

[root@master ~]# ansible webservers -m firewalld -a 'rich_rule="rule family=ipv4 forward-port port=443 protocol=tcp to-port=8443" permanent=true immediate=true state=enabled'

5、masquerade

[root@master ~]# ansible webservers -m firewalld -a 'mquerade=yes

selinux模块

功能:管理远端主机的 SELINUX 防火墙;

  • state Selinux模式:enforcing、permissive、disabled
  • policy targeted

示例

1.设置 selinux 为 enforcing

[root@xuzhichao ~]# ansible 192.168.20.23 -m selinux -a 'state=enforcing policy=targeted'
[root@nginx03 ~]# grep "^SELINUX" /etc/selinux/config
 SELINUX=enforcing
 SELINUXTYPE=targeted

2.设置 selinux 为 disabled:

[root@xuzhichao ~]# ansible 192.168.20.23 -m selinux -a 'state=disabled'
[root@nginx03 ~]# grep "^SELINUX" /etc/selinux/config
SELINUX=disabled
SELINUXTYPE=targeted

sefcontext模块

受控主机缺少依赖policycoreutils-python

[root@server ~]# ansible node1 -m yum -a 'name=policycoreutils-python-utils-2.9-16.el8.noarch state=installed' 
[root@server ~]# ansible node1 -m sefcontext -a 'target=/www setype=httpd_sys_content


相关文章
|
12月前
|
运维 Shell Linux
Ansible自动化运维工具之常用模块使用实战(5)
Ansible自动化运维工具之常用模块使用实战(5)
279 0
|
2月前
|
缓存 Shell Linux
[ansible]常用内置模块
[ansible]常用内置模块
|
3月前
|
Shell 应用服务中间件 Linux
Ansible的常用模块
Ansible的常用模块
56 6
|
3月前
|
Shell 数据安全/隐私保护
Ansible Ad-hoc,命令执行模块
Ansible Ad-hoc,命令执行模块
31 1
|
3月前
|
运维 Linux 应用服务中间件
Linux之自动化运维工具ansible、ansible模块(2)
Linux之自动化运维工具ansible、ansible模块(2)
|
3月前
|
运维 Linux Shell
Linux之自动化运维工具ansible、ansible模块(1)
Linux之自动化运维工具ansible、ansible模块(1)
|
5月前
|
算法 安全 Linux
Ansible 中的copy 复制模块应用详解
Ansible 中的copy 复制模块应用详解
307 1
|
12月前
|
运维 Linux
Ansible自动化运维工具之常用模块使用实战(6)
Ansible自动化运维工具之常用模块使用实战(6)
177 0
|
5月前
|
网络安全
使用ansible-playbook关闭防火墙
使用ansible-playbook关闭防火墙
71 0
|
11月前
|
网络安全 数据安全/隐私保护
ansible的get_url模块
ansible的get_url模块
121 1