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'] }}"
相关推荐
xqhoj3 分钟前
Linux——make、makefile
linux·运维·服务器
张童瑶20 分钟前
Linux 在线安装编译Python3.11
linux·运维·python3.11
Shi_haoliu30 分钟前
SolidTime 在 Rocky Linux 9.5 上的完整部署流程
linux·运维·nginx·postgresql·vue·php·laravel
Lkygo1 小时前
LlamaIndex使用指南
linux·开发语言·python·llama
qq_254617771 小时前
nslookup 这个命令解析dns,和系统接口gethostbyname解析区别在哪?
linux·网络
HIT_Weston2 小时前
100、【Ubuntu】【Hugo】搭建私人博客:元信息&翻译(一)
linux·运维·ubuntu
自由的好好干活2 小时前
UBI镜像文件打包与编辑
linux·嵌入式硬件
shawnyz3 小时前
RHCSE--ansible1-入门和模块
linux·运维·ansible
奔跑的花短裤4 小时前
ubuntu安装Isaac sim4.5与强化学习使用
linux·ubuntu·机器人·强化学习·isaac sim·isaac lab
陕西小伙伴网络科技有限公司4 小时前
CentOS-7 编译glibc-2.29
linux·运维·centos