From f220483465d3f5e426e0937c739045cbb79be43c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Manuel=20Dom=C3=ADnguez?= Date: Tue, 27 Jun 2023 16:10:25 +0200 Subject: [PATCH 1/3] Fix role failing on Squid task "Create the cache directories for the first time" Squid cannot be launched if it is already running. If the role has been run at least once, then Squid will fail to execute during the "Create the cache directories for the first time" task, causing the whole role to fail. This commit changes the behavior of the role so that it tries to create the cache directories only if they do not exist. In addition, it ensures Squid is not running before trying to do so. --- tasks/squid.yml | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/tasks/squid.yml b/tasks/squid.yml index b994e61..15c9499 100644 --- a/tasks/squid.yml +++ b/tasks/squid.yml @@ -6,7 +6,7 @@ backup: true mode: 0644 notify: - - restart squid + - Restart squid - name: Fix cache directory permission ansible.builtin.file: @@ -18,14 +18,28 @@ setype: squid_cache_t when: cvmfs_stratum1_cache_dir is defined -- name: Create the cache directories for the first time - become: true - become_user: "{{ cvmfs_squid_user }}" - ansible.builtin.command: squid -z - args: - creates: "{{ cvmfs_stratum1_cache_dir }}/00" +- name: Check whether the cache directories exist + ansible.builtin.stat: + path: "{{ cvmfs_stratum1_cache_dir.dir }}/00" + register: cvmfs_stratum1_cache_dir_stat when: cvmfs_stratum1_cache_dir is defined +- name: Create the cache directories for the first time + when: cvmfs_stratum1_cache_dir is defined and not cvmfs_stratum1_cache_dir_stat.stat.exists + block: + + - name: Ensure squid is stopped + ansible.builtin.service: + name: "{{ cvmfs_squid_service_name }}" + state: stopped + + - name: Create the cache directories + become: true + become_user: "{{ cvmfs_squid_user }}" + ansible.builtin.command: squid -z + args: + creates: "{{ cvmfs_stratum1_cache_dir.dir }}/00" + - name: Ensure squid is enabled and started ansible.builtin.service: name: "{{ cvmfs_squid_service_name }}" From 58679a5fb8d0a57385cd54d158057a946f140400 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Manuel=20Dom=C3=ADnguez?= Date: Wed, 28 Jun 2023 08:48:44 +0200 Subject: [PATCH 2/3] Revert "Fix role failing on Squid task "Create the cache directories for the first time"" This reverts commit f220483465d3f5e426e0937c739045cbb79be43c. --- tasks/squid.yml | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/tasks/squid.yml b/tasks/squid.yml index 15c9499..b994e61 100644 --- a/tasks/squid.yml +++ b/tasks/squid.yml @@ -6,7 +6,7 @@ backup: true mode: 0644 notify: - - Restart squid + - restart squid - name: Fix cache directory permission ansible.builtin.file: @@ -18,27 +18,13 @@ setype: squid_cache_t when: cvmfs_stratum1_cache_dir is defined -- name: Check whether the cache directories exist - ansible.builtin.stat: - path: "{{ cvmfs_stratum1_cache_dir.dir }}/00" - register: cvmfs_stratum1_cache_dir_stat - when: cvmfs_stratum1_cache_dir is defined - - name: Create the cache directories for the first time - when: cvmfs_stratum1_cache_dir is defined and not cvmfs_stratum1_cache_dir_stat.stat.exists - block: - - - name: Ensure squid is stopped - ansible.builtin.service: - name: "{{ cvmfs_squid_service_name }}" - state: stopped - - - name: Create the cache directories - become: true - become_user: "{{ cvmfs_squid_user }}" - ansible.builtin.command: squid -z - args: - creates: "{{ cvmfs_stratum1_cache_dir.dir }}/00" + become: true + become_user: "{{ cvmfs_squid_user }}" + ansible.builtin.command: squid -z + args: + creates: "{{ cvmfs_stratum1_cache_dir }}/00" + when: cvmfs_stratum1_cache_dir is defined - name: Ensure squid is enabled and started ansible.builtin.service: From 13fbd036ad1a11b1a0853abdd02142edb87d728b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Manuel=20Dom=C3=ADnguez?= Date: Wed, 28 Jun 2023 08:53:41 +0200 Subject: [PATCH 3/3] Fix role failing on Squid task "Create the cache directories for the first time" This is a simpler solution than that from f220483. In fact, the cause of the problem was just a typo (see changes and docs for ansible.builtin.command). --- tasks/squid.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasks/squid.yml b/tasks/squid.yml index b994e61..7930ecf 100644 --- a/tasks/squid.yml +++ b/tasks/squid.yml @@ -23,7 +23,7 @@ become_user: "{{ cvmfs_squid_user }}" ansible.builtin.command: squid -z args: - creates: "{{ cvmfs_stratum1_cache_dir }}/00" + creates: "{{ cvmfs_stratum1_cache_dir.dir }}/00" when: cvmfs_stratum1_cache_dir is defined - name: Ensure squid is enabled and started