Thanks a lot, Vladimir
That works.

Thanks

---
Lee

On Thu, Dec 23, 2021 at 4:05 PM Vladimir Botka <[email protected]> wrote:

> On Thu, 23 Dec 2021 14:22:00 +0530
> Thomas Stephen Lee <[email protected]> wrote:
>
> > - hosts: localhost
> >   tasks:
> >     - name: Populate service facts
> >       ansible.builtin.service_facts:
> >
> >     - name: Print service facts
> >       loop:
> >       - postfix
> >       - rsyslog
> >       - sshd
> >       ansible.builtin.debug:
> >         var: ansible_facts.services['{{ item }}.service']['state']
> > ...
> > should print only
> >
> > "ansible_facts.services['rsyslog.service']['state']": "running"
>
> Try
>
>      - name: Print service facts
>        ansible.builtin.debug:
>          msg: '{{ _sr }}: {{ _st }}'
>        loop:
>          - postfix
>          - rsyslog
>          - sshd
>        vars:
>          _sr: 'ansible_facts.services["{{ item }}.service"]["state"]'
>          _st: '{{ ansible_facts.services[item ~ ".service"].state }}'
>
> The single/double quotes of the results are reversed. If this is a
> problem you'll have to escape them.
>
> ok: [localhost] => (item=sshd) =>
>   msg: 'ansible_facts.services["sshd.service"]["state"]: active'
>
> --
> Vladimir Botka
>

-- 
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/CAG7s96VPduwR6igk%3DzYm477Ey%3DCOdU%3DCBPyaQzr0VyPwbZ-MYQ%40mail.gmail.com.

Reply via email to