LOGBOOK

HELP

Quiz Entry - updated: 2026.11.12

How do you find out which values stat returns, and what is the most common use of its result in a playbook?

Read the module docs (ansible-navigator doc ansible.builtin.stat or ansible-doc), or register the result and print it with debug: var:; most often the result feeds a when such as when: not result.stat.exists.

- name: Examine all stat output of /etc/passwd
  hosts: workstation
  tasks:
    - name: stat /etc/passwd
      ansible.builtin.stat:
        path: /etc/passwd
      register: results

    - name: Display stat results
      ansible.builtin.debug:
        var: results

Printing the whole variable once is the quickest way to learn its shape: you see results.stat.exists, results.stat.mode, results.stat.pw_name and so on, with real values from your host.

In real playbooks stat is the "look before you leap" step:

- ansible.builtin.stat:
    path: /etc/myapp/initialized
  register: init_flag

- name: Run first-time setup
  ansible.builtin.command: /usr/local/bin/myapp-init
  when: not init_flag.stat.exists

If the file doesn't exist, stat still succeeds, with exists: false, so the check never fails the play.

Go deeper:

From Quiz: ITIA / Ansible: Managing Files and Jinja2 Templates | Updated: Nov 12, 2026