How do you rotate secrets such as database passwords or API keys with Ansible?
IntermediateProductionSecurity and Secrets
Answer
Orchestrate in the right order so there is no outage: generate the new value, update the source of truth (secret manager), apply it to the consumer (the database user, then app config), reload, verify health, and only then retire the old value.
For database accounts, support two valid credentials during the changeover, or rotate in a rolling manner with serial. Keep the rotation playbook idempotent and tagged (--tags rotate_db), and log each step without printing the secret (no_log). If a manager can rotate by itself (Secrets Manager rotation Lambda), let Ansible only consume the value.
More on Security and Secrets
How do you set up a secure automation user and SSH access?BeginnerHow do you give the automation user sudo with least privilege?IntermediateWhat are the alternatives to Ansible Vault for secrets, and when do you use them?IntermediateHow do you read AWS Secrets Manager and SSM parameters in a playbook?IntermediateHow do you integrate HashiCorp Vault with Ansible?AdvancedHow do you stop secrets from leaking into logs and output?Beginner