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 ~]#
相关推荐
Sokach10153 小时前
Linux Shell 脚本从零到能用:一个新手的一天学习总结
linux
SelectDB19 小时前
Litefuse 开源并推出单进程轻量模式,25 秒就能跑起来的 Agent 可观测与评估平台
运维·后端·自动化运维
AlfredZhao19 小时前
Docker 容器时区不对,`timedatectl` 不存在怎么办?
linux·timezone
zzzzzz3102 天前
9K Star 炸裂开源!这个 C 语言写的代码知识图谱,把 Linux 内核索引压缩到了 3 分钟
linux·服务器·sql
XIAOHEZIcode2 天前
Linux系统鼠标偏移常见原因以及修复方案
linux·运维·游戏
用户0328472220703 天前
如何搭建本地yum源(上)
运维
A小辣椒4 天前
TShark:Wireshark CLI 功能
linux
A小辣椒4 天前
TShark:基础知识
linux
AlfredZhao4 天前
OCI 明明分配了 200G 系统盘,为什么 df 只看到 30G?
linux·oci
AlfredZhao5 天前
vi 删除指定范围的行,不用再反复按 dd
linux·vi