added examples for systemd service usage (#83192)

mostly how to filter/manipulate the results
---------

Co-authored-by: flowerysong <junk+github@flowerysong.com>
pull/83132/head
Brian Coca 4 weeks ago committed by GitHub
parent 57a8eca3af
commit 504bdae894
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -45,6 +45,19 @@ EXAMPLES = r'''
- name: Print service facts
ansible.builtin.debug:
var: ansible_facts.services
- name: show names of existing systemd services, sometimes systemd knows about services that were never installed
debug: msg={{ existing_systemd_services | map(attribute='name') }}
vars:
known_systemd_services: "{{ ansible_facts['services'].values() | selectattr('source', 'equalto', 'systemd') }}"
existing_systemd_services: "{{ known_systemd_services | rejectattr('status', 'equalto', 'not-found') }}"
- name: restart systemd service if it exists
service:
state: restarted
name: ntpd.service
when: ansible_facts['services']['ntpd.service']['status'] | default('not-found') != 'not-found'
'''
RETURN = r'''

Loading…
Cancel
Save