ansible部分模块学习

ansible模块学习

copy模块

copy模块
src source 源⽂件
dest destination ⽬标
backup backup=yes 则会在覆盖前进⾏备份
mode 修改权限
owner 修改为指定所有者
group 修改为指定⽤户组

案例1:传输/root/work/scripts/net-tools-install.sh⽂件到/opt/net-tools-install.sh

bash 复制代码
ansible all -m copy -a 'src=/root/work/scripts/net-tools-install.sh dest=/opt/net-tools-install.sh'

案例2:传输/root/work/scripts/net-tools-install.sh⽂件到/opt/net-tools-install.sh,先备份,后修改

bash 复制代码
ansible all -m copy  -a 'src=/root/work/scripts/net-tools-install.sh dest=/opt/net-tools-install.sh backup=yes'

systemd模块

systemd模块
name ⽤于指定服务名称
enabled 控制服务的开机⾃启动 enabled=yes /enabled=no
state 表示服务开,关,重启... state=started 开启 state=stopped 关闭 state=reloaded 重读配置⽂件(服务⽀持) sshd,nfs state=restarted 重启(关闭再开启)
daemon-reload yes是否重新加载对应的服务的管理配置⽂件(讲解了systemctl配置⽂件.)

案例1:关闭防火墙

bash 复制代码
ansible all -m systemd -a 'name=firewalld enabled=no state=stopped'
ansible all -a 'systemctl status firewalld'

案例2:开启防火墙

bash 复制代码
ansible all -m systemd -a 'name=firewalld enabled=yes state=started'
ansible all -a 'systemctl status firewalld'

案例3:重启网络服务

bash 复制代码
ansible all -m systemd -a 'name=network state=restarted'

yum模块

通过yum命令安装软件

yum模块
name 指定软件包名字
state installed 安装(present) removed 删除 (absent) latest安装或更新

案例1:安装 lrzsz

bash 复制代码
ansible all -m yum -a 'name=lrzsz state=installed'

案例2:安装sl,cowsay, aalib

bash 复制代码
ansible all -m yum -a 'name=sl,cowsay,aalib state=installed'

get_url模块

get_url下载功能
url 指定要下载的地址
dest 下载到哪个⽬录

案例1:下载nginx源码包到 /opt目录下

下载地址: https://nginx.org/download/nginx-1.24.0.tar.gz

bash 复制代码
ansible all -m get_url -a 'url=https://nginx.org/download/nginx-1.24.0.tar.gz dest=/opt'
相关推荐
待什么青丝17 分钟前
【TMS570LC4357】之相关驱动开发学习记录2
c语言·arm开发·驱动开发·单片机·学习
行云流水剑28 分钟前
【学习记录】如何使用 Python 提取 PDF 文件中的内容
python·学习·pdf
虾球xz1 小时前
CppCon 2015 学习:CLANG/C2 for Windows
开发语言·c++·windows·学习
yzx9910132 小时前
Linux 系统中的算法技巧与性能优化
linux·算法·性能优化
fengyehongWorld2 小时前
Linux Docker的简介
linux·docker
蓝婷儿2 小时前
6个月Python学习计划 Day 17 - 继承、多态与魔术方法
开发语言·python·学习
曹瑞曹瑞3 小时前
VMware导入vmdk文件
linux·运维·服务器
Johny_Zhao3 小时前
2025年6月Docker镜像加速失效终极解决方案
linux·网络·网络安全·docker·信息安全·kubernetes·云计算·containerd·yum源·系统运维
持续前进的奋斗鸭3 小时前
Postman测试学习(1)
学习·postman
hello kitty w3 小时前
Python学习(7) ----- Python起源
linux·python·学习