Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Return Values of Ansible Commands

Tags:

ansible

I am trying to find the return values of Ansible commands so I can better program in Ansible Playbooks. Using stat as an example. I don't see any any of the return values listed in the documentation. http://docs.ansible.com/stat_module.html

I am however able to find them by doing adhoc commands. Is there a better way? Perhaps they are not documented because it is OS specific in each instance.

For example:

ansible 12.34.56.78  -m stat -a "path=/appserver"
12.34.56.78 | success >> {
"changed": false,
"stat": {
    "atime": 1424197918.2113113,
    "ctime": 1423779491.431509,
    "dev": 64768,
    "exists": true,
    "gid": 1000,
    "inode": 9742,
    "isblk": false,
    "ischr": false,
    "isdir": true,
    "isfifo": false,
    "isgid": false,
    "islnk": false,
    "isreg": false,
    "issock": false,
    "isuid": false,
    "mode": "0755",
    "mtime": 1423585087.2470782,
    "nlink": 4,
    "pw_name": "cloud",
    "rgrp": true,
    "roth": true,
    "rusr": true,
    "size": 4096,
    "uid": 1000,
    "wgrp": false,
    "woth": false,
    "wusr": true,
    "xgrp": true,
    "xoth": true,
    "xusr": true
}
}
like image 387
Timothy Faraci Avatar asked Feb 17 '15 22:02

Timothy Faraci


1 Answers

Your best bet is to do exactly what you did, or to write a playbook that dumps the contents of what the module returns:

- stat: path=/path/to/file
  register: st

- debug: var=st

Part of the reason the stat command doesn't document everything it returns is because as the documentation for the module states:

Retrieves facts for a file similar to the linux/unix ‘stat’ command.

So you can find out what all those properties mean if you invoke man 2 stat in a linux shell.

like image 76
Bruce P Avatar answered Nov 30 '22 20:11

Bruce P