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 ~]#
相关推荐
桌面运维家8 小时前
IDV云桌面vDisk机房网络管控访问限制部署方案
运维·服务器·网络
ShineWinsu8 小时前
对于Linux:动静态库的制作与原理的解析—下
linux·运维·服务器·进程·链接·虚拟地址空间·
RH2312119 小时前
2026.4.16Linux 管道
java·linux·服务器
handler0110 小时前
Linux: 基本指令知识点(2)
linux·服务器·c语言·c++·笔记·学习
liuyukuan10 小时前
如何在win11上打开 WSL2(Windows 的 Linux 子系统)?
linux·windows
KKKlucifer10 小时前
国内堡垒机如何打通云网运维安全一体化
运维·安全
橙子也要努力变强10 小时前
Linux信号机制
linux·服务器·网络
shughui10 小时前
FinalShell / Xshell 完整教程(下载+安装+使用,2026最新版)
linux·fiddler·xshell·xftp·finalshell·远程连接工具
wydd99_lll11 小时前
docker特权模式下逃逸
运维·docker·容器
程序猿编码11 小时前
给你的网络流量穿件“隐形衣“:手把手教你用对称加密打造透明安全隧道
linux·开发语言·网络·安全·linux内核