How do you read AWS Secrets Manager and SSM parameters in a playbook?
IntermediateProductionSecurity and Secrets
Answer
vars:
db_password: "{{ lookup('amazon.aws.secretsmanager_secret', 'prod/app/db', region='ap-south-1') }}"
api_key: "{{ lookup('amazon.aws.ssm_parameter', '/prod/app/api_key', region='ap-south-1', decrypt=true) }}"
Lookups run on the control node, using its AWS credentials (an instance role is best). The IAM policy should allow only secretsmanager:GetSecretValue on the specific ARNs. Lookups are re-evaluated every time the variable is used, so assign the value once with set_fact under no_log: true when it is used a lot.
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 integrate HashiCorp Vault with Ansible?AdvancedHow do you stop secrets from leaking into logs and output?BeginnerHow do you handle the vault password in CI/CD?Intermediate