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'] }}"
相关推荐
上海运维Q先生13 分钟前
SUSE 报错修复:unable to open display ““
linux·运维
云栖梦泽23 分钟前
Linux内核与驱动:5.并发与竞争
linux·c++
牢七26 分钟前
CVE-2022-37202 nday 研究 sql
linux·windows·microsoft
打工人1379号27 分钟前
2K3000常见问题合集
linux·运维·服务器
冰冷的希望30 分钟前
【系统】非虚拟机,物理机安装Ubuntu教程,Windows与Linux(Ubuntu)双系统共存!
linux·windows·ubuntu·系统架构·vmware·双系统·pe系统
minji...1 小时前
Linux 进程信号(四)内核态&&用户态,sigaction,可重入函数,volatile,SIGCHLD信号
linux·运维·服务器
新兴AI民工1 小时前
【Linux内核二十九】进程管理模块:CFS调度器check_preempt_wakeup
linux·linux内核·wakeup
lwx9148521 小时前
Linux-parted命令
linux·运维·服务器
xin_yao_xin1 小时前
Linux 下 Docker 安装教程(2026)
linux·运维·docker
不愿透露姓名的大鹏1 小时前
Linux环境下Node.js后台运行方式(实用版)
linux·运维·node.js