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'] }}"
相关推荐
为思念酝酿的痛21 小时前
POSIX信号量
linux·运维·服务器·后端
人还是要有梦想的1 天前
linux下用搜狗输入法,中英文切换
linux·运维·服务器
bush41 天前
嵌入式linux学习记录二
linux·运维·学习
9分钟带帽1 天前
linux_通过NFS挂载远程服务器的硬盘
linux·服务器
运维栈记1 天前
API Error: 400 Request body format invalid
linux·ai
小白兔奶糖ovo1 天前
【Leetcode】231. 2的幂
linux·算法·leetcode
s_w.h1 天前
【 linux 】动静态库的制作
linux·运维·服务器·算法·bash
顺风尿一寸1 天前
深入Linux内核:mkdir系统调用的完整实现解析
linux
用户2367829801681 天前
Linux free 命令深度解析:从内存监控到 OOM 排查的完整指南
linux
无足鸟ICT1 天前
【RHCA+】boxes命令(艺术框)
linux