# Get specifics from Ansible output

**URL:** <https://forum.ansible.com/t/get-specifics-from-ansible-output/19895>\
**Category:** Ansible Project\
**Created:** [November 30, 2015, 11:19am UTC](https://forum.ansible.com/t/get-specifics-from-ansible-output/19895 "2015-11-30T11:19:13Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![K\_de\_Jong](https://avatars.discourse-cdn.com/v4/letter/k/51bf81/32.png) [@K\_de\_Jong](https://forum.ansible.com/u/K_de_Jong)\
**Post date:** [November 30, 2015, 11:19am UTC](https://forum.ansible.com/t/get-specifics-from-ansible-output/19895/1 "2015-11-30T11:19:13Z")

</div>

First of all, this is what I’m trying to do. I want to check first if certain directories are in fact directories and not symlinks. If they happen to be directories I want to rename them to {{ item }}.old and then after that task I want to run a task that will replace the dirs with symlinks.  
My approach to do this now is to collect the stat information from a list of directories. Then I want to iterate through the information collected by Ansible and if the item is a dir (sym.stat.isdir == True) then I want to move it. After that task is complete I’ll run a new task that will create the symlinks to replace the dirs.

But I have a problem with the iteration process. A single directory is no problem, but it becomes unclear for me when a list of directories with the stat module is used. I assume this is possible, what’s the use of this information if you can’t use it 🙂

So this is what I’ve already tried.

The following task:

- name: check if home dirs are symlinks  
stat: path=/home/keesj/{{ item }}  
with\_items:

- Documents

- Music

- Pictures

- Videos  
register: sym  
tags: sym

- debug: var=sym.results

tags: sym

Has as output:

[root@defiant Ansible]# ansible-playbook -i hosts site.yml -t sym

PLAY [192.168.124.126] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

GATHERING FACTS \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
Enter passphrase for key ‘/root/.ssh/id\_rsa’:  
ok: [192.168.124.126]

TASK: [common | check if home dirs are symlinks] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [192.168.124.126] =\> (item=Documents)  
ok: [192.168.124.126] =\> (item=Music)  
ok: [192.168.124.126] =\> (item=Pictures)  
ok: [192.168.124.126] =\> (item=Videos)

TASK: [common | debug var=sym.results] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [192.168.124.126] =\> {  
“var”: {  
“sym.results”: [  
{  
“changed”: false,  
“invocation”: {  
“module\_args”: “path=/home/keesj/Documents”,  
“module\_complex\_args”: {},  
“module\_name”: “stat”  
},  
“item”: “Documents”,  
“stat”: {  
“atime”: 1448615699.9801893,  
“ctime”: 1448462998.0985308,  
“dev”: 64768,  
“exists”: true,  
“gid”: 1000,  
“gr\_name”: “keesj”,  
“inode”: 1449767,  
“isblk”: false,  
“ischr”: false,  
“isdir”: true,  
“isfifo”: false,  
“isgid”: false,  
“islnk”: false,  
“isreg”: false,  
“issock”: false,  
“isuid”: false,  
“mode”: “0755”,  
“mtime”: 1448462998.0985308,  
“nlink”: 2,  
“path”: “/home/keesj/Documents”,  
“pw\_name”: “keesj”,  
“rgrp”: true,  
“roth”: true,  
“rusr”: true,  
“size”: 4096,  
“uid”: 1000,  
“wgrp”: false,  
“woth”: false,  
“wusr”: true,  
“xgrp”: true,  
“xoth”: true,  
“xusr”: true  
}  
},  
{  
“changed”: false,  
“invocation”: {  
“module\_args”: “path=/home/keesj/Music”,  
“module\_complex\_args”: {},  
“module\_name”: “stat”  
},  
“item”: “Music”,  
“stat”: {  
“atime”: 1448615700.0871918,  
“ctime”: 1448462998.0985308,  
“dev”: 64768,  
“exists”: true,  
“gid”: 1000,  
“gr\_name”: “keesj”,  
“inode”: 1449768,  
“isblk”: false,  
“ischr”: false,  
“isdir”: true,  
“isfifo”: false,  
“isgid”: false,  
“islnk”: false,  
“isreg”: false,  
“issock”: false,  
“isuid”: false,  
“mode”: “0755”,  
“mtime”: 1448462998.0985308,  
“nlink”: 2,  
“path”: “/home/keesj/Music”,  
“pw\_name”: “keesj”,  
“rgrp”: true,  
“roth”: true,  
“rusr”: true,  
“size”: 4096,  
“uid”: 1000,  
“wgrp”: false,  
“woth”: false,  
“wusr”: true,  
“xgrp”: true,  
“xoth”: true,  
“xusr”: true  
}  
},  
{  
“changed”: false,  
“invocation”: {  
“module\_args”: “path=/home/keesj/Pictures”,  
“module\_complex\_args”: {},  
“module\_name”: “stat”  
},  
“item”: “Pictures”,  
“stat”: {  
“atime”: 1448615700.1171927,  
“ctime”: 1448462998.0985308,  
“dev”: 64768,  
“exists”: true,  
“gid”: 1000,  
“gr\_name”: “keesj”,  
“inode”: 1449769,  
“isblk”: false,  
“ischr”: false,  
“isdir”: true,  
“isfifo”: false,  
“isgid”: false,  
“islnk”: false,  
“isreg”: false,  
“issock”: false,  
“isuid”: false,  
“mode”: “0755”,  
“mtime”: 1448462998.0985308,  
“nlink”: 2,  
“path”: “/home/keesj/Pictures”,  
“pw\_name”: “keesj”,  
“rgrp”: true,  
“roth”: true,  
“rusr”: true,  
“size”: 4096,  
“uid”: 1000,  
“wgrp”: false,  
“woth”: false,  
“wusr”: true,  
“xgrp”: true,  
“xoth”: true,  
“xusr”: true  
}  
},  
{  
“changed”: false,  
“invocation”: {  
“module\_args”: “path=/home/keesj/Videos”,  
“module\_complex\_args”: {},  
“module\_name”: “stat”  
},  
“item”: “Videos”,  
“stat”: {  
“atime”: 1448615700.1201928,  
“ctime”: 1448462998.0985308,  
“dev”: 64768,  
“exists”: true,  
“gid”: 1000,  
“gr\_name”: “keesj”,  
“inode”: 1449770,  
“isblk”: false,  
“ischr”: false,  
“isdir”: true,  
“isfifo”: false,  
“isgid”: false,  
“islnk”: false,  
“isreg”: false,  
“issock”: false,  
“isuid”: false,  
“mode”: “0755”,  
“mtime”: 1448462998.0985308,  
“nlink”: 2,  
“path”: “/home/keesj/Videos”,  
“pw\_name”: “keesj”,  
“rgrp”: true,  
“roth”: true,  
“rusr”: true,  
“size”: 4096,  
“uid”: 1000,  
“wgrp”: false,  
“woth”: false,  
“wusr”: true,  
“xgrp”: true,  
“xoth”: true,  
“xusr”: true  
}  
}  
]  
}  
}

PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
192.168.124.126 : ok=3 changed=0 unreachable=0 failed=0

It would be nice if these items could be read with a with\_items: and then iterate through it. But nothing I haven’t been successful in finding a way to do that.

This may be something? But again, I’m stuck, tried a lot of things to get some info out of it, but nothing. Also can’t find any documentation about it for Ansible.

- debug: var=sym.items

tags: sym

[root@defiant Ansible]# ansible-playbook -i hosts site.yml -t sym

PLAY [192.168.124.126] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

GATHERING FACTS \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [192.168.124.126]

TASK: [common | check if home dirs are symlinks] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [192.168.124.126] =\> (item=Documents)  
ok: [192.168.124.126] =\> (item=Music)  
ok: [192.168.124.126] =\> (item=Pictures)  
ok: [192.168.124.126] =\> (item=Videos)

TASK: [common | debug var=sym.items] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [192.168.124.126] =\> {  
“var”: {  
“sym.items”: “\<built-in method items of dict object at 0x7ff5fb9cf398\>”  
}  
}

Any suggestions?
