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'] }}"
相关推荐
脏脏a33 分钟前
【Linux】冯诺依曼体系结构与操作系统概述
linux·服务器
adnyting1 小时前
【Linux日新月异(三)】CentOS 7软件管理深度指南:从YUM到源码编译
linux·运维·centos
知识分享小能手1 小时前
openEuler入门学习教程,从入门到精通,云计算与 Linux 操作系统概述(1)
linux·云计算·openeuler
励志成为编程高手2 小时前
在ubuntu中创建根文件系统
linux·ubuntu·rootfs
HIT_Weston2 小时前
31、【Ubuntu】【远程开发】内网穿透:反向隧道建立(三)
linux·运维·ubuntu
skywalk81633 小时前
在FreeBSD 14.3上部署轻量级Linux jail环境 仅仅占用10M内存
linux·运维·服务器·虚拟机·轻量化·freebsd·jail
知南x3 小时前
【STM32MP157 异核通信框架学习篇】(10)Linux下Remoteproc相关API (下)
linux·stm32·学习
Tipriest_3 小时前
Linux 环境变量的添加与查看详解
linux·环境变量
牢七4 小时前
新linux
linux
HIT_Weston7 小时前
27、【Ubuntu】【远程开发】内网穿透:CA 签名
linux·运维·ubuntu