Skip to content

Instantly share code, notes, and snippets.

@heiwa4126
Created March 8, 2021 07:28
Show Gist options
  • Select an option

  • Save heiwa4126/d6cb9576cff8e0426702d15d20c2163c to your computer and use it in GitHub Desktop.

Select an option

Save heiwa4126/d6cb9576cff8e0426702d15d20c2163c to your computer and use it in GitHub Desktop.
Ansibleのfindモジュールの例。/etc/*.confをコントロールマシンにコピーする。Jinja2のフィルタがめんどくさいがshell:つかうよりはいいんじゃないかと。
---
- name: fetch /etc/*.conf
hosts: linux
become: false
gather_facts: false
vars:
outpath: "{{ playbook_dir }}/var/etc_conf/{{ inventory_hostname }}"
tasks:
- name: get list
find:
path: /etc
pattern: "*.conf"
register: rc
# - debug: var=rc
# - debug: msg="{{ rc.files|map(attribute='path') }}"
- name: fetch /etc/*.conf files
fetch:
src: "{{ item }}"
dest: "{{ outpath }}/"
flat: true
with_items: "{{ rc.files|map(attribute='path') }}"
become: true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment