Rekey a vault file

Re-encrypt a vault file with a new password without exposing the plaintext; a safe way to rotate the vault password

ansible-vault rekey vault.yml --new-vault-password-file new_pass.txt

tool
ansible56 commands
tags
ansiblevaultsecretssecurity

More ansible commands

  • ansible-playbook site.yml --vault-id dev@dev_pass.txt --vault-id prod@prompt

    Mix vault IDs: a password file for dev and a prompt for prod, so each environment has its own secrets

  • EDITOR=vim ansible-vault edit group_vars/prod/secrets.yml --vault-password-file ~/.vault_pass

    Decrypt, edit in $EDITOR and encrypt again in one step; the decrypted temp file is removed when you close the editor

  • ansible-inventory -i aws_ec2.yml --graph --vars

    Show the cloud inventory tree with host vars; check the plugin grouping before a run

  • ansible-inventory -i aws_ec2.yml --list --yaml > resolved_inventory.yml

    Turn a dynamic inventory into static YAML for diffs or offline debugging

  • plugin: constructed keyed_groups: - key: tags.Role prefix: role - key: placement.region prefix: region

    Build host groups from facts or tags with the constructed plugin, for example role_web, region_eu

all 56 ansible commands