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'] }}"
相关推荐
q***47181 小时前
使用Canal将MySQL数据同步到ES(Linux)
linux·mysql·elasticsearch
Y淑滢潇潇2 小时前
RHCE 防火墙实验
linux·运维·rhce
wadesir2 小时前
当前位置:首页 > 服务器技术 > 正文Linux网络HSRP协议(实现路由器热备份与高可用性的实用指南)
linux·服务器·网络
稻谷君W2 小时前
Ubuntu 远程访问 Win11 WSL2 并固定访问教程
linux·运维·ubuntu
wdfk_prog3 小时前
[Linux]学习笔记系列 -- [kernel]workqueue
linux·笔记·学习
wdfk_prog3 小时前
[Linux]学习笔记系列 -- [kernel]usermode_helper
linux·笔记·学习
weixin_436525073 小时前
使用 idea 命令行构建 Docker 镜像并部署到云服务器
linux·docker·github
z***94845 小时前
Linux下安装Nginx服务及systemctl方式管理nginx详情
linux·运维·nginx
凉晓风5 小时前
Linux上TCP通信异常排查工具命令
linux·运维·tcp/ip
Xの哲學5 小时前
Linux 分区表深度技术剖析
linux·网络·算法·架构·边缘计算