Ansible Module stat: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 9: Line 9:


<syntaxhighlight lang='yaml'>
<syntaxhighlight lang='yaml'>
- name: "Check if a directory exists"
- name: Gather stats on the given path
   stat:
   stat:
     path: "{{ some_path }}"
     path: "{{ some_path }}"
   register: some_dir
   register: some_path_stat
- name: debug
  debug:
    var: some_path_stat
</syntaxhighlight>
 
The module result variable has the following structure:
<syntaxhighlight lang=''json'>
{
        "changed": false,
        "failed": false,
        "stat": {
            "atime": 1625423678.392114,
            "attr_flags": "",
            "attributes": [],
            "birthtime": 1625352249.6358514,
            "block_size": 4096,
            "blocks": 0,
            "charset": "binary",
            "ctime": 1625423644.281025,
            "dev": 16777220,
            "device_type": 0,
            "executable": true,
            "exists": true,
            "flags": 0,
            "generation": 0,
            "gid": 20,
            "gr_name": "staff",
            "inode": 30508999,
            "isblk": false,
            "ischr": false,
            "isdir": true,
            "isfifo": false,
            "isgid": false,
            "islnk": false,
            "isreg": false,
            "issock": false,
            "isuid": false,
            "mimetype": "inode/directory",
            "mode": "0755",
            "mtime": 1625423644.281025,
            "nlink": 24,
            "path": "/Users/ovidiu/Library/Application Support/JetBrains/IntelliJIdea2021.2",
            "pw_name": "ovidiu",
            "readable": true,
            "rgrp": true,
            "roth": true,
            "rusr": true,
            "size": 768,
            "uid": 502,
            "version": null,
            "wgrp": false,
            "woth": false,
            "writeable": true,
            "wusr": true,
            "xgrp": true,
            "xoth": true,
            "xusr": true
        }
    }
</syntaxhighlight>
</syntaxhighlight>

Revision as of 06:10, 5 July 2021

External

Internal

Overview

Retrieves facts for a file similar to the Linux/Unix "stat" command.

- name: Gather stats on the given path
  stat:
    path: "{{ some_path }}"
  register: some_path_stat
- name: debug
  debug:
    var: some_path_stat

The module result variable has the following structure:

{
        "changed": false,
        "failed": false,
        "stat": {
            "atime": 1625423678.392114,
            "attr_flags": "",
            "attributes": [],
            "birthtime": 1625352249.6358514,
            "block_size": 4096,
            "blocks": 0,
            "charset": "binary",
            "ctime": 1625423644.281025,
            "dev": 16777220,
            "device_type": 0,
            "executable": true,
            "exists": true,
            "flags": 0,
            "generation": 0,
            "gid": 20,
            "gr_name": "staff",
            "inode": 30508999,
            "isblk": false,
            "ischr": false,
            "isdir": true,
            "isfifo": false,
            "isgid": false,
            "islnk": false,
            "isreg": false,
            "issock": false,
            "isuid": false,
            "mimetype": "inode/directory",
            "mode": "0755",
            "mtime": 1625423644.281025,
            "nlink": 24,
            "path": "/Users/ovidiu/Library/Application Support/JetBrains/IntelliJIdea2021.2",
            "pw_name": "ovidiu",
            "readable": true,
            "rgrp": true,
            "roth": true,
            "rusr": true,
            "size": 768,
            "uid": 502,
            "version": null,
            "wgrp": false,
            "woth": false,
            "writeable": true,
            "wusr": true,
            "xgrp": true,
            "xoth": true,
            "xusr": true
        }
    }