Howto access 'exists' from a register: var which has results?

31 views
Skip to first unread message

Patrick Ansible-ML

unread,
Sep 15, 2014, 9:56:43 AM9/15/14
to ansible...@googlegroups.com
Hi,

I have a task which checks if some files exist and does a register. In
the next task, how do I access the exists: [false|true] result for use
in 'when:'? I tried variations of things like this:
'repos_extra_installed.results.stats.exists == false'
but I always get an error.

group_vars:

repos_extra_repos:
- repos_extra_name: internal
repos_extra_file: internal.repo
repos_extra_key: RPM-GPG-KEY-internal

task:

- name: repos | Check if extra repos are already installed
stat:
path: /etc/yum.repos.d/{{ item.repos_extra_file }}
with_items: repos_extra_repos
register: repos_extra_installed

- debug: var=repos_extra_installed

Debug output:

TASK: [common | debug var=repos_extra_installed]
******************************
ok: [test.local] => {
"repos_extra_installed": {
"changed": false,
"msg": "All items completed",
"results": [
{
"changed": false,
"invocation": {
"module_args": "",
"module_name": "stat"
},
"item": {
"repos_extra_file": "internal.repo",
"repos_extra_key": "RPM-GPG-KEY-internal",
"repos_extra_name": "internal"
},
"stat": {
"exists": false
}
}
]
}
}


Thanks,
Patrick

Michael Peters

unread,
Sep 15, 2014, 10:02:09 AM9/15/14
to ansible...@googlegroups.com
It should be repos_extra_installed.results[0].stat.exists.

It's more complicated because you're doing a with_items on the task
that does the register. So each item in that list will have a separate
entry in the repos_extra_installed.results 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 ansible-proje...@googlegroups.com.
> To post to this group, send email to ansible...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/5413E11D.805%40puzzled.xs4all.nl.
> For more options, visit https://groups.google.com/d/optout.

Patrick Ansible-ML

unread,
Sep 15, 2014, 3:43:12 PM9/15/14
to ansible...@googlegroups.com
On 15-09-14 16:02, Michael Peters wrote:
> It should be repos_extra_installed.results[0].stat.exists.
>
> It's more complicated because you're doing a with_items on the task
> that does the register. So each item in that list will have a separate
> entry in the repos_extra_installed.results list.

Thank you Michael.

Cheers,
Patrick


Reply all
Reply to author
Forward
0 new messages