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'] }}"
相关推荐
BestOrNothing_20154 小时前
(2)联想拯救者安装 Ubuntu 双系统前的 BIOS 设置全过程
linux·bios·拯救者·ubuntu22.04·联想lenovo
23.4 小时前
【Linux】grep命令终极指南
linux
巨斧空间掌门4 小时前
JDK17 下载 windows Linux
linux·运维·服务器
AI+程序员在路上5 小时前
CANopen 协议:介绍、调试命令与应用
linux·c语言·开发语言·网络
learndiary5 小时前
2026.03.12~2026.03.19制作的共7个视频及简介
linux·视频·学习日记小店
JiMoKuangXiangQu5 小时前
Linux:ARM64 中断处理简析
linux·arm64 中断
小生不才yz6 小时前
【Makefile 专家之路 | 函数篇】11. 终极奥义:eval 函数——动态生成规则的“核武器”
linux
皮卡蛋炒饭.6 小时前
进程得控制
linux·运维·服务器
YMWM_6 小时前
Install pyrealsense2 on the jetson thor
linux·realsense2
BestOrNothing_20157 小时前
(3)Ubuntu 22.04 双系统安装全过程记录
linux·ubuntu22.04·双系统安装