LOGBOOK

HELP

Quiz Entry - updated: 2026.11.12

How do you make sure a file is gone from the managed hosts, and why should state be written out even where it is optional?

ansible.builtin.file with state: absent deletes the path if it exists and reports ok if it is already gone. Writing state explicitly documents the intended end state and protects you from a module's default changing.

- name: Make sure a file does not exist on managed hosts
  ansible.builtin.file:
    dest: /path/to/file
    state: absent

(dest and name are aliases of path in the file module.)

Many modules have a default state, usually present, so state can often be left out. Write it anyway:

  • Readability. state: absent says "this must not exist" at a glance; without it, the reader has to know each module's default.
  • Modules have more than two states. file alone knows file, directory, link, hard, touch and absent; apt knows present, latest, absent, ...
  • Defaults can change between versions, and an explicit value keeps the task meaning the same.

Since Ansible describes desired states, not commands, a task without a visible state hides exactly the information the reader needs.

Go deeper:

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