From e63644da9c280793c4eecb55973b67f688e8124a Mon Sep 17 00:00:00 2001 From: N07070 Date: Tue, 21 Jun 2022 12:11:12 +0200 Subject: [PATCH 1/4] Add check to run task in check mod & a error message. --- tasks/set_version.yml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tasks/set_version.yml b/tasks/set_version.yml index 469b344..293db37 100644 --- a/tasks/set_version.yml +++ b/tasks/set_version.yml @@ -14,15 +14,23 @@ url: https://api.github.com/repos/go-gitea/gitea/releases/latest return_content: true register: gitea_remote_metadata + when: not ansible_check_mode + + - name: "Fail if running in check mode without versions set." + fail: + msg: "You are running this playbook in check mode : please set the gitea version with {{ gitea_version }}, the URI module cannot load the latest version while in this mode." + when: ansible_check_mode and ( gitea_version not defined ) - name: "Set fact latest gitea release" ansible.builtin.set_fact: gitea_remote_version: "{{ gitea_remote_metadata.json.tag_name[1:] }}" + when: not ansible_check_mode - name: "Set gitea version target (latest)" ansible.builtin.set_fact: gitea_version_target: "{{ gitea_remote_version }}" - when: gitea_version == "latest" + when: not ansible_check_mode + when: gitea_version == "latest" - name: "Set gitea version target ({{ gitea_version }})" ansible.builtin.set_fact: From 520dbaa3c2d612f4048aadd38affd31709f6938b Mon Sep 17 00:00:00 2001 From: N07070 Date: Tue, 21 Jun 2022 12:11:12 +0200 Subject: [PATCH 2/4] Add check to run task in check mod & a error message. --- tasks/set_version.yml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tasks/set_version.yml b/tasks/set_version.yml index 469b344..427ed53 100644 --- a/tasks/set_version.yml +++ b/tasks/set_version.yml @@ -14,15 +14,23 @@ url: https://api.github.com/repos/go-gitea/gitea/releases/latest return_content: true register: gitea_remote_metadata + when: not ansible_check_mode + + - name: "Fail if running in check mode without versions set." + fail: + msg: "You are running this playbook in check mode : please set the gitea version with gitea_version, the URI module cannot load the latest version while in this mode." + when: ansible_check_mode and ( gitea_version not defined ) - name: "Set fact latest gitea release" ansible.builtin.set_fact: gitea_remote_version: "{{ gitea_remote_metadata.json.tag_name[1:] }}" + when: not ansible_check_mode - name: "Set gitea version target (latest)" ansible.builtin.set_fact: gitea_version_target: "{{ gitea_remote_version }}" - when: gitea_version == "latest" + when: not ansible_check_mode + when: gitea_version == "latest" - name: "Set gitea version target ({{ gitea_version }})" ansible.builtin.set_fact: From db0da06c082198296cec60ffe3c450b5dba5f10b Mon Sep 17 00:00:00 2001 From: L3D Date: Tue, 21 Jun 2022 17:22:57 +0200 Subject: [PATCH 3/4] Fixing linting errors and increment version Linting errors: - Use FQCN for builtin actions. (fail -> ansible.builtin.fail) - line too long (175 > 170 characters) - trailing spaces increment version for simple version check --- tasks/set_version.yml | 10 ++++++---- vars/main.yml | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/tasks/set_version.yml b/tasks/set_version.yml index 427ed53..3129dbd 100644 --- a/tasks/set_version.yml +++ b/tasks/set_version.yml @@ -17,8 +17,10 @@ when: not ansible_check_mode - name: "Fail if running in check mode without versions set." - fail: - msg: "You are running this playbook in check mode : please set the gitea version with gitea_version, the URI module cannot load the latest version while in this mode." + ansible.builtin.fail: + msg: | + "You are running this playbook in check mode: + Please set the Gitea version with the variable 'gitea_version', because the URI module cannot detect the latest version in this mode." when: ansible_check_mode and ( gitea_version not defined ) - name: "Set fact latest gitea release" @@ -29,8 +31,8 @@ - name: "Set gitea version target (latest)" ansible.builtin.set_fact: gitea_version_target: "{{ gitea_remote_version }}" - when: not ansible_check_mode - when: gitea_version == "latest" + when: not ansible_check_mode + when: gitea_version == "latest" - name: "Set gitea version target ({{ gitea_version }})" ansible.builtin.set_fact: diff --git a/vars/main.yml b/vars/main.yml index 33efc57..eb96c97 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -56,5 +56,5 @@ transfer_custom_footer: - 'files/gitea_footer/extra_links_footer.tmpl' - 'files/extra_links_footer.tmpl' -playbook_version_number: 37 # should be int +playbook_version_number: 38 # should be int playbook_version_path: 'do1jlr.gitea.version' From 7603c93fb586292ae6917cd224be388578c5db2e Mon Sep 17 00:00:00 2001 From: L3D Date: Tue, 21 Jun 2022 17:36:40 +0200 Subject: [PATCH 4/4] gitea_version variable is already defined the gitea_version variable is always defined. But it can have values like 'latest' --- tasks/set_version.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasks/set_version.yml b/tasks/set_version.yml index 3129dbd..20810cb 100644 --- a/tasks/set_version.yml +++ b/tasks/set_version.yml @@ -21,7 +21,7 @@ msg: | "You are running this playbook in check mode: Please set the Gitea version with the variable 'gitea_version', because the URI module cannot detect the latest version in this mode." - when: ansible_check_mode and ( gitea_version not defined ) + when: ansible_check_mode and ( gitea_version == 'latest' or gitea_version == 'present' ) - name: "Set fact latest gitea release" ansible.builtin.set_fact: