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'
相关推荐
Coder个人博客14 小时前
Linux6.19-ARM64 mm mmu子模块深入分析
大数据·linux·车载系统·系统架构·系统安全·鸿蒙系统
Doro再努力17 小时前
Vim 快速上手实操手册:从入门到生产环境实战
linux·编辑器·vim
wypywyp17 小时前
8. ubuntu 虚拟机 linux 服务器 TCP/IP 概念辨析
linux·服务器·ubuntu
阿蒙Amon17 小时前
TypeScript学习-第10章:模块与命名空间
学习·ubuntu·typescript
AI绘画哇哒哒17 小时前
【干货收藏】深度解析AI Agent框架:设计原理+主流选型+项目实操,一站式学习指南
人工智能·学习·ai·程序员·大模型·产品经理·转行
Doro再努力17 小时前
【Linux操作系统10】Makefile深度解析:从依赖推导到有效编译
android·linux·运维·服务器·编辑器·vim
senijusene17 小时前
Linux软件编程:IO编程,标准IO(1)
linux·运维·服务器
忧郁的橙子.17 小时前
02-本地部署Ollama、Python
linux·运维·服务器
醇氧17 小时前
【linux】查看发行版信息
linux·运维·服务器
戌中横18 小时前
JavaScript——预解析
前端·javascript·学习