In my point of view, the in the original question tried approach to gather service statuses should be avoided since that example seems to be an anti-pattern for Ansible. However, there are options to fulfill the requirement for a report.
A simpler solution is either
ansible test -m systemd -a 'name=cntlm enabled=true'
test.example.com | SUCCESS => {
"changed": false,
"enabled": true,
"name": "cntlm",
"status": {
<a lot of output>
}
}
or
ansible test -m shell -a 'systemctl status cntlm'
test.example.com | CHANGED | rc=0 >>
● cntlm.service - CNTLM HTTP Accelerator For NTLM Secured Proxies Authenticator
Loaded: loaded (/usr/lib/systemd/system/cntlm.service; enabled; vendor preset: disabled)
Active: active (running) since Thu 2022-09-01 09:00:00 CEST; 1 weeks 4 days ago
Main PID: 234567 (cntlm)
CGroup: /system.slice/cntlm.service
└─234567 /usr/sbin/cntlm -c /etc/cntlm.conf -U cntlm -P /run/cntlm/cntlmd.pid
or almost the requested, after enabling callback plugin for ad hoc commands
ansible test -m shell -a 'systemctl status cntlm'
PLAY [Ansible Ad-Hoc] **************************************************************************************************
Monday 01 September 2022 09:00:00 +0200 (0:00:00.071) 0:00:00.071 ******
TASK [shell] ***********************************************************************************************************
changed: [test.example.com]
PLAY RECAP *************************************************************************************************************
test.example.com : ok=1 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
Monday 01 September 2022 09:00:00 +0200 (0:00:02.171) 0:00:02.243 ******
===============================================================================
shell ----------------------------------------------------------------------------------------------------------- 2.17s
Playbook run took 0 days, 0 hours, 0 minutes, 2 seconds
Config
[defaults]
bin_ansible_callbacks = True
Further Q&A
Finally, If you are now are interested in customizing the output more, you'll probably need to start Developing plugins and creating your own Callback plugin. The source of lib/ansible/plugins/callback/default.py
can be a good start.