Ansible 常用模块详解:firewalld、setup实战

Ansible常用模块

firewalld模块

复制代码
-m firewalld 
    管理控制防火墙
指令参数 选项 说明
service http\udp..... 添加或者删除服务、协议
port 添加或者删除端口号
state enabled, disabled 开启或者禁止防火墙
zone public 设置防火墙区域
permanent yes, no 修改规则是否重启生效-永久,默认no
immediate yes, no 修改规则是否立即生效-临时,默认no
masquerade yes, no 启动或禁止防火墙地址伪装
复制代码
[root@ansible ~]# ansible webservers -m shell -a 'systemctl start firewalld'
192.168.92.20 | CHANGED | rc=0 >>

[root@ansible ~]# ansible webservers -m firewalld -a 'service=http immediate=yes permanent=yes state=enabled'
192.168.92.20 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python3"
    },
    "changed": true,
    "msg": "Permanent and Non-Permanent(immediate) operation, Changed service http to enabled"
}
[root@ansible ~]# ansible webservers -m shell -a 'systemctl stop firewalld'
192.168.92.20 | CHANGED | rc=0 >>

[root@ansible ~]#

setup模块

复制代码
-m setup 
    主要收集信息 
    通过facts组件实现功能
        用于采集被控端设备信息一个途径
指令参数 选项 说明
filter 采集信息
复制代码
[root@ansible ~]# ansible webservers -m setup -a 'filter=ansible_memory_mb'
192.168.92.20 | SUCCESS => {
    "ansible_facts": {
        "ansible_memory_mb": {
            "nocache": {
                "free": 1465,
                "used": 273
            },
            "real": {
                "free": 1238,
                "total": 1738,
                "used": 500
            },
            "swap": {
                "cached": 0,
                "free": 2047,
                "total": 2047,
                "used": 0
            }
        },
        "discovered_interpreter_python": "/usr/bin/python3"
    },
    "changed": false
}
[root@ansible ~]# ansible webservers -m setup -a 'filter=ansible_all_ipv4_addresses'
192.168.92.20 | SUCCESS => {
    "ansible_facts": {
        "ansible_all_ipv4_addresses": [
            "192.168.92.20"
        ],
        "discovered_interpreter_python": "/usr/bin/python3"
    },
    "changed": false
}
[root@ansible ~]# ansible webservers -m setup -a 'filter=nameserver'
192.168.92.20 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python3"
    },
    "changed": false
}
[root@ansible ~]#
相关推荐
Championship.23.242 小时前
Linux 3.0 锁机制与故障排查详解
linux·运维·服务器
天疆说2 小时前
Zotero Connector 在 Edge 里找不到桌面 Zotero(Linux / Zotero 9.0.6 / Edge 150)
linux·前端·edge
风123456789~4 小时前
【Linux专栏】ls 排除某个文件
linux·运维·服务器
IT曙光4 小时前
ubuntu apt-get离线源制作
linux·ubuntu
其实防守也摸鱼5 小时前
运维--学习阶段问题解答(1)(自测)
linux·运维·服务器·数据库·学习·自动化·命令模式
懒鸟一枚5 小时前
深入理解 Linux 内存、Swap 交换分区与分页机制的关系
java·linux·数据库
Darkwanderor6 小时前
对Linux的进程控制的研究
linux·运维·c++
bksczm9 小时前
linux之线程概念和控制
linux·开发语言·c++
爱网络爱Linux9 小时前
Linux proc 目录安全加固
linux·运维·rhce·rhca·红帽认证·proc 目录安全加固
hehelm9 小时前
Linux网络编程—TCP字典翻译系统
linux·开发语言·网络·c++·tcp/ip