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'] }}"
相关推荐
千里镜宵烛27 分钟前
Linux--进程概念
linux·运维·服务器
无聊的小坏坏30 分钟前
Linux 进程调度与管理:从内核管理到调度机制的深度解析
linux·ubuntu
FungLeo1 小时前
node 进程管理工具 pm2 的详细说明 —— 一步一步配置 Ubuntu Server 的 NodeJS 服务器详细实录 7
linux·服务器·ubuntu·pm2·node 进程管理
huangyuchi.2 小时前
【Linux】编译器gcc/g++及其库的详细介绍
linux·运维·服务器·笔记·编译器·gcc·g++
liuyunluoxiao4 小时前
内存管理【Linux操作系统】
linux
独行soc4 小时前
2025年渗透测试面试题总结-腾讯[实习]安全研究员(题目+回答)
linux·安全·web安全·面试·职场和发展·渗透测试
egoist20234 小时前
【Linux仓库】冯诺依曼体系结构与操作系统【进程·壹】
linux·运维·服务器·开发语言·操作系统·冯诺依曼体系结构
白总Server5 小时前
Golang 依赖注入:构建松耦合架构的关键技术
linux·运维·服务器·macos·架构·golang·xcode
夏沫mds5 小时前
不动产登记区块链系统(Vue3 + Go + Gin + Hyperledger Fabric)
linux·golang·区块链·gin·fabric
m0_746177198 小时前
小白畅通Linux之旅-----Linux日志管理
linux·运维·服务器