Parsing output

21 views
Skip to first unread message

John Harmon

unread,
Aug 25, 2017, 11:03:21 AM8/25/17
to Ansible Project
I have the following output from my debug (using "find", and the debug output for "files")
{
           
"atime": 1503588437.3974097,
           
"ctime": 1503588433.7234097,
           
"dev": 2051,
           
"gid": 0,
           
"inode": 21408,
           
"isblk": false,
           
"ischr": false,
           
"isdir": false,
           
"isfifo": false,
           
"isgid": false,
           
"islnk": false,
           
"isreg": true,
           
"issock": false,
           
"isuid": false,
           
"mode": "0644",
           
"mtime": 1503588433.7194097,
           
"nlink": 1,
           
"path": "/etc/sysconfig/network-scripts/ifcfg-enp0s3",
           
"rgrp": true,
           
"roth": true,
           
"rusr": true,
           
"size": 278,
           
"uid": 0,
           
"wgrp": false,
           
"woth": false,
           
"wusr": true,
           
"xgrp": false,
           
"xoth": false,
           
"xusr": false
       
}

I need to parse out /etc/sysconfig/network-scripts/ifcfg-enp0s3 (or maybe even just ifcfg-enp0s3) from the above output.... how would I go about doing that? 

Kai Stian Olstad

unread,
Aug 25, 2017, 11:18:14 AM8/25/17
to ansible...@googlegroups.com
I think you have left out something of the output since find can return more
than one answer it always return a list.

So if you use register: result on the find you can always do this.

- debug: msg='Found file: {{ item.path }}'
with_items: '{{ result.files }}'


--
Kai Stian Olstad

John Harmon

unread,
Aug 25, 2017, 11:23:15 AM8/25/17
to Ansible Project, ansible-pr...@olstad.com
Perfect.  Thank you.
Reply all
Reply to author
Forward
0 new messages