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

Ansible学习笔记6

stat模块:获取文件的状态信息,类似Linux的stat状态。

获取/etc/fstab文件的状态。

[root@localhost tmp]# ansible group1 -m stat -a "path=/etc/fstab"
192.168.17.106 | SUCCESS => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"},"changed": false,"stat": {"atime": 1693322482.6770303,"attr_flags": "","attributes": [],"block_size": 4096,

得到了json格式的文件。key-value。对于开发的人很喜欢这种键值对的格式,开发的时候非常方便。能够通过key得到值。

template模块(拓展)

与copy模块功能几乎是一样的。

template模块是不能拷贝目录的。

文件拷贝是可以的。

[root@localhost ~]# ansible group1 -m template -a "src=/etc/hosts dest=/etc/hosts"
192.168.17.106 | SUCCESS => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"},"changed": false,"checksum": "ae3c3e4f757591751a520e8a4bba45490e6c3164","dest": "/etc/hosts","gid": 0,"group": "root","mode": "0644","owner": "root","path": "/etc/hosts","size": 226,"state": "file","uid": 0
}
192.168.17.105 | SUCCESS => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"},"changed": false,"checksum": "ae3c3e4f757591751a520e8a4bba45490e6c3164","dest": "/etc/hosts","gid": 0,"group": "root","mode": "0644","owner": "root","path": "/etc/hosts","size": 226,"state": "file","uid": 0
}

那我们涉及到copy文件,建议还是使用copy模块来实现。

template模块首先使用变量来渲染jinja2模板文件成普通文件,然后再复制过去。而copy不支持。(jinja2是一个基于python的模板引擎。)

fetch模块:

fetch模块跟copy模块功能类似,但是作用相反,用于把远程主机上的文件拷贝到本地。

场景:把很多服务器上的日志拷贝到本地。日志集中管理。日志分析。

PV:pageview:点击率。

将/tmp/1.txt文件拷贝到本地。根据每台主机的IP地址或者别名存放在/tmp目录下。

[root@localhost ~]# ansible group1 -m fetch -a "src=/tmp/1.txt dest=/tmp"
192.168.17.105 | CHANGED => {"changed": true,"checksum": "d2911a028d3fcdf775a4e26c0b9c9d981551ae41","dest": "/tmp/192.168.17.105/tmp/1.txt","md5sum": "0d59da0b2723eb03ecfbb0d779e6eca5","remote_checksum": "d2911a028d3fcdf775a4e26c0b9c9d981551ae41","remote_md5sum": null
}
192.168.17.106 | CHANGED => {"changed": true,"checksum": "b27fb3c4285612643593d53045035bd8d972c995","dest": "/tmp/192.168.17.106/tmp/1.txt","md5sum": "cd0bd22f33d6324908dbadf6bc128f52","remote_checksum": "b27fb3c4285612643593d53045035bd8d972c995","remote_md5sum": null
}

主要为了区分不同的agent主机。

[root@localhost tmp]# ll
total 4
drwxr-xr-x  3 root root  17 Aug 30 13:36 192.168.17.105
drwxr-xr-x  3 root root  17 Aug 30 13:36 192.168.17.106
-rwx------. 1 root root 836 Aug 29 14:56 ks-script-edvhAX
-rw-------. 1 root root   0 Aug 29 14:53 yum.log
[root@localhost tmp]# cat 192.168.17.105/tmp/1.txt
agent1
[root@localhost tmp]# cat 192.168.17.106/tmp/1.txt
agent2

如果只fetch一个文件,那么路径也是这么一个过程。

说明:需要注意的是,不能fetch目录。

http://www.lryc.cn/news/150288.html

相关文章:

  • Linux挖矿程序清除
  • 使用Git和Github上传代码文件
  • OpenAI发布ChatGPT企业级版本
  • vue3中axios的使用方法
  • 【docker】容器的运行、停止、查看等基本操作
  • Python|OpenCV-鼠标自动绘制图像(4)
  • IDEA 设置提示信息
  • 清理docker镜像方法
  • windows 搭建 swoole开发环境(官网已支持)
  • matlab的基本使用
  • hznuoj---python查找最大字母
  • Leetcode---360周赛
  • CocosCreator3.8研究笔记(三)CocosCreator 项目结构说明及编辑器的简单使用
  • html5学习笔记18-web存储、web sql、web worker
  • 大数据专业毕业能从事什么工作
  • avalonia、WPF使用ScottPlot动态显示ECG心电图
  • 国内数学公式识别软件对比
  • SCOPE_IDENTITY什么意思
  • 构建现代应用:Java中的热门架构概览
  • Axure RP软件安装包分享(附安装教程)
  • 关于微信小程序的生命周期
  • 【数据结构】带头双向循环链表及其实现
  • 问道管理:日换手率达20是好是坏?
  • 勃艮第葡萄酒是如何分级的?
  • 使用awvs进行web安全扫描
  • 抖音小程序开发教学系列(1)- 抖音小程序简介
  • 【4.Vue兄弟组件之间传值-Bus总线】
  • element中Notification组件(this.$notify)自定义样式
  • Manjaro安装使用
  • 【iOS】折叠cell