On Monday, August 12, 2019 at 3:57:36 PM UTC-4, a.g. wrote:
>
> I can't seem to get this syntax correct, and at least one reference I 
> found produced more errors.  I'd like to create a list of all running 
> processes.
>
>     - name: populate running services into a list
>       set_fact:
>         services_running: >
>           {%  if (hostvars[inventory_hostname]['services']['{{ item 
> }}']['state'] == 'running')  %}
>                  services_running + [ '{{ item }}' ]
>           {%  endif  %}
>       with_items: "{{ hostvars[inventory_hostname]['services'].keys() }}"
>

That's a very roundabout approach.

- set_fact:
    services_running: "{{ services | dict2items | selectattr('value.state', 
'equalto', 'running') | map(attribute='key') | list }}"

-- 
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/468166b7-a2ee-4c1e-8331-b202279d65ab%40googlegroups.com.

Reply via email to