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'] }}"
相关推荐
小张同学a.21 分钟前
MooseFS 分布式存储实战指南:部署、运维与 Pacemaker+SBD 高可用落地
linux·运维·分布式·pacemaker·moosefs·sbd
精进之道35 分钟前
拆开一个 .rpm 文件,里面到底装了什么?
linux
wuminyu41 分钟前
JDK21 FFM异步读取MSG_ZEROCOPY错误队列揭秘
java·linux·c语言·jvm·c++
Eloudy42 分钟前
sunshine - ubuntu 22.04, moonlight - mac OS26 远程桌面
linux·运维·ubuntu
苍狗T1 小时前
K8s 集群实战:基于 Harbor 私有仓库 + cri‑dockerd 完整部署
linux·运维·云原生·容器·kubernetes
石小千1 小时前
X86下载 ARM 架构的包
linux·运维
殷忆枫1 小时前
嵌入式Linux下基于FFmpeg实现MP4解码为JPG图片(SSD202D交叉编译实战)
linux·运维·ffmpeg
吃不吃早饭1 小时前
RHEL9 搭建 Harbor 私有仓库与 Ansible 自动化部署 Kubernetes 运行环境完整实践
kubernetes·自动化·ansible
牢姐与蒯1 小时前
Linux进程(二)之进程概念
linux·运维·服务器·ubuntu
草莓熊Lotso2 小时前
【Redis 初阶】Hash 类型深度解析:结构化数据存储的最优解
linux·网络·数据库·redis·tcp/ip·缓存·哈希算法