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,39 +1,40 @@
--- ---
- 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:
- file: - block:
state: absent - file:
dest: '{{ render_path }}' state: absent
changed_when: false dest: '{{ render_path }}'
- file: changed_when: false
state: directory - file:
dest: '{{ render_path }}/{{ item.path }}' state: directory
changed_when: false dest: '{{ render_path }}/{{ item.path }}'
with_filetree: './compose' changed_when: false
when: item.state == 'directory' with_filetree: './compose'
- name: Template Compose structure when: item.state == 'directory'
ansible.builtin.template: - name: Template Compose structure
src: "{{ item.src }}" ansible.builtin.template:
dest: "{{ render_path }}/{{ item.path }}" src: "{{ item.src }}"
force: true dest: "{{ render_path }}/{{ item.path }}"
changed_when: false force: true
with_filetree: './compose' changed_when: false
when: item.state == 'file' and item.path not in render_blacklist with_filetree: './compose'
- name: Copy blacklisted files when: item.state == 'file' and item.path not in render_blacklist
copy: delegate_to: localhost
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