Make a directory with the file module
Learn
file: paths and their attributes
ansible.builtin.file manages whether a path exists and its attributes, through
state::
state: | ensures |
|---|---|
directory | a directory exists |
touch | an (empty) file exists, updating its timestamp |
absent | the path is gone |
mode: sets permissions ("0644"), owner: and group: set ownership.
Tasks run in order, top to bottom, and the PLAY RECAP's changed counts every task that
altered something in this run. The editor opens with your playbook from the previous step:
add a second task below the first.
Your task
Now add a second task using the ansible.builtin.file module to ensure an empty
file ready.flag exists (state: touch). Keep your copy task above it — the run should
now report two changed tasks.
- name: Mark the host ready
ansible.builtin.file:
path: ready.flag
state: touch
Interview prep
Knowing the difference between changed and ok shows you understand what Ansible is actually doing.
A task reports ok instead of changed. Did it run?
Yes — ok means the module ran and found the machine already in the desired state, so it made no change. changed means it had to act. The task succeeded either way; the difference tells you whether this run actually altered anything, which is how you reason about what a playbook did.