On Thursday, 22 February 2018 22.26.01 CET John Harmon wrote:
> I have the following output from a variable called directories. It was
> created using a loop that would run stat against two different paths. What
> is the proper way to reference the "stat: exists: boolean" sections of the
> output? I need to check for both directories for both item.paths. I have
> tried and tried, but I must be doing something wrong.
> "directories.results": [
> {
> "_ansible_ignore_errors": null,
> "_ansible_item_result": true,
> "_ansible_no_log": false,
> "_ansible_parsed": true,
> "changed": false,
> "failed": false,
> "invocation": {
> "module_args": {
> "checksum_algorithm": "sha1",
> "follow": false,
> "get_attributes": true,
> "get_checksum": true,
> "get_md5": true,
> "get_mime": true,
> "path": "/home/applmgr/Scripts"
> }
> },
>
> *"item": { "path": "/home/applmgr/Scripts"*
> },
> "stat": {
> "atime": 1519330068.2478893,
> "attr_flags": "e",
> "attributes": [
> "extents"
> ],
> ......lots of stuff
> * "exists": true,*
> ......lots of stuff
> }
> },
> {
> "_ansible_ignore_errors": null,
> "_ansible_item_result": true,
> "_ansible_no_log": false,
> "_ansible_parsed": true,
> "changed": false,
> "failed": false,
> "invocation": {
> "module_args": {
> "checksum_algorithm": "sha1",
> "follow": false,
> "get_attributes": true,
> "get_checksum": true,
> "get_md5": true,
> "get_mime": true,
> "path": "/home/oracle/Scripts"
> }
> },
>
>
>
>
> * "item": { "path": "/home/oracle/Scripts" },
> "stat": { "exists": false*
> }
> }
> ]
> }
It depends on what you want to do next.
The fist one is
{{ directories.results.0.stats.exists }}
and the second one is
{{ directories.results.1.stats.exists }}
If you need both to be true before running a task that would be
when: directories.results.0.stats.exists and directories.results.1.stats.exists
since they are bools.
--
Kai Stian Olstad