Support configuration of multiple hosts

This commit is contained in:
Tobias Manske 2022-09-07 17:07:34 +02:00
parent b4f88686b8
commit dad7d71f09
Signed by: tobias
GPG Key ID: E83C743C1FC2F79A
3 changed files with 39 additions and 33 deletions

View File

@ -0,0 +1 @@
render_blacklist: []

View File

@ -0,0 +1,4 @@
render_blacklist:
- "03_syncthing/config/cert.pem"
- "03_syncthing/config/key.pem"
- "03_syncthing/config/config.xml"

View File

@ -1,13 +1,21 @@
--- ---
- name: Wait for hosts to be ready
hosts: all
gather_facts: false
tasks:
- name: Wait for system to become reachable
wait_for_connection:
timeout: 300
sleep: 10
- name: Render compose files - name: Render compose files
hosts: localhost hosts: all
tags: template tags: template
vars: vars:
render_path: "./render/compose" render_path: "./render/{{ inventory_hostname }}/compose"
render_blacklist:
- EMPTY
tasks: tasks:
- block:
- file: - file:
state: absent state: absent
dest: '{{ render_path }}' dest: '{{ render_path }}'
@ -26,14 +34,7 @@
changed_when: false changed_when: false
with_filetree: './compose' with_filetree: './compose'
when: item.state == 'file' and item.path not in render_blacklist when: item.state == 'file' and item.path not in render_blacklist
- name: Copy blacklisted files delegate_to: localhost
copy:
src: "{{ item.src }}"
dest: "{{ render_path }}/{{ item.path }}"
force: true
changed_when: false
with_filetree: './compose'
when: item.state == 'file' and item.path in render_blacklist
- name: Backup - name: Backup
hosts: all hosts: all
@ -111,7 +112,7 @@
- name: Gather local Config - name: Gather local Config
delegate_to: 127.0.0.1 delegate_to: 127.0.0.1
find: find:
paths: ./render/compose paths: "./render/{{ inventory_hostname }}/compose"
recurse: true recurse: true
file_type: file file_type: file
register: local_compose_files register: local_compose_files
@ -129,7 +130,7 @@
verbosity: 2 verbosity: 2
- ansible.builtin.set_fact: - ansible.builtin.set_fact:
compose_dirs_tainted: "{{ remote_compose_files.files | map(attribute='path') | difference(local_compose_files.files | map(attribute='path') | map('regex_replace', '^render/', '/home/core/')) | map('dirname') }}" compose_dirs_tainted: "{{ remote_compose_files.files | map(attribute='path') | difference(local_compose_files.files | map(attribute='path') | map('regex_replace', '^render/.*/compose', '/home/core/compose')) | map('dirname') }}"
- ansible.builtin.debug: - ansible.builtin.debug:
var: compose_dirs_tainted var: compose_dirs_tainted
verbosity: 2 verbosity: 2
@ -142,7 +143,7 @@
- name: Copy Compose files - name: Copy Compose files
ansible.posix.synchronize: ansible.posix.synchronize:
src: ./render/compose src: "./render/{{ inventory_hostname }}/compose"
dest: /home/core/ dest: /home/core/
archive: false archive: false
checksum: true checksum: true