The goal of this Task is to securely store, manage, and automate the distribution of sensitive credentials using Ansible Vault. The project will integrate Ansible Vault into a CI/CD pipeline with Jenkins, GitHub, AWS Secrets Manager, and Terraform for end-to-end automation.
echo "my_secret_password" > .vault_pass
ansible-vault encrypt secrets.yml --vault-password-file .vault_pass
db_user: admin
db_password: SuperSecurePassword123
aws_access_key: AKIAXXXXXXX
aws_secret_key: 5y3NtXXXXXXX
aws secretsmanager create-secret --name ansible-vault-password --secret-string "my_secret_password"
pipeline {
agent any
environment {
VAULT_PASSWORD = sh(script: "aws secretsmanager get-secret-value --secret-id ansible-vault-password --query SecretString --output text", returnStdout: true).trim()
}
stages {
stage('Decrypt Secrets') {
steps {
sh "echo ${VAULT_PASSWORD} > .vault_pass"
sh "ansible-vault decrypt secrets.yml --vault-password-file .vault_pass"
}
}
stage('Deploy Infrastructure') {
steps {
sh "ansible-playbook -i inventory playbook.yml --vault-password-file .vault_pass"
}
}
}
}
Use Jenkins credentials store to inject secrets dynamically.
resource "aws_instance" "web" {
ami = "ami-12345678"
instance_type = "t2.micro"
tags = {
Name = "SecureWebServer"
}
}
export ANSIBLE_VAULT_PASSWORD=$(aws secretsmanager get-secret-value --secret-id ansible-vault-password --query SecretString --output text)
ansible-playbook -i inventory playbook.yml --vault-password-file .vault_pass
Automate secret rotation with AWS Lambda and trigger it periodically using AWS CloudWatch.
This end-to-end task ensures secrets are protected, infrastructure is provisioned securely, and automation is seamless. 🚀