Interview Prep/Ansible/Security: Vault, Become and Compliance

You need to store an SSH private key that Ansible deploys to hosts.

IntermediateScenarioSecurity: Vault, Become and Compliance
Answer

Situation read → Secret file distribution.

What I'd do → Encrypt the whole key file with vault and use copy with content.

- ansible.builtin.copy:
    content: "{{ vault_deploy_key }}\n"
    dest: /home/deploy/.ssh/id_ed25519
    owner: deploy
    mode: "0600"
  no_log: true

Why → no_log avoids exposing the key in output and diffs.

Interview tip → Use --diff carefully; it can print file contents. Use no_log or diff: false.

All Ansible questions Roadmap: Ansible

More on Security: Vault, Become and Compliance