Linux-Ansible模块扩展

news/2025/2/24 10:13:53

文章目录

  • 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,并且备份文件内容

http://www.niftyadmin.cn/n/5864200.html

相关文章

剖析IO原理和零拷贝机制

目录 1 Linux的五种IO模型1.1 模型调用的函数1.1.1 recv函数1.1.2 select函数1.1.3 poll函数1.1.4 epoll函数1.1.5 sigaction函数 1.2 IO模型1.2.1 阻塞IO模型1.2.2 非阻塞IO模型1.2.3 IO复用模型1.2.4 信号驱动IO模型1.2.5 异步IO模型1.2.6 IO模型比较 2 Java的BIO、NIO、AIO2…

054 redisson

文章目录 使用Redisson演示可重入锁读写锁信号量闭锁获取三级分类redisson分布式锁 package com.xd.cubemall.product.config;import org.redisson.Redisson; import org.redisson.api.RedissonClient; import org.redisson.config.Config; import org.springframework.context…

TCP初始化序列号为什么要不一样

区分不同的连接(包括一些历史连接)、确保数据的顺序性、防止重放攻击(时间戳) 初始化序列号 ISN M F(localhost, localport, remotehost, remoteport)。 M是一个32位的计时器,这个计时器每隔 4 微秒加1,循环一次4.55小时F 是一…

深入解析思科 IOS 路由交换设备缓冲区机制

目录 一、数据包缓冲管理 二、数据包缓冲池 Packet buffer pool 1. 静态缓冲池 vs 动态缓冲池 2. 公共池 vs 私有池 三、系统缓冲 System Buffers 1. Buffer elements 2. Public buffer pools 四、缓冲区输出 & 丢包计数详解 1. Show buffers 2. Show interfa…

uni-app集成sqlite

Sqlite SQLite 是一种轻量级的关系型数据库管理系统(RDBMS),广泛应用于各种应用程序中,特别是那些需要嵌入式数据库解决方案的场景。它不需要单独的服务器进程或系统配置,所有数据都存储在一个单一的普通磁盘文件中&am…

goredis常见基础命令

基本操作 //删除键 exists,err: rdb.Exists(ctx,"key").Result() if err!nil{panic(err) } if exists>0{err rdb.Del(ctx,"key").Err()if err!nil{panic(err)} }string类型 //设置一个键值对 //0表示没有过期时间 err:rdb.Set(ctx,"key1",…

Layer2 扩容解决方案详解

Layer2 扩容解决方案详解 🔄 1. Layer2 基础概念 1.1 什么是 Layer2? Layer2 是建立在以太坊主网(Layer1)之上的扩容解决方案,它: 继承以太坊的安全性提供更高的交易吞吐量降低交易费用保持去中心化特性…

hot100_300. 最长递增子序列

hot100_300. 最长递增子序列 思路动态规划 给你一个整数数组 nums ,找到其中最长严格递增子序列的长度。 子序列 是由数组派生而来的序列,删除(或不删除)数组中的元素而不改变其余元素的顺序。例如,[3,6,2,7] 是数组 […