当前位置: 首页 > news >正文

Linux-Ansible模块扩展

文章目录

  • Archive Unarchive
  • Setup模块
  • Lineinfile Replace

https://i-blog.csdnimg.cn/blog_migrate/58966ddd9b29aabe8841f5ec34f0d31c.gif

🏡作者主页:点击!

🤖Linux专栏:点击!

⏰️创作时间:2025年02月23日18点11分

在这里插入图片描述

Archive Unarchive

在这里插入图片描述

Archive和Unarchive模块

需求:主机192.168.1.100中 /tmp 中创建文件 test1、test2 将它们打包为 test.zip,同时删除 test1 和 test2,再将其解压至 /tmp /file 目录中

ansible 192.168.1.100 -m file -a "path=/tmp/test1 state=touch"  #创建文件
ansible 192.168.1.100 -m file -a "path=/tmp/test2 state=touch"  #创建文件
ansible 192.168.1.100 -m archive -a "path=/tmp/test1,/tmp/test2 format=zip remove=yes dest=/tmp/test.zip"
#打包文件删除源文件

ansible 192.168.1.100 -m unarchive -a "remote_src=yes src=/tmp/test.zip dest=/tmp/file" #此时解压缩remote_src=yes意思是压缩包来自被控制节点,也就是远端节点

ansible 192.168.1.100 -m unarchive -a "copy=no src=/tmp/test.zip dest=/tmp/file/" #进行解压缩操作,因为是在远端主机上

#解压到的路径必须是一个已经存在的目录

Setup模块

在这里插入图片描述

不加参数表示的是全部信息

  • filter:针对数据进行收集
  • gather_subset:收集全量信息的子集,范围比 filter 更广一点
  • gather_timeout:限定整个收集任务的超时时间

Setup模块实践

ansible 192.168.1.100 -m setup    #收集信息

Lineinfile Replace

在这里插入图片描述

Lineinfile Replace模块实践

ansible 192.168.1.100 -m lineinfile -a "path=/tmp/file/test regexp='^Listen' line='Listen 8080' state=present"  #使用命令对文件内容进行插入,此时就会出现一个test文件内容为Listen 8080
ansible 192.168.1.100 -m replace -a "path=/tmp/file/test regexp='Listen' replace='LISTEN' backup=yes"
#将文件内容 Listen 改为 LISTEN,并且备份文件内容

相关文章:

  • 基于Java的实时数据流处理框架设计与实现
  • 从训练到部署:基于YOLOv5和TensorRT的人脸口罩检测系统全流程实战指南(开源代码)
  • 修改`FSL Yocto Project Community BSP`用到的u-boot源码,使其能适配百问网(100ask)的开发板
  • 架构师面试(六):熔断和降级
  • 智能优化算法:莲花算法(Lotus flower algorithm,LFA)介绍,提供MATLAB代码
  • 软开的过程
  • nodejs:vue 3 + vite 作为前端,将 html 填入<iframe>,在线查询英汉词典
  • Spring Boot 多模块怎么统一管理
  • python网络安全怎么学 python做网络安全
  • Git学习笔记
  • Java 注解
  • 点云的几何特征
  • git常用指令详解
  • 【多语言生态篇六】【DeepSeek×Node.js:WebSocket实时服务从入门到“超神“指南(史诗级万字拆解)】
  • [ TypeScript ] “undefined extends xxx“ 总是为 true 的 bug
  • MySQL分库分表后单表数据还是过大怎么办
  • javascript闭包在实际项目中有哪些应用场景?请举例说明。
  • JavaScript系列(84)--前端工程化概述
  • pytorch3d安装记录
  • 【JAVA】io流之缓冲流
  • 网站 托管/搜索引擎营销实训报告
  • 网站改域名审核时间/seo技术快速网站排名
  • 做网站设计的提成点是多少/seo推广培训中心
  • 查找人网站 优帮云/百度关键词搜索排名多少钱
  • 做企业网站织梦和wordpress哪个好/站长之家怎么用
  • 查询工具类网站制作/模板式自助建站