squid: install systemd unit and restart only if needed

This commit is contained in:
Jérémy Lecour 2019-09-23 21:58:08 +02:00 committed by Jérémy Lecour
parent c98be7c864
commit 9ea567ee2d

View file

@ -1,14 +1,24 @@
--- ---
- name: "Set custom systemd unit service (Debian 10 or later)" - name: Look for existing systemd unit
command: systemctl -q is-active squid.service
changed_when: False
failed_when: False
register: squid_systemd_active
- name: "Squid systemd unit service is present (Debian 10 or later)"
copy: copy:
src: squid.service src: squid.service
dest: /etc/systemd/system/squid.service dest: /etc/systemd/system/squid.service
when: ansible_distribution_major_version | version_compare('10', '>=') when:
- ansible_distribution_major_version | version_compare('10', '>=')
- squid_systemd_active.rc != 0
- name: "Reload systemd and restart squid (Debian 10 or later)" - name: "Systemd is reload and Squid restarted (Debian 10 or later)"
systemd: systemd:
name: squid name: squid
state: restarted state: restarted
daemon_reload: yes daemon_reload: yes
when: ansible_distribution_major_version | version_compare('10', '>=') when:
- ansible_distribution_major_version | version_compare('10', '>=')
- squid_systemd_active.rc != 0