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'] }}"
相关推荐
NO.102410 分钟前
11.4八股
java·linux·数据库
我想吃余16 分钟前
Linux信号(下):信号保存和信号处理
linux·运维·信号处理
七夜zippoe24 分钟前
高性能网络编程实战:用Tokio构建自定义协议服务器
linux·服务器·网络·rust·tokio
owCode26 分钟前
Linux中的管道
linux·运维·服务器
jiedaodezhuti29 分钟前
服务器负载过高的多维度诊断与性能瓶颈定位指南
linux
neo_will_mvp32 分钟前
服务器bmc功能
linux·运维·服务器
敲上瘾39 分钟前
Elasticsearch从入门到实践:核心概念到Kibana测试与C++客户端封装
大数据·linux·c++·elasticsearch·搜索引擎·全文检索
慕慕涵雪月光白1 小时前
在Ubuntu系统上安装英伟达(NVIDIA)RTX 3070 Ti的驱动程序
linux·运维·人工智能·ubuntu
做运维的阿瑞2 小时前
CentOS 7 停止维护后 YUM 源配置速查手册
linux·运维·centos
mc23562 小时前
Linux 基本命令
linux