Skip to content

Commit 54f09b8

Browse files
authored
Merge pull request #3 from kysrpex/squid
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 PR 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.
2 parents 9252ae5 + f220483 commit 54f09b8

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

tasks/squid.yml

+20-6
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,28 @@
1818
setype: squid_cache_t
1919
when: cvmfs_stratum1_cache_dir is defined
2020

21-
- name: Create the cache directories for the first time
22-
become: true
23-
become_user: "{{ cvmfs_squid_user }}"
24-
ansible.builtin.command: squid -z
25-
args:
26-
creates: "{{ cvmfs_stratum1_cache_dir }}/00"
21+
- name: Check whether the cache directories exist
22+
ansible.builtin.stat:
23+
path: "{{ cvmfs_stratum1_cache_dir.dir }}/00"
24+
register: cvmfs_stratum1_cache_dir_stat
2725
when: cvmfs_stratum1_cache_dir is defined
2826

27+
- name: Create the cache directories for the first time
28+
when: cvmfs_stratum1_cache_dir is defined and not cvmfs_stratum1_cache_dir_stat.stat.exists
29+
block:
30+
31+
- name: Ensure squid is stopped
32+
ansible.builtin.service:
33+
name: "{{ cvmfs_squid_service_name }}"
34+
state: stopped
35+
36+
- name: Create the cache directories
37+
become: true
38+
become_user: "{{ cvmfs_squid_user }}"
39+
ansible.builtin.command: squid -z
40+
args:
41+
creates: "{{ cvmfs_stratum1_cache_dir.dir }}/00"
42+
2943
- name: Ensure squid is enabled and started
3044
ansible.builtin.service:
3145
name: "{{ cvmfs_squid_service_name }}"

0 commit comments

Comments
 (0)