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'] }}"
相关推荐
chicheese15 分钟前
Linux 面试速查表:从初级到高级,附高频场景答题模板
linux·运维
Linux-lucky43 分钟前
32-38-Linux学习之旅之MySQL综合
linux·运维·学习·mysql·ubuntu
vortex52 小时前
常用终端模拟器全面对比:Kitty、WezTerm、Ghostty 与 Konsole
linux
INGNIGHT3 小时前
270 · 电话号码的字母组合II(Trie)
linux·算法
zly35003 小时前
VMware Converter Standalone 物理机转化为虚拟机后源1硬盘变成了2个硬盘(2个硬盘文件)虚拟机无法启动。
linux·运维·服务器
GeW4 小时前
从内核到数据:Linux与工业数据库如何支撑高端制造
linux
小小的木头人6 小时前
Linux systemd Service 与 Timer 定时任务原理及实战
linux
熊明才7 小时前
WSL2 网络突然瘫痪(Network is unreachable / 没有 eth0)最短修复指南(2026年9月20日亲测可用)
linux·windows·wsl2
Tairitsu_H7 小时前
[Linux系统] 自动化构建make / Makefile | 进度条
linux·操作系统·makefile·make
行者全栈架构师7 小时前
大模型运维准确率不到 50%?我们用 DeepSeek V4 测了 5 大场景,结果出人意料
linux·人工智能·开源