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'] }}"
相关推荐
Petal9909127 小时前
内核调试:Linux编译内核源码为deb并更新内核
linux·运维·服务器
用户467244544997 小时前
Linux 进程管理
linux
一个平凡而乐于分享的小比特8 小时前
Linux内核构建三剑客:Kconfig、.config与Makefile关系详解
linux·makefile·kconfig·.config
Dillon Dong8 小时前
服务器运维:Linux 磁盘查看 & 清理常用命令
linux·运维·服务器
ben9518chen8 小时前
Linux用户管理
linux·运维·服务器
用户6135411460169 小时前
xampplinux_v174beta11在 Linux 下的安装与配置步骤
linux
Byron Loong9 小时前
【系统】Mac系统和Linux 指令对比
linux·macos·策略模式
markvivv9 小时前
在 Kylin Linux Advanced Server for Kunpeng V10 上构建 VSCode 1.106
linux·vscode·kylin
看见繁华9 小时前
Linux 交叉编译实践笔记
linux·运维·笔记
tianyuanwo10 小时前
深入解析CentOS 8网络配置:NetworkManager DNS管理机制与网卡类型深度剖析
linux·网络·centos