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'] }}"
相关推荐
*翊墨*42 分钟前
达梦数据库Linux安装
linux·数据库·excel
瑶总迷弟1 小时前
在centos上基于kubeadm部署单master的k8s集群
linux·kubernetes·centos
是小胡嘛1 小时前
华为云CentOS系统中运行http服务器无响应
linux·服务器·c++·http·centos·华为云
lhyzws2 小时前
CENTOS上的网络安全工具(二十九)GPU助力SPARK
linux·spark·gpu算力
学嵌入式的长路2 小时前
正点原子imx6ull移植lvgl v8.3及触摸屏调试
linux·驱动开发·lvgl·imx6ull·触摸屏
馨谙2 小时前
使用 systemd 单元管理容器环境完全指南
linux
石像鬼₧魂石2 小时前
有哪些常见的字典可以用于Hydra的密码破解?
linux·学习·ssh
RXXW_Dor2 小时前
西门子EtherNet/IP 适配器 通过 EtherNet/IP 将第三方控制系统连接到 SIMATIC S7 控制器
linux·网络·tcp/ip
Mr.H01272 小时前
(上册)TCP 服务器核心流程实操指南
linux·服务器·网络·tcp/ip
DeeplyMind3 小时前
Guest → QEMU → Virglrenderer 调用逻辑分析
linux·驱动开发·虚拟化·virtio-gpu·virglrenderer