Top Banner
DevOps Lecture 4 Automation 6 Oct 2021 Chinmaya Dehury [email protected] LTAT.06.015 : Lec-04 : Automation 1
46

DevOps Lecture 4 Automation

Feb 25, 2022

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: DevOps Lecture 4 Automation

DevOps – Lecture 4

Automation6 Oct 2021

Chinmaya Dehury

[email protected]

LTAT.06.015 : Lec-04 : Automation 1

Page 2: DevOps Lecture 4 Automation

OUTLINE

LTAT.06.015 : Lec-04 : Automation 2

A quick Recap…

Automation

What can be automated in

your business?

Key featureswhy

automation?Benefits

Automation in DevOps

Build Automation

Test Automation

Deployment Automation

Infrastructure Automation

Automation in Resource provisioning

Infrastructure as Code (IaC)

IaC & Scripts BenefitsDeclarative

vs ImperativeTools

AnsibleAutomation tool

Basic architecture

Inventories tasks modules collections Playbooks Roles

Page 3: DevOps Lecture 4 Automation

Recap

LTAT.06.015 : Lec-04 : Automation 3

Virtualization Hypervisor Hypervisor typesLevel/Cons of virtualization

Containerization Intro + benefitsNamespace +

Cgroup

Containerization platform - Docker

Architecture ComponentsStorage

managementContainer

orchestration

Containers clustering -Kubernetes

Components (Master+worker)

Building blocks Workflows

LAB -03: Kubernetes Management Platform

- Rancher

Page 4: DevOps Lecture 4 Automation

Automation

…performs tasks with reduced human assistance

LTAT.06.015 : Lec-04 : Automation 4https://www.redhat.com/en/topics/automation/what-is-devops-automation

Page 5: DevOps Lecture 4 Automation

What can be automated in your business?

• IT automation

• business automation

• robotic process automation

• industrial automation

• machine learning• Adaptive algorithms that use predictive models to perform tasks without explicit

instructions

• E.g. predictive maintenances

• deep learning• Automatically detect repetitive manual tasks and later automate them

• Etc….

LTAT.06.015 : Lec-04 : Automation 5

https://www.redhat.com/en/topics/automation

Page 6: DevOps Lecture 4 Automation

Key features of automation technologies

• Unified automation platforms• promote consistency and let you standardize automated processes and content

across development, test, and production environments.

• Easy, straightforward operations• allow more team members to participate and contribute.

• Overall simplicity• promotes greater adoption of automation throughout your organization.

• Integration with other tools and products • allow you to more easily automate a broader range of tasks and components.

• Platform scalability • allows you to simply expand the capacity of your pipeline as adoption grows.

LTAT.06.015 : Lec-04 : Automation 6

Page 7: DevOps Lecture 4 Automation

…but why automation?

• Blue Cross and Blue Shield of North Carolina saved*• > US$850,000

• 70,000 work hours.

• by automating VM provisioning

• executed 200,000 Ansible Playbooks

• The City of Denver, without Ansible Automation Platform• 20 minutes to create an individual Microsoft Teams environment

• Less than a min with automation platform

LTAT.06.015 : Lec-04 : Automation 7

* https://www.redhat.com/en/resources/bcbsnc-case-study

Page 8: DevOps Lecture 4 Automation

…but why automation? - Benefits

• Consistency• Consistent infra for both dev and ops teams

• Scalability

• Speed

• Flexibility

• Standardization • Both dev and ops team will follow the same standard toolstack

LTAT.06.015 : Lec-04 : Automation 8

* https://www.redhat.com/en/resources/bcbsnc-case-study

Page 9: DevOps Lecture 4 Automation

Automation in DevOps

…use of technology to perform tasks with reduced human assistance [src].

helps you

• accelerate processes

• scale environments

• build continuous integration

• Continuous Testing

• build continuous delivery

• build continuous deployment (CI/CD) workflows

LTAT.06.015 : Lec-04 : Automation 9

Src: https://www.redhat.com/en/topics/automation/what-is-devops-automation

Page 10: DevOps Lecture 4 Automation

Build Automation in DevOps

• Automatic source code retrieval

• Source code compilation into binary

• Packaging compiled files (maybe into a compressed one)

Key metrics

• Average build time

• Frequency of builds

• Success rate• x% success/failed

LTAT.06.015 : Lec-04 : Automation 10

Src: https://www.redhat.com/en/topics/automation/what-is-devops-automation

Page 11: DevOps Lecture 4 Automation

Test Automation in DevOps• Unit tests -> code analytics

• Integration tests

• System tests

• Installation test

• User experience tests

• UI tests

Key metrics

• Test execution time

• Test code coverage

• Code coverage criteria• Function coverage – has each function in the program been called?• Statement coverage – has each statement in the program been

executed?• Edge coverage – has every edge in the control-flow graph been

executed?• Branch coverage - e.g. if and case statements• Condition coverage – e.g. true – false condition

LTAT.06.015 : Lec-04 : Automation 11Src: https://www.redhat.com/en/topics/automation/what-is-devops-automation

Page 12: DevOps Lecture 4 Automation

Deployment Automation in DevOps

• Model the environment

• Deploy the application • Orchestration of the workflow

Key metrics

• % of failed/success deployments

• Avg. deployment time

• Deployment frequency

• Environment provisioning time

LTAT.06.015 : Lec-04 : Automation 12

Src: https://www.redhat.com/en/topics/automation/what-is-devops-automation

Page 13: DevOps Lecture 4 Automation

Infrastructure Automation in DevOps

• Create the required infrastructure• For development environment

• For testing environment

• For production environment

Key metrics

• Environment provisioning time

• Average deployment time

• Resource configuration

• Frequency of environment provisioning

LTAT.06.015 : Lec-04 : Automation 13

Src: https://www.redhat.com/en/topics/automation/what-is-devops-automation

Page 14: DevOps Lecture 4 Automation

Automation in Resource provisioning • What to provision? What does resource mean here?

• Server :• Provision the servers

• Set up the physical servers• Install the necessary system software

• configure the servers• Make it ready to access over network

• Network

• Service • Service set up • Data management• User management

• User• Create user• Assign to group(s)• Assign roles (viewer, commenter, editor, administrator, owner, etc.)• Assign permissions

LTAT.06.015 : Lec-04 : Automation 14

Page 15: DevOps Lecture 4 Automation

Infrastructure as Code (IaC)

• No manual work to provision the infrastructure:• Create VM

• Prepare specific OS image

• Create specific network interface

• Create storage server

• Manually assigning computing resource to each VM

• E.g. setting up 1000 VMs for an application deployment may need more than 15 weeks and >10 dedicated staffs

• IaC:• No more manual work

• Write a code ->• Provision the required infrastructure and configure

LTAT.06.015 : Lec-04 : Automation 15

Page 16: DevOps Lecture 4 Automation

Infrastructure as Code (IaC) – Examples

• No manual work to provision the infrastructure:• Create VM

• Prepare specific OS image

• Create specific network interface

• Create storage server

• Manually assigning computing resource to each VM

• E.g. setting up 1000 VMs for an application deployment may need more than 15 weeks and >10 dedicated staffs

• IaC:• No more manual work

• Write a code ->• Provision the required infrastructure and configure

LTAT.06.015 : Lec-04 : Automation 16

Page 17: DevOps Lecture 4 Automation

IaC & Scripts

• Scripts • Not suitable for large scale system

• Hard to keep track of

• Hard to maintain

• Used to automate a static step

• Not flexible

• IaC• It is also a script-like environment -> high-level scripting

• Provides versatility of code

• More human readable

• Platform-agnostic

LTAT.06.015 : Lec-04 : Automation 17

Page 18: DevOps Lecture 4 Automation

Infrastructure as Code (IaC) – Benefits

• Cost reduction

• Increase in speed of deployments

• Reduce errors -> risk

• Infrastructure/configuration consistency• Development and Operation teams are aligned

• Reduced management overhead

LTAT.06.015 : Lec-04 : Automation 18

Page 19: DevOps Lecture 4 Automation

IaC :Declarative vs Imperative

Declarative approach

• Defines the desired state of the system

• Keeps a list of the current state of system objects

LTAT.06.015 : Lec-04 : Automation 20

Imperative approach

• Defines the specific commands needed to achieve the desired configuration

• Order of execution of those commands

2 ways to approach IaC—declarative or imperative

Page 20: DevOps Lecture 4 Automation

Infrastructure as Code (IaC) – Tools

• Ansible

• Puppet

• Chef

• Terraform

• SaltStack

• AWS CloudFormation

• Azure Resource Manager

• Google Cloud Deployment Manager

LTAT.06.015 : Lec-04 : Automation 21

Page 21: DevOps Lecture 4 Automation

Infrastructure as Code (IaC) – Tools

• Ansible

• Puppet

• Chef

• Terraform

• SaltStack

• AWS CloudFormation

• Azure Resource Manager

• Google Cloud Deployment Manager

LTAT.06.015 : Lec-04 : Automation 22

Page 22: DevOps Lecture 4 Automation

Ansible Automation tool• An open source infrastructure automation tool

• A configuration management tool

• Gives the ability to control and configure multiple servers from one single location• Avoid doing repeated tasks manually• E.g. Setting up the database server, web server, etc

• Agentless• Require only ssh access

• Over 1,300 modules

• Easy to learn• Because of so high level descriptive languages (using YAML)

• Founded in 2013

• Bought by Red Hat in 2015.

• Alternatives:• Puppet• Chef• Salt

LTAT.06.015 : Lec-04 : Automation 23

Page 23: DevOps Lecture 4 Automation

Why Ansible?

• Agentless• Target system requires only sshd and python

• No daemons or agents to install

• Security• Relies on ssh

• Easy to get started, compared to the others!• Human readable, YAML format

LTAT.06.015 : Lec-04 : Automation 24

https://searchitoperations.techtarget.com/feature/Ansible-vs-Chef-vs-Puppet-vs-SaltStack-A-comparison

Page 24: DevOps Lecture 4 Automation

Basic Ansible Architecture

LTAT.06.015 : Lec-04 : Automation 25

VM1Master Node

Installed Ansible

VM2

VM3

ssh

Control nodeManaged nodes

Page 25: DevOps Lecture 4 Automation

Ansible Inventories

LTAT.06.015 : Lec-04 : Automation 26

VM1Master Node

Installed Ansible

VM2

VM3

ssh

Inventory

Page 26: DevOps Lecture 4 Automation

Ansible Inventories

LTAT.06.015 : Lec-04 : Automation 27

VM1Master Node

Installed Ansible

VM2

VM3

ssh

Inventory 1

VM4

VM5

Inventory 2

Inve

nto

ry 3

Page 27: DevOps Lecture 4 Automation

Ansible Inventories

LTAT.06.015 : Lec-04 : Automation 28

VM1Master Node

Installed Ansible

Server1

Server2

ssh

Web-servers

Server3

Server4

Offsite

Bac

kup

-se

rve

rs

Sample Inventory file (ini format)

Page 28: DevOps Lecture 4 Automation

Ansible Inventories

LTAT.06.015 : Lec-04 : Automation 29

VM1Master Node

Installed Ansible

Server1

Server2

ssh

Web-servers

Server3

Server4

Offsite

Bac

kup

-se

rve

rs

The default inventory/host file is in /etc/ansible/hosts

Page 29: DevOps Lecture 4 Automation

Ansible tasks

LTAT.06.015 : Lec-04 : Automation 30

VM1Master Node

Installed Ansible

Server1

Server2

ssh

Web-servers

Server3

Server4

Offsite

Bac

kup

-se

rve

rs

Now, You want to test if all the servers are accessible from VM1

ping

ping

ping

ping

Page 30: DevOps Lecture 4 Automation

Ansible tasks

LTAT.06.015 : Lec-04 : Automation 31

VM1Master Node

Installed Ansible

Server1

Server2

ssh

Web-servers

Server3

Server4

Offsite

Bac

kup

-se

rve

rs

Now, You want to test if all the servers are accessible from VM1

ping

ping

Page 31: DevOps Lecture 4 Automation

Ansible tasks

LTAT.06.015 : Lec-04 : Automation 32

VM1Master Node

Installed Ansible

Server1

Server2

ssh

Web-servers

Server3

Server4

Offsite

Bac

kup

-se

rve

rs

Now, You want to test if all the servers are accessible from VM1

ping

ping

Host-group

Page 32: DevOps Lecture 4 Automation

Ansible modules

LTAT.06.015 : Lec-04 : Automation 33

VM1Master Node

Installed Ansible

Server1

Server2

ssh

Web-servers

Server3

Server4

Offsite

Bac

kup

-se

rve

rs

Now, You want to test if all the servers are accessible from VM1

ping

ping

Module name

Page 33: DevOps Lecture 4 Automation

Ansible modules - Example

LTAT.06.015 : Lec-04 : Automation 34

VM1Master Node

Installed Ansible

Server1

Server2

ssh

Web-servers

Server3

Server4

Offsite

Bac

kup

-se

rve

rs

Page 34: DevOps Lecture 4 Automation

Ansible modules

• The units of code Ansible executes.

• Each module has a particular use.

• You can invoke• a single module with a task.

• several different modules in a playbook

• modules are grouped in collections

LTAT.06.015 : Lec-04 : Automation 35

Page 35: DevOps Lecture 4 Automation

Ansible modules

• The units of code Ansible executes.

• Each module has a particular use.

• You can invoke• a single module with a task.

• several different modules in a playbook

• modules are grouped in collections

LTAT.06.015 : Lec-04 : Automation 36

amazon.awsansible.builtinansible.netcommonansible.posixansible.utilsansible.windowsarista.eosawx.awxazure.azcollectioncheck_point.mgmtchocolatey.chocolateycisco.acicisco.asacisco.intersightcisco.ioscisco.iosxrcisco.merakicisco.msocisco.nsocisco.nxoscisco.ucscloudscale_ch.cloudcommunity.awscommunity.azurecommunity.cryptocommunity.digitaloceancommunity.dockercommunity.fortioscommunity.generalcommunity.googlecommunity.grafana

ibm.qradarinfinidat.infiniboxinspur.smjunipernetworks.junoskubernetes.coremellanox.onyxnetapp.awsnetapp.azurenetapp.cloudmanagernetapp.elementswnetapp.ontapnetapp.um_infonetapp_eseries.santricitynetbox.netboxngine_io.cloudstackngine_io.exoscalengine_io.vultropenstack.cloudopenvswitch.openvswitchovirt.ovirtpurestorage.flasharraypurestorage.flashbladesensu.sensu_goservicenow.servicenowsplunk.est_systems_mms.icinga_directortheforeman.foremanvyos.vyoswti.remote

community.hashi_vaultcommunity.hrobotcommunity.kubernetescommunity.kubevirtcommunity.libvirtcommunity.mongodbcommunity.mysqlcommunity.networkcommunity.okdcommunity.postgresqlcommunity.proxysqlcommunity.rabbitmqcommunity.routeroscommunity.skydivecommunity.sopscommunity.vmwarecommunity.windowscommunity.zabbixcontainers.podmancyberark.conjurcyberark.pasdellemc.enterprise_sonicdellemc.openmanagedellemc.os10dellemc.os6dellemc.os9f5networks.f5_modulesfortinet.fortimanagerfortinet.fortiosfrr.frrgluster.glustergoogle.cloudhetzner.hcloudhpe.nimble

The List of collections

Page 36: DevOps Lecture 4 Automation

Ansible collections• Ansible.Builtin is a collections

LTAT.06.015 : Lec-04 : Automation 37

add_host – Add a host (and alternatively a group) to the ansible-playbook in-memory inventoryapt – Manages apt-packagesapt_key – Add or remove an apt keyapt_repository – Add and remove APT repositoriesassemble – Assemble configuration files from fragmentsassert – Asserts given expressions are trueasync_status – Obtain status of asynchronous taskblockinfile – Insert/update/remove a text block surrounded by marker linescommand – Execute commands on targetscopy – Copy files to remote locationscron – Manage cron.d and crontab entriesdebconf – Configure a .deb packagedebug – Print statements during executiondnf – Manages packages with the dnf package managerdpkg_selections – Dpkg package selection selectionsexpect – Executes a command and responds to promptsfail – Fail with custom messagefetch – Fetch files from remote nodesfile – Manage files and file propertiesfind – Return a list of files based on specific criteriagather_facts – Gathers facts about remote hostsget_url – Downloads files from HTTP, HTTPS, or FTP to nodegetent – A wrapper to the unix getent utilitygit – Deploy software (or files) from git checkoutsgroup – Add or remove groupsgroup_by – Create Ansible groups based on factshostname – Manage hostnameimport_playbook – Import a playbookimport_role – Import a role into a playimport_tasks – Import a task listinclude – Include a play or task listinclude_role – Load and execute a roleinclude_tasks – Dynamically include a task listinclude_vars – Load variables from files, dynamically within a taskiptables – Modify iptables rules

known_hosts – Add or remove a host from the known_hosts filelineinfile – Manage lines in text filesmeta – Execute Ansible ‘actions’package – Generic OS package managerpackage_facts – Package information as factspause – Pause playbook executionping – Try to connect to host, verify a usable python and return pong on successpip – Manages Python library dependenciesraw – Executes a low-down and dirty commandreboot – Reboot a machinereplace – Replace all instances of a particular string in a file using a back-referenced regular expressionrpm_key – Adds or removes a gpg key from the rpm dbscript – Runs a local script on a remote node after transferring itservice – Manage servicesservice_facts – Return service state information as fact dataset_fact – Set host variable(s) and fact(s).set_stats – Define and display stats for the current ansible runsetup – Gathers facts about remote hostsshell – Execute shell commands on targetsslurp – Slurps a file from remote nodesstat – Retrieve file or file system statussubversion – Deploys a subversion repositorysystemd – Manage systemd unitssysvinit – Manage SysV services.tempfile – Creates temporary files and directoriestemplate – Template a file out to a target hostunarchive – Unpacks an archive after (optionally) copying it from the local machineuri – Interacts with webservicesuser – Manage user accountsvalidate_argument_spec – Validate role argument specs.wait_for – Waits for a condition before continuingwait_for_connection – Waits until remote system is reachable/usableyum – Manages packages with the yum package manageryum_repository – Add or remove YUM repositories

The List of modules in Ansible.Builtin colleciton

Page 37: DevOps Lecture 4 Automation

Ansible collections• Ansible.Builtin collections -> ansible.builtin.file is a module

LTAT.06.015 : Lec-04 : Automation 38

• Change file ownership, group and permissions• Give insecure permissions to an existing file• Create a symbolic link• Touch a file• Create a directory if it does not exist• Remove file (delete file)• Recursively remove directory

Some functionalities of file module

Page 38: DevOps Lecture 4 Automation

Ansible Playbooks• Ordered lists of tasks, saved so you can run those tasks in that order

repeatedly.

• Include variables as well as tasks

• Written in YAML and are easy to read, write, share and understand.

LTAT.06.015 : Lec-04 : Automation 39https://docs.ansible.com/ansible/latest/user_guide/playbooks_intro.html#about-playbooks

Page 39: DevOps Lecture 4 Automation

Ansible Playbooks – an Example

LTAT.06.015 : Lec-04 : Automation 40

Playbook1.yaml

First play

Second play

https://docs.ansible.com/ansible/latest/user_guide/playbooks_intro.html#about-playbooks

Execute the playbook:

Page 40: DevOps Lecture 4 Automation

Ansible Playbooks

• Ansible executes • each task in order

• with specific arguments.

• one at a time• against all machines matched by the host pattern.

• By Default: • When a task has executed on all target machines,

Ansible moves on to the next task• Ansible runs in parallel against all the hosts in the

pattern you set in the hosts: field of each play

• Instead of all, you can manage only a few machines at a time.

• The order of execution can also be changed

LTAT.06.015 : Lec-04 : Automation 41https://docs.ansible.com/ansible/latest/user_guide/playbooks_intro.html#about-playbooks

https://docs.ansible.com/ansible/latest/user_guide/playbooks_strategies.html#playbooks-strategies

Page 41: DevOps Lecture 4 Automation

Ansible Roles

• A way of organizing tasks and related files to be later called in a playbook.

• Roles are a collection of tasks, • moved from one playbook to another,

• can be run independently but only through a playbook file.

• Roles can be considered as something similar to libraries

LTAT.06.015 : Lec-04 : Automation 42

Page 42: DevOps Lecture 4 Automation

Ansible Roles – An example• A way of organizing tasks and related files to be later called in a playbook.

• Roles are a collection of tasks, • moved from one playbook to another, • can be run independently but only through a playbook file.

• Roles can be considered as something similar to libraries

LTAT.06.015 : Lec-04 : Automation 43

Page 43: DevOps Lecture 4 Automation

Summary

LTAT.06.015 : Lec-04 : Automation 44

Automation

What can be automated in

your business?

Key featureswhy

automation?Benefits

Automation in DevOps

Build Automation

Test Automation

Deployment Automation

Infrastructure Automation

Automation in Resource provisioning

Infrastructure as Code (IaC)

IaC & Scripts BenefitsDeclarative

vs ImperativeTools

AnsibleAutomation tool

Basic architecture

Inventories tasks modules collections Playbooks Roles

Page 44: DevOps Lecture 4 Automation

Lab Sessions

• Installation and basic configuration of Ansible v2.9.

• Basic Ansible commands

• Working with Ansible Playbook

• Install Docker

• Creating a K8 cluster using Ansible

• Deploy your service on k8 cluster

LTAT.06.015 : Lec-04 : Automation 45

Page 45: DevOps Lecture 4 Automation

References

• https://nsrc.org/workshops/2013/nsrc-ubuntunet-trainers/raw-attachment/wiki/Agenda/intro-ansible.pdf

• https://www.redhat.com/en

• https://docs.ansible.com/ansible/latest/user_guide/playbooks_strategies.html#playbooks-strategies

• https://docs.ansible.com/ansible/latest/user_guide/playbooks_intro.html#about-playbooks

• https://searchitoperations.techtarget.com/feature/Ansible-vs-Chef-vs-Puppet-vs-SaltStack-A-comparison

• https://www.redhat.com/en/topics/automation/what-is-devops-automation

• https://www.redhat.com/en/resources/bcbsnc-case-study

• https://www.redhat.com/en/topics/automation

LTAT.06.015 : Lec-04 : Automation 46

Page 46: DevOps Lecture 4 Automation

Any Question ?

47