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 ~]#
相关推荐
我爱学习好爱好爱2 小时前
Ansible Playbook介绍 playbook的编写要求 playbook多任务案例
linux·运维·ansible
今儿敲了吗2 小时前
Linux学习笔记第三章——基础命令(一)
linux·笔记·学习
我科绝伦(Huanhuan Zhou)2 小时前
MySQL数据库备份管理系统新增备份任务巡检功能
运维·数据库·mysql
奇树谦2 小时前
Ubuntu 24 常用截图工具一键安装脚本+自定义快捷键配置指南
linux·运维·ubuntu
吕司2 小时前
Linux的ELF文件与虚拟地址空间
linux·运维·服务器
SPC的存折2 小时前
4、Ansible之Playbook变量应用
linux·前端·chrome·ansible
倔强的石头1062 小时前
【Linux指南】基础IO系列(三):Linux 系统 IO 接口 —— 深入内核的文件操作
linux·数据库
biubiubiu07062 小时前
Ubuntu 22.04 中 cron 和 systemd timer 的区别与使用
linux·运维·ubuntu
Agent产品评测局2 小时前
医药行业合规自动化平台选型,核心要点详解:企业级智能体驱动的合规化演进与实测分析
运维·网络·人工智能·ai·chatgpt·自动化