ansible/pb_disable_browsed.yaml
2025-01-08 21:43:42 +01:00

28 lines
1.5 KiB
YAML

# Source https://sysadmin.info.pl/en/blog/disabling-the-cups-browsed-service-on-multiple-systems-using-ansible/
- name: Check if cups-browsed service exists (systemd)
command: systemctl cat cups-browsed
register: cups_browsed_exists
changed_when: False
failed_when: cups_browsed_exists.rc not in [0, 1]
when: systemctl_check.rc == 0
ignore_errors: yes
- name: Stop cups-browsed service (systemd)
systemd:
name: cups-browsed
state: stopped
when: cups_browsed_exists is defined and cups_browsed_exists.rc is defined and cups_browsed_exists.rc == 0
- name: Disable cups-browsed service (systemd)
systemd:
name: cups-browsed
enabled: no
when: cups_browsed_exists is defined and cups_browsed_exists.rc is defined and cups_browsed_exists.rc == 0
- name: Display cups-browsed service status in JSON format
debug:
msg: |
{
"Machine": "{{ inventory_hostname }}",
"Python binary": "{{ ansible_python_interpreter }}",
"Systemd used": "{{ 'Yes' if systemctl_check.rc == 0 else 'No' }}",
"Cups-browsed service exists": "{{ 'Yes' if (systemctl_check.rc == 0 and cups_browsed_exists is defined and cups_browsed_exists.rc == 0) else 'No' }}",
"Cups-browsed service stopped and disabled": "{{ 'Stopped and Disabled' if (systemctl_check.rc == 0 and cups_browsed_exists is defined and cups_browsed_exists.rc == 0) else 'Not applicable' }}"
}