Skip to content

Commit

Permalink
Merge pull request #11645 from rumch-se/template_change_ansible
Browse files Browse the repository at this point in the history
Changes in template service_disabled - ansible part
marcusburghardt authored Mar 7, 2024
2 parents f0474eb + f00e0ae commit 9753afb
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions shared/templates/service_disabled/ansible.template
Original file line number Diff line number Diff line change
@@ -3,30 +3,33 @@
# strategy = disable
# complexity = low
# disruption = low

{{%- if init_system == "systemd" %}}
- name: Block Disable service {{{ SERVICENAME }}}
block:
- name: Disable service {{{ SERVICENAME }}}
block:
- name: Disable service {{{ SERVICENAME }}}
systemd:
name: "{{{ DAEMONNAME }}}.service"
enabled: "no"
state: "stopped"
masked: "yes"
rescue:
- name: "Intentionally ignored previous 'Disable service {{{ SERVICENAME }}}' failure, service was already disabled"
meta: noop

- name: "{{{ rule_title }}} - Collect systemd Services Present in the System"
ansible.builtin.command: systemctl -q list-unit-files --type service
register: service_exists
changed_when: false
failed_when: service_exists.rc not in [0, 1]
check_mode: false

- name: '{{{ rule_title }}} - Ensure "{{{ DAEMONNAME }}}.service" is Masked'
ansible.builtin.systemd:
name: "{{{ DAEMONNAME }}}.service"
state: "stopped"
enabled: false
masked: true
when: 'service_exists.stdout_lines is search("{{{ SERVICENAME }}}.service",multiline=True)'

- name: "Unit Socket Exists - {{{ DAEMONNAME }}}.socket"
command: systemctl -q list-unit-files {{{ DAEMONNAME }}}.socket
ansible.builtin.command: systemctl -q list-unit-files {{{ DAEMONNAME }}}.socket
register: socket_file_exists
changed_when: False
changed_when: false
failed_when: socket_file_exists.rc not in [0, 1]
check_mode: False
check_mode: false

- name: Disable socket {{{ SERVICENAME }}}
systemd:
ansible.builtin.systemd:
name: "{{{ DAEMONNAME }}}.socket"
enabled: "no"
state: "stopped"

0 comments on commit 9753afb

Please sign in to comment.