Hi @Marian Saldhana, I need a loop as I want to add more services and machines.
Thanks --- Lee On Mon, Dec 27, 2021 at 2:48 PM Marian Saldhana <[email protected]> wrote: > > You can try something like this if it suits your requirements. > +++ > > - name: Get ypbind service status > > ansible.builtin.systemd: > > name: "ypbind" > > register: ypbind_status > > > > - debug: > > var: ypbind_status.status.ActiveState > > > > - name: Get smbd service status > > ansible.builtin.systemd: > > name: "smbd" > > register: smbd_status > > > > - debug: > > var: smbd_status.status.ActiveState > > > +++ > > > Output > > +++ > > > > > TASK [authentication_service_tab3 : debug] > ********************************************************************************************** > > ok: [192.168.43.237] => { > > "ypbind_status.status.ActiveState": "inactive" > > } > > ok: [192.168.43.6] => { > > "ypbind_status.status.ActiveState": "inactive" > > } > > > > > On Mon, Dec 27, 2021 at 1:48 PM Dick Visser <[email protected]> wrote: >> >> Can you post the unfiltered variable hello >> >> On Mon, 27 Dec 2021 at 07:32, Thomas Stephen Lee <[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/CAG7s96V2RgCu6LrKt06DKigdH-_DA0n%2Bp8Tsv9s6UB4205__BQ%40mail.gmail.com. >>> >> -- >> Sent from a mobile device - please excuse the brevity, spelling and >> punctuation. >> >> -- >> 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/CAL8fbwOSnpe%3D_zn4fxm5X7Sy3ofcHDdrUWMjm5YnvEM%3DZeAtNQ%40mail.gmail.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/CANDC7%2BDEW9-dG1fcjS-T2RE4%3DY6U3-nGs%2BNvoh8pDXb0uy788A%40mail.gmail.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/CAG7s96XMFKv7FPgfiWP%2Bxh-3vPjpYCbe2TsaJy8Muan2%3DCE6fw%40mail.gmail.com.
