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'] }}"
相关推荐
不会kao代码的小王20 分钟前
零基础也能搭博客?
linux·windows·后端
weixin_462446232 小时前
ubuntu/kali安装k8s
linux·ubuntu·kubernetes
lys_8283 小时前
【linux】解决NAT模型下使用Xshell连接虚拟机显示22端口connection failed问题
linux·运维·服务器
序属秋秋秋4 小时前
《Linux系统编程之系统导论》【冯诺依曼体系结构 + 操作系统基本概述】
linux·运维·服务器·c语言·ubuntu·操作系统·冯诺依曼体系结构
她说彩礼65万5 小时前
C# 特性详解
linux·服务器·c#
Hi202402179 小时前
消除FFmpeg库的SONAME依赖
linux·ffmpeg
gfanbei10 小时前
ARM V8 Cortex R52 上电运行在什么状态?— Deepseek 解答
linux·arm开发·嵌入式硬件
liu****11 小时前
14.日志封装和线程池封装
linux·开发语言·c++
云动雨颤11 小时前
访问宝塔面板安全入口404?SSH命令轻松解决
linux·运维·安全
NPE~11 小时前
[Linux命令分享]日志查看 — — less
linux·运维·less·常用命令·日志查看