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'] }}"
相关推荐
色空大师25 分钟前
【网站开发-java】
java·linux·服务器·开发语言·网站·搭建网站
释怀不想释怀34 分钟前
硬盘基础了解知识
linux·运维·服务器
福楠38 分钟前
现代C++ | 右值引用 + std::move + noexcept
linux·c语言·开发语言·c++
逆向编程41 分钟前
Ubuntu 入门教程,日常常用命令
linux·运维·ubuntu
逆向编程1 小时前
Ubuntu 入门教程:从安装到日常使用,新手一步到位
linux·运维·ubuntu
叠叠乐1 小时前
ubuntu linux DNS 系统流程逻辑
linux·运维·ubuntu
西西弗Sisyphus1 小时前
Linux Shell 脚本中的 Shebang(#! /bin/bash)是什么
linux·bash·shebang
qzhqbb1 小时前
Linux 防火墙(iptable、nftables、ufw)
linux·运维·服务器
Mapleay1 小时前
alsa-lib 的插件
linux
枫桥骤雨1 小时前
Ubuntu NVM部署Node.js教程
linux·ubuntu·node.js·nvm