DevOps Classroomnotes 29/Jan/2023

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
Published
Categorized as Uncategorized Tagged

By continuous learner

devops & cloud enthusiastic learner

Leave a comment

Turn on JavaScript to leave a comment.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Please turn AdBlock off
Social Network Integration by Acurax Social Media Branding Company
Exit mobile version
%%footer%%