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/20211223113556.5ae39cef%40gmail.com.
pgpTSBOQ6wZGD.pgp
Description: OpenPGP digital signature
