Ensure we only try to enable service if the unit file existed
This commit is contained in:
parent
2c5e901450
commit
2eecb73a49
1 changed files with 13 additions and 3 deletions
|
|
@ -379,16 +379,26 @@ Unowned /etc config files not attributed to packages or services.
|
||||||
task_parts.append(copy_task(mf, "[Restart service]"))
|
task_parts.append(copy_task(mf, "[Restart service]"))
|
||||||
|
|
||||||
task_parts.append(
|
task_parts.append(
|
||||||
f"""- name: Ensure {unit} is enabled (preserve running state)
|
f"""
|
||||||
|
- name: Check if unit exists
|
||||||
|
ansible.builtin.command: systemctl cat "{{ unit_name }}"
|
||||||
|
register: _unit_exists
|
||||||
|
changed_when: false
|
||||||
|
failed_when: false
|
||||||
|
|
||||||
|
- name: Ensure {unit} is enabled (preserve running state)
|
||||||
ansible.builtin.service:
|
ansible.builtin.service:
|
||||||
name: "{{{{ unit_name }}}}"
|
name: "{{ unit_name }}"
|
||||||
enabled: true
|
enabled: true
|
||||||
|
when: _unit_exists.rc == 0
|
||||||
|
|
||||||
- name: Start {unit} if it was active at harvest time
|
- name: Start {unit} if it was active at harvest time
|
||||||
ansible.builtin.service:
|
ansible.builtin.service:
|
||||||
name: "{{{{ unit_name }}}}"
|
name: "{{{{ unit_name }}}}"
|
||||||
state: started
|
state: started
|
||||||
when: {var_prefix}_start | bool
|
when:
|
||||||
|
- {var_prefix}_start | bool
|
||||||
|
- _unit_exists.rc == 0
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue