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.
    Preview
  • 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
    Preview
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 Reply

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

Please turn AdBlock off
Social Media Icons Powered by Acurax Web Design Company

Discover more from Direct DevOps from Quality Thought

Subscribe now to keep reading and get access to the full archive.

Continue reading

Visit Us On FacebookVisit Us On LinkedinVisit Us On Youtube