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'] }}"
相关推荐
CS_浮鱼10 分钟前
【Linux】进程间通信
linux·运维·数据库
Altair123110 分钟前
实验6 基于端口和域名的虚拟主机
linux·运维·服务器·云计算
爱和冰阔落14 分钟前
【Linux工具链】编译效率革命:条件编译优化+动静态库管理+Makefile自动化,解决多场景开发痛点
linux·运维·自动化
wa的一声哭了20 分钟前
WeBASE管理平台部署-WeBASE-Web
linux·前端·网络·arm开发·spring boot·架构·区块链
Shylock_Mister39 分钟前
ARM与x86交叉编译实战排错指南
linux·c语言·arm开发
敲上瘾39 分钟前
MySQL事务全攻略:ACID特性、隔离级别与并发控制
linux·数据库·mysql·安全
b***9101 小时前
在linux(Centos)中Mysql的端口修改保姆级教程
linux·mysql·centos
shizhan_cloud1 小时前
Linux 交换空间管理
linux·运维
YouEmbedded1 小时前
解码死锁的产生与解决
linux·避免死锁·死锁产生·预防死锁·处理死锁
果子没有六分钟2 小时前
【Linux】进程调度器
linux·运维·服务器