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'] }}"
相关推荐
Huangjin007_19 小时前
【Linux 系统篇(十五)】进程 (三) :进程状态深度详解
linux·运维
RisunJan19 小时前
Linux命令-talk(终端实时对话)
linux·运维·服务器
NeilYuen20 小时前
【vemory】高性能KV存储AOF方案设计
linux·c++·redis·缓存
三言老师21 小时前
Rocky Linux 8.6 整机系统备份与迁移方案文档文档用途
linux·运维·服务器·网络
雾时之林21 小时前
Linux----防火墙
linux·运维·网络
消失的旧时光-19431 天前
7-fix补充篇:机器人为什么需要多级控制仲裁?Cloud、Linux 与 MCU 分别管什么
linux·单片机·机器人·仲裁机制·安全保护机制
睡一觉就好了。1 天前
线程的理解
linux
我星期八休息1 天前
网络编程—NAT、代理服务与内网穿透
linux·服务器·网络·网络协议
RisunJan1 天前
Linux命令-sysctl(运行时修改内核参数)
linux·网络·智能路由器
yunwei371 天前
eBPF 教程:使用 fsession 追踪慢速 vfs_read 调用
linux·云原生