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'
相关推荐
nashane3 小时前
HarmonyOS 6学习:深入解析冷启动中的ArkCompiler
学习·华为·harmonyos
liulilittle3 小时前
Linux Swap 文件配置与持久化(虚拟内存)
linux·运维·服务器
linux修理工3 小时前
使用codebuddy学习kafka
分布式·学习·kafka
青梅橘子皮4 小时前
Linux---进程控制(2)(进程程序替换)
linux·c++·算法
阿寻寻4 小时前
【人工智能学习260612-软件测试篇】小工具实现 [特殊字符] Prompt工程 + RAG思路 + API调用 + 自动化测试
人工智能·功能测试·学习·prompt
零陵上将军_xdr4 小时前
从沙子到CPU——计算机硬件基础入门
linux·运维·硬件架构
vortex54 小时前
Linux 命令工具箱:util-linux 与 GNU Coreutils
linux·运维·gnu
荒--4 小时前
MSF 使用
linux·运维·服务器
狮子再回头4 小时前
relhat9.1 sshd配置
linux·服务器·网络
吃好睡好便好4 小时前
白发的根源和应对
学习·生活