From 80e57417f497c3c37d53daa04f8ef6b010b96e19 Mon Sep 17 00:00:00 2001 From: ikkemaniac Date: Sun, 19 Jun 2022 11:30:28 +0200 Subject: [PATCH 01/13] To recover from a failure or allow to quickly reset to known state we need to know with what playbook-commit the sever is installed. This commit saves the GIT hash/status when we run the playbook in a file called git_hash.yml. It also backs up that file by copying it to the target machine. --- roles/matrix-base/defaults/main.yml | 4 ++ roles/matrix-base/tasks/setup_matrix_base.yml | 53 +++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/roles/matrix-base/defaults/main.yml b/roles/matrix-base/defaults/main.yml index eccda626..9213c661 100644 --- a/roles/matrix-base/defaults/main.yml +++ b/roles/matrix-base/defaults/main.yml @@ -298,3 +298,7 @@ run_setup: true run_self_check: true run_start: true run_stop: true + +# Saves the git hash in a file called git_hash.yml +# Set this to false if GIT is not installed on the local system (the system where the ansible command is run on) +git_save_hash: true \ No newline at end of file diff --git a/roles/matrix-base/tasks/setup_matrix_base.yml b/roles/matrix-base/tasks/setup_matrix_base.yml index 6eebe3c0..5d3c5820 100644 --- a/roles/matrix-base/tasks/setup_matrix_base.yml +++ b/roles/matrix-base/tasks/setup_matrix_base.yml @@ -19,6 +19,59 @@ mode: '0660' when: "matrix_vars_yml_snapshotting_enabled | bool" +- name: Save current git-repo status on the target to aid with restoring in case of problems + block: + - name: Get local git hash + delegate_to: 127.0.0.1 + become: false + register: git_describe + shell: + git describe + --always + --tags + --dirty + --long + --all + + - set_fact: + git_hash: "{{ git_describe.stdout }}" + + - name: Git hash + debug: + msg: "Git hash: {{ git_hash }}" + + - name: Save git hash in git_hash.yml + become: false + local_action: + copy + content="git_hash_last_run{{ ":" }} {{ git_hash }}\n" + dest="{{ matrix_vars_yml_snapshotting_src }}/git_hash.yml" + + - name: Copy git_hash.yml file to target + copy: + src: "{{ matrix_vars_yml_snapshotting_src }}/git_hash.yml" + dest: "{{ matrix_base_data_path }}/git_hash.yml" + owner: "{{ matrix_user_username }}" + group: "{{ matrix_user_groupname }}" + mode: '0660' + + rescue: + - name: GIT not found error + ansible.builtin.debug: + msg: >- + Couldn't find GIT on the local machine. Continuing without saving the GIT hash. + You can disable saving the GIT hash by setting 'git_save_hash: false' in vars.yml + when: "git_describe.stderr.find('not found') != -1" + + - name: GIT hash error + ansible.builtin.fail: + msg: >- + Error when trying to get the GIT hash. + You can disable saving the GIT hash by setting 'git_save_hash: false' in vars.yml + when: "git_describe.stderr.find('not found') == -1" + + when: "matrix_vars_yml_snapshotting_enabled|bool and git_save_hash|bool" + - name: Ensure Matrix network is created in Docker community.docker.docker_network: name: "{{ matrix_docker_network }}" From 678dfc6dc3afe990fc71decf65260115458371bc Mon Sep 17 00:00:00 2001 From: ikkemaniac Date: Sun, 30 Oct 2022 14:00:04 +0100 Subject: [PATCH 02/13] Rename var --- roles/matrix-base/defaults/main.yml | 2 +- roles/matrix-base/tasks/setup_matrix_base.yml | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/roles/matrix-base/defaults/main.yml b/roles/matrix-base/defaults/main.yml index 9213c661..22d89c23 100644 --- a/roles/matrix-base/defaults/main.yml +++ b/roles/matrix-base/defaults/main.yml @@ -301,4 +301,4 @@ run_stop: true # Saves the git hash in a file called git_hash.yml # Set this to false if GIT is not installed on the local system (the system where the ansible command is run on) -git_save_hash: true \ No newline at end of file +matrix_playbook_commit_hash_preservation_enabled: true \ No newline at end of file diff --git a/roles/matrix-base/tasks/setup_matrix_base.yml b/roles/matrix-base/tasks/setup_matrix_base.yml index 5d3c5820..d443fee8 100644 --- a/roles/matrix-base/tasks/setup_matrix_base.yml +++ b/roles/matrix-base/tasks/setup_matrix_base.yml @@ -60,17 +60,17 @@ ansible.builtin.debug: msg: >- Couldn't find GIT on the local machine. Continuing without saving the GIT hash. - You can disable saving the GIT hash by setting 'git_save_hash: false' in vars.yml + You can disable saving the GIT hash by setting 'matrix_playbook_commit_hash_preservation_enabled: false' in vars.yml when: "git_describe.stderr.find('not found') != -1" - name: GIT hash error ansible.builtin.fail: msg: >- Error when trying to get the GIT hash. - You can disable saving the GIT hash by setting 'git_save_hash: false' in vars.yml + You can disable saving the GIT hash by setting 'matrix_playbook_commit_hash_preservation_enabled: false' in vars.yml when: "git_describe.stderr.find('not found') == -1" - when: "matrix_vars_yml_snapshotting_enabled|bool and git_save_hash|bool" + when: "matrix_vars_yml_snapshotting_enabled|bool and matrix_playbook_commit_hash_preservation_enabled|bool" - name: Ensure Matrix network is created in Docker community.docker.docker_network: From 230eea678471e9b46b3a9069d5505c4499dc6f63 Mon Sep 17 00:00:00 2001 From: ikkemaniac Date: Sun, 30 Oct 2022 14:04:33 +0100 Subject: [PATCH 03/13] Save git_hash.yml only on the target --- roles/matrix-base/tasks/setup_matrix_base.yml | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/roles/matrix-base/tasks/setup_matrix_base.yml b/roles/matrix-base/tasks/setup_matrix_base.yml index d443fee8..a9773855 100644 --- a/roles/matrix-base/tasks/setup_matrix_base.yml +++ b/roles/matrix-base/tasks/setup_matrix_base.yml @@ -40,16 +40,9 @@ debug: msg: "Git hash: {{ git_hash }}" - - name: Save git hash in git_hash.yml - become: false - local_action: - copy - content="git_hash_last_run{{ ":" }} {{ git_hash }}\n" - dest="{{ matrix_vars_yml_snapshotting_src }}/git_hash.yml" - - - name: Copy git_hash.yml file to target + - name: Save git_hash.yml on target copy: - src: "{{ matrix_vars_yml_snapshotting_src }}/git_hash.yml" + content: "{{ git_hash }}" dest: "{{ matrix_base_data_path }}/git_hash.yml" owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" From 930867d50d7bf399c843c13211ed78473a430943 Mon Sep 17 00:00:00 2001 From: ikkemaniac Date: Sun, 30 Oct 2022 14:07:39 +0100 Subject: [PATCH 04/13] Remove matrix_vars_yml_snapshotting_enabled condition --- roles/matrix-base/tasks/setup_matrix_base.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/matrix-base/tasks/setup_matrix_base.yml b/roles/matrix-base/tasks/setup_matrix_base.yml index a9773855..6fe7e47d 100644 --- a/roles/matrix-base/tasks/setup_matrix_base.yml +++ b/roles/matrix-base/tasks/setup_matrix_base.yml @@ -63,7 +63,7 @@ You can disable saving the GIT hash by setting 'matrix_playbook_commit_hash_preservation_enabled: false' in vars.yml when: "git_describe.stderr.find('not found') == -1" - when: "matrix_vars_yml_snapshotting_enabled|bool and matrix_playbook_commit_hash_preservation_enabled|bool" + when: "matrix_playbook_commit_hash_preservation_enabled|bool" - name: Ensure Matrix network is created in Docker community.docker.docker_network: From 3d902b7fe733957e966593775979ec22e349899e Mon Sep 17 00:00:00 2001 From: ikkemaniac Date: Sun, 30 Oct 2022 14:33:09 +0100 Subject: [PATCH 05/13] be more specific on GIT not found error --- roles/matrix-base/tasks/setup_matrix_base.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/roles/matrix-base/tasks/setup_matrix_base.yml b/roles/matrix-base/tasks/setup_matrix_base.yml index 6fe7e47d..59dbe087 100644 --- a/roles/matrix-base/tasks/setup_matrix_base.yml +++ b/roles/matrix-base/tasks/setup_matrix_base.yml @@ -54,14 +54,14 @@ msg: >- Couldn't find GIT on the local machine. Continuing without saving the GIT hash. You can disable saving the GIT hash by setting 'matrix_playbook_commit_hash_preservation_enabled: false' in vars.yml - when: "git_describe.stderr.find('not found') != -1" + when: "git_describe.stderr.find('git: not found') != -1" - - name: GIT hash error + - name: Get GIT hash error ansible.builtin.fail: msg: >- Error when trying to get the GIT hash. You can disable saving the GIT hash by setting 'matrix_playbook_commit_hash_preservation_enabled: false' in vars.yml - when: "git_describe.stderr.find('not found') == -1" + when: "git_describe.stderr.find('git: not found') == -1" when: "matrix_playbook_commit_hash_preservation_enabled|bool" From fd25cf8f54e9341b005004f1dd991b9458c0be2e Mon Sep 17 00:00:00 2001 From: ikkemaniac Date: Sun, 30 Oct 2022 14:37:45 +0100 Subject: [PATCH 06/13] Update wording --- roles/matrix-base/defaults/main.yml | 11 ++++++----- roles/matrix-base/tasks/setup_matrix_base.yml | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/roles/matrix-base/defaults/main.yml b/roles/matrix-base/defaults/main.yml index 22d89c23..4ad5fe55 100644 --- a/roles/matrix-base/defaults/main.yml +++ b/roles/matrix-base/defaults/main.yml @@ -284,6 +284,11 @@ matrix_docker_installation_enabled: true # Possible values are "docker-ce" (default) and "docker.io" (Debian). matrix_docker_package_name: docker-ce +# Controls whether the current playbook's commit hash is saved in `git_hash.yml` on the target +# Set this to false if GIT is not installed on the local system (the system where the ansible command is run on) +# to suppres the warning message. +matrix_playbook_commit_hash_preservation_enabled: true + # Variables to Control which parts of our roles run. run_postgres_import: true run_postgres_upgrade: true @@ -297,8 +302,4 @@ run_dendrite_register_user: true run_setup: true run_self_check: true run_start: true -run_stop: true - -# Saves the git hash in a file called git_hash.yml -# Set this to false if GIT is not installed on the local system (the system where the ansible command is run on) -matrix_playbook_commit_hash_preservation_enabled: true \ No newline at end of file +run_stop: true \ No newline at end of file diff --git a/roles/matrix-base/tasks/setup_matrix_base.yml b/roles/matrix-base/tasks/setup_matrix_base.yml index 59dbe087..44e4137c 100644 --- a/roles/matrix-base/tasks/setup_matrix_base.yml +++ b/roles/matrix-base/tasks/setup_matrix_base.yml @@ -59,7 +59,7 @@ - name: Get GIT hash error ansible.builtin.fail: msg: >- - Error when trying to get the GIT hash. + Error when trying to get the GIT hash. Please consult the error message above. You can disable saving the GIT hash by setting 'matrix_playbook_commit_hash_preservation_enabled: false' in vars.yml when: "git_describe.stderr.find('git: not found') == -1" From 15fbc525cf4f70e8e1f9a0814e4b9fb671d18dd3 Mon Sep 17 00:00:00 2001 From: ikkemaniac Date: Sun, 30 Oct 2022 14:53:27 +0100 Subject: [PATCH 07/13] Typo --- roles/matrix-base/defaults/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/matrix-base/defaults/main.yml b/roles/matrix-base/defaults/main.yml index 4ad5fe55..bcc821a4 100644 --- a/roles/matrix-base/defaults/main.yml +++ b/roles/matrix-base/defaults/main.yml @@ -286,7 +286,7 @@ matrix_docker_package_name: docker-ce # Controls whether the current playbook's commit hash is saved in `git_hash.yml` on the target # Set this to false if GIT is not installed on the local system (the system where the ansible command is run on) -# to suppres the warning message. +# to suppress the warning message. matrix_playbook_commit_hash_preservation_enabled: true # Variables to Control which parts of our roles run. From 39e6484956671080c1d7e2fbd94c6d7427669b66 Mon Sep 17 00:00:00 2001 From: ikkemaniac Date: Mon, 31 Oct 2022 22:57:16 +0100 Subject: [PATCH 08/13] fix lints --- roles/matrix-base/tasks/setup_matrix_base.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/roles/matrix-base/tasks/setup_matrix_base.yml b/roles/matrix-base/tasks/setup_matrix_base.yml index 44e4137c..5c45323e 100644 --- a/roles/matrix-base/tasks/setup_matrix_base.yml +++ b/roles/matrix-base/tasks/setup_matrix_base.yml @@ -21,11 +21,11 @@ - name: Save current git-repo status on the target to aid with restoring in case of problems block: - - name: Get local git hash + - name: Get local git hash delegate_to: 127.0.0.1 become: false register: git_describe - shell: + ansible.builtin.shell: git describe --always --tags @@ -33,15 +33,15 @@ --long --all - - set_fact: + - ansible.builtin.set_fact: git_hash: "{{ git_describe.stdout }}" - name: Git hash - debug: + ansible.builtin.debug: msg: "Git hash: {{ git_hash }}" - + - name: Save git_hash.yml on target - copy: + ansible.builtin.copy: content: "{{ git_hash }}" dest: "{{ matrix_base_data_path }}/git_hash.yml" owner: "{{ matrix_user_username }}" From 2b049da963ddab978e6be9fdc014d23f819ed272 Mon Sep 17 00:00:00 2001 From: ikkemaniac Date: Mon, 31 Oct 2022 23:00:04 +0100 Subject: [PATCH 09/13] move when clause per linting suggestion --- roles/matrix-base/tasks/setup_matrix_base.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/roles/matrix-base/tasks/setup_matrix_base.yml b/roles/matrix-base/tasks/setup_matrix_base.yml index 5c45323e..cdde09d2 100644 --- a/roles/matrix-base/tasks/setup_matrix_base.yml +++ b/roles/matrix-base/tasks/setup_matrix_base.yml @@ -20,6 +20,7 @@ when: "matrix_vars_yml_snapshotting_enabled | bool" - name: Save current git-repo status on the target to aid with restoring in case of problems + when: "matrix_playbook_commit_hash_preservation_enabled|bool" block: - name: Get local git hash delegate_to: 127.0.0.1 @@ -63,8 +64,6 @@ You can disable saving the GIT hash by setting 'matrix_playbook_commit_hash_preservation_enabled: false' in vars.yml when: "git_describe.stderr.find('git: not found') == -1" - when: "matrix_playbook_commit_hash_preservation_enabled|bool" - - name: Ensure Matrix network is created in Docker community.docker.docker_network: name: "{{ matrix_docker_network }}" From 45c9c2b17a6e60f828b0d4a1723c4eb8a5aae1cb Mon Sep 17 00:00:00 2001 From: ikkemaniac Date: Mon, 31 Oct 2022 23:08:45 +0100 Subject: [PATCH 10/13] convert shell to command usage --- roles/matrix-base/tasks/setup_matrix_base.yml | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/roles/matrix-base/tasks/setup_matrix_base.yml b/roles/matrix-base/tasks/setup_matrix_base.yml index cdde09d2..0aafe183 100644 --- a/roles/matrix-base/tasks/setup_matrix_base.yml +++ b/roles/matrix-base/tasks/setup_matrix_base.yml @@ -26,13 +26,14 @@ delegate_to: 127.0.0.1 become: false register: git_describe - ansible.builtin.shell: - git describe - --always - --tags - --dirty - --long - --all + ansible.builtin.command: + cmd: >- + git describe + --always + --tags + --dirty + --long + --all - ansible.builtin.set_fact: git_hash: "{{ git_describe.stdout }}" From 93615b6ad988edb4a7972e32f0595d70fb2fd1e0 Mon Sep 17 00:00:00 2001 From: ikkemaniac Date: Mon, 31 Oct 2022 23:20:56 +0100 Subject: [PATCH 11/13] Revert "convert shell to command usage" to allow for a catching the specific "git: not found" error. This reverts commit 45c9c2b17a6e60f828b0d4a1723c4eb8a5aae1cb. --- roles/matrix-base/tasks/setup_matrix_base.yml | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/roles/matrix-base/tasks/setup_matrix_base.yml b/roles/matrix-base/tasks/setup_matrix_base.yml index 0aafe183..cdde09d2 100644 --- a/roles/matrix-base/tasks/setup_matrix_base.yml +++ b/roles/matrix-base/tasks/setup_matrix_base.yml @@ -26,14 +26,13 @@ delegate_to: 127.0.0.1 become: false register: git_describe - ansible.builtin.command: - cmd: >- - git describe - --always - --tags - --dirty - --long - --all + ansible.builtin.shell: + git describe + --always + --tags + --dirty + --long + --all - ansible.builtin.set_fact: git_hash: "{{ git_describe.stdout }}" From 8b425b995ec446109b6b13f711c85d11b57e8136 Mon Sep 17 00:00:00 2001 From: ikkemaniac Date: Mon, 31 Oct 2022 23:44:47 +0100 Subject: [PATCH 12/13] add newline char --- roles/matrix-base/defaults/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/matrix-base/defaults/main.yml b/roles/matrix-base/defaults/main.yml index bcc821a4..52049ed5 100644 --- a/roles/matrix-base/defaults/main.yml +++ b/roles/matrix-base/defaults/main.yml @@ -302,4 +302,4 @@ run_dendrite_register_user: true run_setup: true run_self_check: true run_start: true -run_stop: true \ No newline at end of file +run_stop: true From 3a49b0077c8b8704c6f7b1cf00b8c19d2e24270b Mon Sep 17 00:00:00 2001 From: ikkemaniac Date: Tue, 1 Nov 2022 09:23:55 +0100 Subject: [PATCH 13/13] fix ansible-lint errors --- roles/matrix-base/tasks/setup_matrix_base.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/roles/matrix-base/tasks/setup_matrix_base.yml b/roles/matrix-base/tasks/setup_matrix_base.yml index cdde09d2..0bf197b6 100644 --- a/roles/matrix-base/tasks/setup_matrix_base.yml +++ b/roles/matrix-base/tasks/setup_matrix_base.yml @@ -22,10 +22,11 @@ - name: Save current git-repo status on the target to aid with restoring in case of problems when: "matrix_playbook_commit_hash_preservation_enabled|bool" block: - - name: Get local git hash + - name: Get local git hash # noqa command-instead-of-module delegate_to: 127.0.0.1 become: false register: git_describe + changed_when: false ansible.builtin.shell: git describe --always