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'] }}"
相关推荐
微露清风7 分钟前
系统性学习Linux-第五讲-基础IO
linux·运维·学习
柏木乃一7 分钟前
Linux线程(8)基于单例模式的线程池
linux·运维·服务器·c++·单例模式·操作系统·线程
17(无规则自律)16 分钟前
嵌入式 Linux 启动:设备树的加载、传递和解析全流程分析
linux·stm32·嵌入式硬件·unix
kebidaixu24 分钟前
VS Code安装 Remote - SSH 扩展
linux·服务器·ssh
AI+程序员在路上33 分钟前
瑞芯微 RV1126B ADB 调试命令完全指南
linux·adb
小茗的嵌入式学习日记37 分钟前
基于IMX6ULL的车载中控系统
linux·c语言·qt
sc_爬坑之路40 分钟前
Linux 部署 Redis:一主一从 + Sentinel 完整实战
linux·redis·sentinel
从入门到放弃-咖啡豆1 小时前
Alibaba Cloud Linux 部署.NET 8 环境 项目运行
linux·服务器·.net·.net core
wongHome1 小时前
Ubuntu的Anaconda环境如何安装安装rasterio
linux·ubuntu
骆驼10241 小时前
Linux PAM(Pluggable Authentication Modules)完整指南——从入门原理到进阶机制,再到实战配置
linux·安全·pam