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

【Ansible】将文件部署到受管主机1:文件模块

文件模块与 Linux 文件管理相关的大部分常用模块都在ansible.builtin collection 中随 ansible-core 一起提供

ansible.builtin 中的常用件模块:

ansible.builtin 中的常用件模块 (续) :

确保受管主机上存在件:

- name: touch a file and set permissionsansible.builtin.file:path: /path/to/fileowner: uaer1group: grooup1mode:0640state: touch

修改文件属性:

- name: SELinux type is set to samba_share_tansible.builtin.file:path: /path/to/samba_filesetype: samba_share_file

在受管主机上复制和编辑件:

默认谁执行,文件属于谁,可指定:

Ansible.builtin.copy模块用于将控制节点上Ansible工作目录中的文件复制到选定的受管主机

- name:copy a file to managed hostsansible.builtin.copy:src: filedest: /path/to/file

Ansible.builtin.fetch模块用于从受管主机提取文件

- name: Retrieve SSH key from referrence hostsansible.builtin.fetch:src: “/home/{{ uaer }}/.ssh/id_rsa.pub”dest: “files/keys/{{ user }}.pub”

Ansible.builtin.lineinfile模块用于确保现有文件中存在特定的单行脚本

- name: add a line of text to fileansible.builtin.lineinfile:path: /path/to/fileline: ‘add this line to file’state: present

Ansibile.builtin.blockinfile模块用于将文本块添加到现有文件

- name: add additional lines to fileansible.builtin.blockinfile:    path: /path/to/fileblock:|first linesecond linestate: present

从受管主机中删除件:

使用ansible.builtn.file模块配合state: absent参数

- name: make a file does not xeist on managed hostansible.builtin.file:dest: /path/to/filestate: absent

检索受管主机上的件状态

使用ansible.builtin.stat模块

- name: verify the chedksum of a fileansible.builtin.stat:path: /path/to/filechecksum_algorithm: md5register: result- ansible.builtin.debugmsg: “the checksum of the file is {{ result.stat.checksum }}”


同步控制节点和受管主机之间的件:

使用ansible.posix.synchronnize模块,类似于rsync命令

- name: synchronize local file to remote filesansible.posix.synchoronize:src:filedest: /path/to/file

http://www.dtcms.com/a/342739.html

相关文章:

  • Autoware Universe 感知详解 | 第二节 宏观认识Autoware Universe感知模块整体架构
  • C++中的内存管理(二)
  • 第四章:大模型(LLM)】07.Prompt工程-(6)受限生成和引导生成
  • 机械试验台功能量具平台:铸铁工装平台
  • 阿里云对象存储OSS之间进行数据转移教程
  • 小迪安全v2023学习笔记(六十八讲)—— Java安全原生反序列化SpringBoot攻防
  • iOS沙盒机制
  • 【系统信息相关】datecal命令
  • React + Antd+TS 动态表单容器组件技术解析与实现
  • (栈)Leetcode155最小栈+739每日温度
  • Python爬虫实战:研究puzzle,构建谜题类数据采集分析系统
  • 编程语言与存储过程:业务处理的速度与取舍
  • 3ds Max 渲染动画总模糊?
  • 基于stm32的智能建筑能源管理系统/基于单片机的能源管理系统
  • 【Java SE】认识数组
  • 【Protues仿真】基于AT89C52单片机的舵机和直流电机控制
  • 【新启航】3D 扫描逆向抄数全流程工具与技能:从手持设备到 CAD 建模的 10 项核心配置解析
  • windows10安装playwright
  • Workerman在线客服系统源码独立部署
  • 笔记本电脑Windows+Ubuntu 双系统,Ubuntu无法挂载Windows的硬盘 报错问题解决
  • TDengine IDMP 运维指南(常见问题)
  • 天眼应急案例(二)
  • 一句话生成uml图相关操作
  • MTK平台蓝牙学习-- 如何查看蓝牙连接参数
  • Vitest 测试框架完全指南 – 极速单元测试解决方案
  • selenium3.141.0执行JS无法传递element解决方法
  • 【自记】Power BI 中 VALUES 和 DISTINCT 在可接收的参数类型上的区别。
  • 【每天一个知识点】 时空组学(Spatiotemporal Omics)
  • Nginx学习记录
  • 移动端网页调试实战 IndexedDB 与本地存储问题的排查与优化