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'] }}"
相关推荐
liweiweili12625 分钟前
Linux 中替换某个目录下所有文件中的特定字符串
linux·运维·服务器
弓弧名家_玄真君1 小时前
Ubuntu 20.04.3 LTS 安装vnc (Xfce4 + Xvfb)
linux·运维·ubuntu
唐·柯里昂7982 小时前
野火鲁班猫5使用正点原子 RTL8188EUS Wifi模块驱动移植(Linux5.10 Debian系统) 解决zsh报错
linux·c语言·mcu·物联网·ubuntu·硬件工程·软件构建
源梦想2 小时前
机甲恐龙动作冒险网页小游戏Linux部署教程
linux·运维·服务器
Hoshino.412 小时前
从0开始学习Linux——第七部分:DNS(1)
linux·网络·学习
yiyeguzhou1002 小时前
论文解读:Overcoming the IOTLB wall for multi-100-Gbps Linux-based networking
linux·运维·服务器
Y淑滢潇潇2 小时前
RHCE Day 7 SHELL概述和基本功能
linux·前端·rhce
妄想出头的工业炼药师2 小时前
cuda如何安装卸载
linux·运维·服务器
柳鲲鹏3 小时前
LINUX下载编译libcamera
linux·运维·服务器
Embedded-Xin3 小时前
Linux架构优化——spdlog实现压缩及异步写日志
android·linux·服务器·c++·架构·嵌入式