Safeguard
Security Guides•

Does Ansible Vault keep files encrypted on the target host?

Not always. A vaulted file passed as src to copy or template is decrypted on the target. Learn which modules do this and how to limit the exposure.

Safeguard Security Team
3 min read

Not always. Content you encrypt with Ansible Vault stays encrypted after a run, with one exception: if you pass an encrypted file as the src of the copy, template, unarchive, script or assemble modules, the file arrives decrypted on the target host when the right password is supplied.

Why this is by design

The documentation calls this intended and useful. You may encrypt a configuration file or template to avoid sharing its details in your repository. Servers then need the plain version so local users and processes can read it. Vault protects the file in source control and on the control node, not on the target.

What Vault protects

LocationProtected by Vault
In your Git repositoryYes, if encrypted
In a log of the file contentsNo, unless output is suppressed
On the target after copy or templateNo, it is plain
In transitGoverned by the connection method, such as SSH

Vault is encryption at rest for your automation source. It is not a secret store for running systems.

Risks after decryption

  • The file's permissions on the target decide who can read it. Set mode and owner explicitly.
  • Backups of the target may capture it in plain form.
  • A later task that reads the file into a registered variable could print it.
  • Debug output can expose the content, so protect tasks with no_log: true as appropriate.

Safer handling

  1. Set tight mode and owner on every task that places a secret file.
  2. Place secrets in a directory with restricted access.
  3. Keep short lived secrets short lived: rotate them after deployment where you can.
  4. Consider whether the application can fetch its secret from a manager at start up, rather than from a file you push.
  5. Add no_log: true to the task, since the file's contents may appear in a diff.

Format notes

Vault files are UTF-8 text with a header line such as $ANSIBLE_VAULT;1.1;AES256 followed by the encrypted body. The header can include a vault ID label. Anyone can see that a file is a vault file, so do not rely on hiding the fact that it exists.

Quick check

Are vaulted variables decrypted on the target too?

Variables are decrypted for use during the run. What lands on disk depends on what each task writes.

Does Vault help with secrets at runtime?

It protects stored automation content. It is not a runtime secret manager.

Is the decrypted file removed after the run?

Not unless your playbook removes it.

Safeguard offers SBOM and dependency scanning and policy gates that can block a pull request on findings, and you can try a free scan at gold.safeguard.sh/scan.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.