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 ~]#
相关推荐
爱喝水的鱼丶1 小时前
SAP-ABAP:ABAP 用户出口参数传递与上下文获取:SAP 标准数据读取与交互逻辑实现
运维·性能优化·交互·sap·abap·经验交流·出口
IT大白鼠1 小时前
PentestGPT作为AI运维编排工作流自动化底座的技术架构与应用价值评估
运维·人工智能·自动化·pentestgpt
M78佐菲1 小时前
c语言学习笔记:排序与查找方法整理
linux·c语言·笔记·学习·算法
ltl2 小时前
QUIC 协议拆解(上):为什么 TCP 改不动了
linux
j7~2 小时前
【Git】《Git 系列指南(二):Git基本操作与 reset 三种模式》
运维·git·git安装·git基本操作·git配置·创建git仓库·git reset三种模式
zzzll11112 小时前
n8n 工作流自动化平台入门指南
运维·自动化
Hrain-AI2 小时前
Anthropic oncall-kit 开源拆解:运维 Agent 落地范式的四基石与权限边界
运维·人工智能·开源
HXDGCL3 小时前
从“转盘困局”到“直线破局”:华创力科技PTS精密分度输送系统如何重塑自动化产线
运维·科技·自动化
戴西软件3 小时前
国内有哪些智能化RPA工具?——从“录数据”到“做判断”,国产数字员工正在重新定义自动化
运维·自动化·rpa
Linux-lucky3 小时前
28-Linux学习之旅之Maven与Nexus制品库
linux·运维·学习·nginx·tomcat·maven