Ansible Vault
ansible-vault encrypt
ansible-vault decrypt
ansible-vault create
ansible-vault view
ansible-playbook --ask-vault-password ...
Ansible in CI/CD Pipelines
-
Ansible Control Node as CI/CD Engines NOde.
-
Sample Script with Declarative Pipeline to depoy
pipeline
{
agent { label 'build' }
stages
{
stage('build and package') {
......
}
stage ('deploy') {
agent { label 'ansible' }
steps {
git '<git url for playbook>'
sh 'ansible-playbook -i hosts deploy.yaml'
}
}
}
}
- Terraform provisioning vm and calling ansible playbook

resource "aws_instance" "web" {
# ...
# Establishes connection to be used by all
# generic remote provisioners (i.e. file/remote-exec)
connection {
type = "ssh"
user = "root"
password = var.root_password
host = self.public_ip
}
file {
// copy id_rsa, id_rsa.pub authorize_key
}
provisioner "remote-exec" {
inline = [
"sudo apt update",
"sudo apt install software-properties-common",
"sudo add-apt-repository --yes --update ppa:ansible/ansible",
"sudo apt install ansible -y",
"git clone <url>",
"cd repo && ansible-playbook -i hosts deploy.yaml"
]
}
}
Exercise
- Write a playbook to run spring petclinic
- Steps:
- install java 11
- download spring petclinic from Refer Here
java -jar spring-petclinic-2.4.2.jar
- Then application will run on 8080 port