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'] }}"
相关推荐
好好学习啊天天向上1 天前
C盘容量不够,python , pip,安装包的位置
linux·python·pip
li_wen011 天前
文件系统(八):Linux JFFS2文件系统工作原理、优势与局限
大数据·linux·数据库·文件系统·jffs2
wypywyp1 天前
2.虚拟机一直显示黑屏,无法打开,可能是分配的硬盘空间不够
linux·运维·服务器
SongYuLong的博客1 天前
TL-WR710N-V2.1 硬改刷机OpenWRT源码编译固件
linux·物联网·网络协议
AlfredZhao1 天前
Docker 快速入门:手把手教你打包 Python 应用
linux·docker·podman
HIT_Weston1 天前
107、【Ubuntu】【Hugo】搭建私人博客:模糊搜索 Fuse.js(三)
linux·javascript·ubuntu
艾莉丝努力练剑1 天前
【优选算法必刷100题】第007~008题(双指针算法):三数之和、四数之和问题求解
linux·算法·双指针·优选算法
chinesegf1 天前
Ubuntu 安装 Python 虚拟环境:常见问题与解决指南
linux·python·ubuntu
crownyouyou1 天前
Ubuntu输入法使用回车键后字符间距异常的问题
linux·运维·ubuntu
济6171 天前
linux 系统移植(第十七期)---Linux 内核移植(5)-- 修改网络驱动(2)--- Ubuntu20.04
linux·运维·网络