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'] }}"
相关推荐
Aspiresky3 分钟前
浅析Linux进程信号处理机制:基本原理及应用
linux·运维·信号处理
ajassi20001 小时前
linux C 语言开发 (八) 进程基础
linux·运维·服务器
..过云雨1 小时前
05.【Linux系统编程】进程(冯诺依曼体系结构、进程概念、进程状态(注意僵尸和孤儿)、进程优先级、进程切换和调度)
linux·笔记·学习
matlab的学徒2 小时前
Web与Nginx网站服务(改)
linux·运维·前端·nginx·tomcat
Insist7532 小时前
prometheus安装部署与alertmanager邮箱告警
linux·运维·grafana·prometheus
BAGAE2 小时前
MODBUS 通信协议详细介绍
linux·嵌入式硬件·物联网·硬件架构·iot·嵌入式实时数据库·rtdbs
灿烂阳光g2 小时前
SELinux 策略文件编写
android·linux
xqlily2 小时前
Linux操作系统之Ubuntu
linux·运维·ubuntu
阿部多瑞 ABU3 小时前
《基于国产Linux的机房终端安全重构方案》
linux·安全
倔强的石头1063 小时前
【Linux指南】Makefile入门:从概念到基础语法
linux·运维·服务器