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'] }}"
相关推荐
i建模1 分钟前
Ubuntu 中使用 LVM(逻辑卷管理)挂载磁盘
linux·运维·ubuntu
cyber_两只龙宝11 分钟前
【Docker】Dockerfile构建镜像实验全流程详解
linux·运维·docker·云原生
de_wizard15 分钟前
Linux 下安装 Golang环境
linux·运维·golang
相醉为友17 分钟前
001 Linux个性操作记录——交叉编译工具链高兼容性调用函数备用
linux·运维·服务器
夹芯饼干25 分钟前
Linux命令(第三节课)
linux·运维·服务器
oushaojun239 分钟前
现代linux gpio编程接口(by deepseek)
linux·libgpiod
皓木.1 小时前
软件测试Linux
linux·运维·服务器
Deitymoon1 小时前
linux——进程间的通信
linux
最好有梦想~1 小时前
嵌入式Linux Lua使用ZeroBrane远程调试
linux·嵌入式硬件·lua
我爱学习好爱好爱1 小时前
Ansible 详解:group模块、vars_files变量、user模块实战
linux·运维·ansible