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'] }}"
相关推荐
Joseph Cooper36 分钟前
STM32MP157 Linux驱动学习笔记(四):典型总线与设备模型(SPI/USB)
linux·stm32·学习
坚持就完事了1 小时前
Linux中的mv命令
linux·运维·服务器
SongYuLong的博客1 小时前
Claude Code安装配置(Linux)
linux·运维·服务器
栈低来信1 小时前
kernel信号量源码分析
linux
结衣结衣.2 小时前
手把手教你实现文档搜索引擎
linux·c++·搜索引擎·开源·c++11
sdm0704273 小时前
进程间通信
linux·运维·服务器
蚰蜒螟3 小时前
Linux内核启动(init)与程序执行(execve)深度解析:从kernel_init到load_elf_binary
linux·运维·服务器
thethefighter3 小时前
信创综合档案管理系统单机版部署与使用
linux·银河麒麟·档案管理系统·单机版·nhdeep·信创版·综合档案管理系统
道清茗3 小时前
【RH294知识点汇总】第 6 章 《 管理复杂的 Play 和 Playbook 》常见问题
linux·服务器·网络
哼?~3 小时前
序列化与反序列化
linux·网络