Hi @Todd Lewis,

That works.

Thanks a lot.

---
Lee

On Mon, Dec 27, 2021 at 10:25 PM Todd Lewis <[email protected]> wrote:
>
> which produces:
> TASK [Dump ActiveState] **********
> ok: [localhost] => {
>     "msg": [
>         {
>             "name": "postfix.service",
>             "state": "active"
>         },
>         {
>             "name": "rsyslog.service",
>             "state": "active"
>         },
>         {
>             "name": "sshd.service",
>             "state": "active"
>         }
>     ]
> }
>
> On Monday, December 27, 2021 at 11:53:21 AM UTC-5 Todd Lewis wrote:
>>
>> You probably want something like this:
>>
>> - hosts: localhost
>>   tasks:
>>   - name: Get Service Status
>>     ansible.builtin.systemd:
>>       name: '{{ item }}.service'
>>     register: hello
>>     loop:
>>       - postfix
>>       - rsyslog
>>       - sshd
>>
>>   - name: Dump ActiveState
>>     debug:
>>       msg: "{{ hello.results | json_query('[*].{name: name, state: 
>> status.ActiveState}') }}"
>>
>>
>> On Monday, December 27, 2021 at 1:32:02 AM UTC-5 [email protected] wrote:
>>>
>>> Hi,
>>>
>>> I am trying to write a playbook that displays the ActiveState of some
>>> services on a machine. I tried various tips from google but could not
>>> get the information I wanted, which is the "service.ActiveState" .
>>> Below is the bare minimum script.
>>>
>>> -----------------%<-----------------
>>>
>>> - hosts: localhost
>>> tasks:
>>> - name: Get Service Status
>>> ansible.builtin.systemd:
>>> name: '{{ item }}.service'
>>> register: hello
>>> loop:
>>> - postfix
>>> - rsyslog
>>> - sshd
>>> - debug:
>>> msg: "{{ hello.results | to_nice_json |
>>> json_query('status.ActiveState') }}"
>>>
>>> -----------------%<-----------------
>>>
>>> The output is
>>>
>>> -----------------%<-----------------
>>>
>>> PLAY [localhost] 
>>> ***************************************************************
>>>
>>> TASK [Gathering Facts] 
>>> *********************************************************
>>> ok: [localhost]
>>>
>>> TASK [Get Service Status] 
>>> ******************************************************
>>> ok: [localhost] => (item=postfix)
>>> ok: [localhost] => (item=rsyslog)
>>> ok: [localhost] => (item=sshd)
>>>
>>> TASK [debug] 
>>> *******************************************************************
>>> ok: [localhost] => {}
>>>
>>> PLAY RECAP 
>>> *********************************************************************
>>> localhost : ok=3 changed=0 unreachable=0
>>> failed=0 skipped=0 rescued=0 ignored=0
>>>
>>> -----------------%<-----------------
>>>
>>> Kindly advice
>>>
>>> Thanks
>>>
>>> ---
>>> Lee
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected].
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/ansible-project/b7f79cd9-8356-481a-aad4-ee8d3df60c92n%40googlegroups.com.

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAG7s96WkgY%3Dv617Lkb3PzQ-jXra4OeuP-bFHRmHDUTxCj1mRYg%40mail.gmail.com.

Reply via email to