Interview Prep/Ansible/Vault, Performance and Execution Behaviour

`--tags deploy` also ran a cleanup task tagged `always` and deleted the release directory

IntermediateTroubleshootingVault, Performance and Execution Behaviour
Answer

Likely causes → Tasks tagged always run for any --tags selection, and are skipped only with --skip-tags always. The never tag works the opposite way: those tasks run only when their other tag is requested explicitly.

Fix → Remove always from destructive tasks, and give them never plus an explicit tag:

- ansible.builtin.file:
    path: /opt/app/releases/old
    state: absent
  tags: [never, cleanup]

Now it only runs with --tags cleanup.

Prevent → Keep always for fact-setting and validation tasks only. Review --list-tasks --tags <x> output before relying on a tag.

All Ansible questions Roadmap: Ansible

More on Vault, Performance and Execution Behaviour