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'] }}"
相关推荐
꯭自꯭闭꯭5 小时前
达梦事物特性及MVCC
linux·运维·数据库
羔羊++7 小时前
18_实验十七_其他命令与自定义启动变量
linux
DYWorker0019 小时前
Linux驱动:RK3568 GMAC + YT8531C 千兆以太网全流程解剖
linux
lisanmengmeng10 小时前
NRPE 添加命令(一)
linux·运维·服务器
树下水月11 小时前
Typora破解
linux·服务器·前端
沫璃染墨12 小时前
《从零入门Linux系统篇(五十七):线程篇·十——生产者消费者模型进阶:从环形缓冲区到POSIX信号量》
linux·运维·服务器·开发语言·c++·系统架构·信号处理
wuminyu12 小时前
LockStack在虚拟线程Mount和Unmount拷贝过程剖析
java·linux·c语言·jvm·c++
深念Y12 小时前
rime-雾凇拼音-配置记录
linux·junit·软件·拼音·kde
殷色玫瑰13 小时前
C++ string类详解:常用接口、字符串操作与模拟实现
java·linux·c语言·开发语言·数据结构·c++
忆挽篱笙歌14 小时前
gcc,g++
linux