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'] }}"
相关推荐
遇见火星3 小时前
Ubuntu Docker 容器化部署教程
linux·ubuntu·docker
ybb_ymm4 小时前
mysql8在linux下的默认规则修改
linux·运维·数据库·mysql
半梦半醒*4 小时前
zabbix安装
linux·运维·前端·网络·zabbix
武文斌777 小时前
复习总结最终版:单片机
linux·单片机·嵌入式硬件·学习
驱动探索者7 小时前
贝尔实验室发展史:20世纪科技圣殿的辉煌与沉浮
linux
何朴尧8 小时前
centos/cuos如何开启软件源
linux·运维·centos
YouEmbedded8 小时前
解码Linux文件IO之标准IO
linux·文件io·系统io
撬动未来的支点8 小时前
【Linux内核】Linux内核裁剪完全指南:从理论到实战的系统优化
linux
csdn_Hzx9 小时前
Linux添加一个系统服务
linux·运维·服务器
洛克大航海9 小时前
Ubuntu安装Hbase
大数据·linux·数据库·ubuntu·hbase