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'] }}"
相关推荐
崔小汤呀18 小时前
最全的docker安装笔记,包含CentOS和Ubuntu
linux·后端
何中应18 小时前
vi编辑器使用
linux·后端·操作系统
何中应18 小时前
Linux进程无法被kill
linux·后端·操作系统
何中应18 小时前
rm-rf /命令操作介绍
linux·后端·操作系统
何中应18 小时前
Linux常用命令
linux·操作系统
葛立国18 小时前
从 / 和 /dev 说起:Linux 文件系统与挂载点一文理清
linux
哇哈哈20211 天前
信号量和信号
linux·c++
不是二师兄的八戒1 天前
Linux服务器挂载OSS存储的完整实践指南
linux·运维·服务器
一个人旅程~1 天前
如何用命令行把win10/win11设置为长期暂停更新?
linux·windows·经验分享·电脑
2302_799525741 天前
PCI、PCIe 和 NVLink
linux