ansible_find模块

bash 复制代码
found_files:
  changed: false
  files:
    - path: /etc/yum.repos.d/example1.repo
      mode: '0644'
      size: 1542
    - path: /etc/yum.repos.d/example2.repo
      mode: '0644'
      size: 2842
  matched: 2

1.find模块返回的格式

2.在后面调用的时候按照相应的key 取对应的value

3.支持正则表达式

4.debug模块可以查看结构

例子:

bash 复制代码
---
- hosts: localhost
  gather_facts: false
  tasks:
    - name: Find specific repo files on localhost
      find:
        paths: /etc/yum.repos.d/
        patterns: "mysql*"
      register: found_files

    - name: Display found repo files
      debug:
        var: found_files.files

- hosts: test_playbook
  gather_facts: false
  tasks:
    - name: Copy repo files to target nodes
      copy:
        src: "{{ item.path }}"
        dest: /etc/yum.repos.d/
      loop: "{{ hostvars['localhost']['found_files']['files'] }}"
相关推荐
Coder个人博客4 小时前
Linux6.19-ARM64 mm mmu子模块深入分析
大数据·linux·车载系统·系统架构·系统安全·鸿蒙系统
Doro再努力7 小时前
Vim 快速上手实操手册:从入门到生产环境实战
linux·编辑器·vim
wypywyp7 小时前
8. ubuntu 虚拟机 linux 服务器 TCP/IP 概念辨析
linux·服务器·ubuntu
Doro再努力8 小时前
【Linux操作系统10】Makefile深度解析:从依赖推导到有效编译
android·linux·运维·服务器·编辑器·vim
senijusene8 小时前
Linux软件编程:IO编程,标准IO(1)
linux·运维·服务器
忧郁的橙子.8 小时前
02-本地部署Ollama、Python
linux·运维·服务器
醇氧8 小时前
【linux】查看发行版信息
linux·运维·服务器
No8g攻城狮8 小时前
【Linux】Windows11 安装 WSL2 并运行 Ubuntu 22.04 详细操作步骤
linux·运维·ubuntu
XiaoFan0129 小时前
免密批量抓取日志并集中输出
java·linux·服务器
souyuanzhanvip9 小时前
ServerBox v1.0.1316 跨平台 Linux 服务器管理工具
linux·运维·服务器