Last active
April 1, 2022 20:09
-
-
Save frenata/f91acd4c0c4dc463a937e6da7b6f629a to your computer and use it in GitHub Desktop.
conditionally restart systemd unit files via ansible, two styles
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tasks: | |
- name: specify a systemd unit file | |
become: true | |
copy: | |
src: foo.service | |
dest: /etc/systemd/system | |
notify: restart foo | |
- name: enable the systemd unit file | |
become: true | |
systemd: | |
name: foo | |
enabled: yes | |
daemon_reload: yes | |
state: started | |
handlers: | |
- name: restart foo | |
become: true | |
systemd: | |
name: foo | |
daemon_reload: yes | |
state: restarted |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tasks: | |
- name: specify a systemd unit file | |
become: true | |
copy: | |
src: foo.service | |
dest: /etc/systemd/system | |
register: foo # record the results of this task | |
- name: enable the systemd unit file | |
become: true | |
systemd: | |
name: foo | |
enabled: yes | |
daemon_reload: yes | |
state: "{{'restarted' if foo.changed else 'started'}}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment