我需要一些帮助来编写 ansible 剧本。到目前为止我已经写了下面的内容,基本上列出了所有带有配置的文件。但我需要过滤掉基本上是 .git/config 的文件
- hosts: all
connection: local
gather_facts: no
tasks:
- name: "Serching old git URL"
become: true
become_user: root
find:
paths: builds
file_type: file
recurse: yes
patterns:
- config$
use_regex: true
contains: 'atlgit-01.us.manh.com'
register: configfiles
- debug:
msg: "{{configfiles.files | map(attribute='path')| list }}"
下面是 0 输出
"/builds/v2020/app/db-upgradesetup-to/.git/config",
"/builds/v2020/app/db-upgradesetup-to/environments/configure/configureEnv.xml",
"/builds/v2020/app/db-upgradesetup-from/.git/config",
"/builds/v2020/app/db-upgradesetup-from/environments/configure/configureEnv.xml",
"/builds/v2020/app/db-upgradesetup-from/ui/help/Content/Resources/images/config.gif",
"/builds/v2020/app/db-upgradesetup-from/ui/help/Content/Resources/images/configure_button.gif",
"/builds/v2020/CI/source/dockerqa/.git/config",
"/builds/v2020/CI/source/docker_ci/.git/config",
"/builds/v2020/escrow/.git/config"
谢谢你的帮助
答案1
find 命令有一个排除选项,我认为它可以满足您的需求。
排除:'.*./.git.config'
https://docs.ansible.com/ansible/latest/collections/ansible/builtin/find_module.html