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'] }}"
相关推荐
活蹦乱跳酸菜鱼13 分钟前
linux ATF BL2执行过程
linux
淡淡烟雨淡淡愁2 小时前
安装libreoffice
linux
蜀道山老天师2 小时前
云原生监控入门:监控基础概念 + SLI/SLO/SLA 详解 + Prometheus 从零安装配置
linux·运维·云原生·prometheus
AIDF20262 小时前
linux 服务器网络问题排查
linux·服务器·网络
楼兰公子2 小时前
br_opi5_plus_defconfig 附带uboot
linux·运维·服务器
mzhan0173 小时前
Linux: signal: SIGALRM; alarm: ITIMER_REAL
linux·运维·服务器
mzhan0173 小时前
Linux: compare的直观性
java·linux·服务器
原来是猿3 小时前
TCP Server 业务扩展实战:从 Echo 到远程命令执行与词典翻译
linux·运维·服务器
剑神一笑4 小时前
Linux awk 命令:文本处理的瑞士军刀
linux·运维·chrome
用户2367829801685 小时前
Linux df 命令深度解析:从磁盘空间监控到 inode 耗尽排查
linux