I would like to walk over lots of hosts and get all services that were manually started (systemctl start xxxx) without being enabled first (systemctl enable xxxx) and also vice-versa all services which are disabled (systemctl disable xxxx) but still running (because have not been stopped).
And instead of automatically 'fixing' all of the above found problems I just would like to have them output to my shell.
Something like a for each loop over systemctl list-unit-files --state=disabled
and running every row through systemctl is-active
would probably work, but I would need to transfer a small SH script to every host...
Can this be done by Ansible alone? (using RHEL7 Update 7 with kernel 3.10.x)
Edit: This is my playbook so far, but I can not get the loop working:
---
- hosts: all
gather_facts: no
tasks:
- name: get service facts
service_facts:
- name: show report
when:
- ansible_facts.services[item + '.service'].state == 'running'
- ansible_facts.services[item + '.service'].status == 'disabled'
debug:
msg: "{{ ansible_facts.services[item + '.service'].status == 'disabled' }}"
loop:
ansible_facts.services