Infrastructure as Code with Ansible CSCI GA 2820 Graduate Division Computer Science Instructor John J Rofrano Senior Technical Staff Member DevOps Champion IBM T J Watson Research Center rofrano cs nyu edu JohnRofrano 1 Infrastructure as Code What Will You Learn What is meant by Infrastructure as Code What are Con guration Management Systems Why would you use them for DevOps Difference between Agent and Agent less Solutions How to use Ansible to manage servers hands on JohnRofrano 2 Infrastructure as Code Some Assembly Required You will need to install Vagrant Tools you will need to complete the lab GitHub Account Git Client Vagrant VirtualBox or Docker Text Editor JohnRofrano 3 Infrastructure as Code Software for this Lab You will need vagrant for this lab brew install vagrant C choco install vagrant JohnRofrano 4 Infrastructure as Code Download manually https www vagrantup com downloads html Select the appropriate download for your OS JohnRofrano 5 Infrastructure as Code Start Docker before Vagrant Vagrant is using Docker so remember to start it before you use vagrant up You can also con gure Docker to start when your computer starts but if you only use it for this class there is no need Just don t forget to start Docker before class JohnRofrano 6 Infrastructure as Code Source for This Lab The source for this lab can be found on GitHub at git clone https github com nyu devops lab ansible git cd lab ansible vagrant up provider docker Note it s vagrant up not code JohnRofrano 7 AND NOW BACK TO AND NOW BACK TO OUR REGULARLY OUR REGULARLY SCHEDULED SCHEDULED PROGRAM PROGRAM JohnRofrano 8 Infrastructure as Code Managing Infrastructure as Code Common DevOps practice to manage infrastructure as code with tools using version control systems like GitHub Eliminates a lot of manual labor that required a whole team of IT engineers environments Makes it easy to scale and maintain all of the different Having replicable cloud con guration tools can easily reproduce and deploy resources automatically to scale your application and services JohnRofrano 9 Infrastructure as Code The Bespoke Build Problem Manually creating servers to deploy applications is Time consuming Error prone Inconsistent at best Unreproducible at worst JohnRofrano 10 Infrastructure as Code History of Tools that Provide Infrastructure as Code JohnRofrano 11 https diawahad medium com infrastructure as code iac mastering code automation 8ba904871b0a Infrastructure as Code Infrastructure as Code Infrastructure as code IaC is the managing and provisioning of infrastructure through code instead of using a manual process to con gure devices or systems Con guration as code is the practice of managing the con guration les in a repository Con g les established the parameters and settings for applications servers and operating systems JohnRofrano 12 Infrastructure as Code Tenets of Infrastructure as Code Describe your infrastructure in textual format and con gure them using that description Never perform system and software con gurations manually Use templates scripts describing how to install con gure systems devices software users Keep all con gurations under source control e g GitHub Con guration Management Systems make this possible JohnRofrano 13 Infrastructure as Code Imperative VS Declarative IMPERATIVE DECLARATIVE Focuses on how Explicit instructions Responsibility lies with the user Better git for small deployments Focuses on what De ne only the outcome The user focuses on the desired state Brings huge bene ts in environment that need scalability JohnRofrano 14 Infrastructure as Code Infra As Code Examples JohnRofrano 15 Infrastructure as Code Puppet Example JohnRofrano 16 Infrastructure as Code SaltStack Example JohnRofrano 17 Infrastructure as Code Chef Example JohnRofrano 18 Infrastructure as Code Ansible Example JohnRofrano 19 Infrastructure as Code Infrastructure as Code with Ansible INVENTORY FILES VAR FILES PLAYBOOKS APPLICATION SERVERS JohnRofrano 20 DATABASE SERVERS Infrastructure as Code Terraform Has providers for many platforms JohnRofrano 21 Infrastructure as Code Terraform is Declarative resource multipass instance test name iac demo cpus 2 image jammy provider multipass terraform required version 1 0 0 required providers multipass source larstobi multipass version 1 4 1 JohnRofrano 22 Describes what is needed not how to do it Infrastructure as Code Terraform Workflow Terraform con g describes desired state Terraform work ow Init initialize terraform Refresh get view of real word Plan reconcile real world with desired state Apply execute plan Destroy undo everything JohnRofrano 23 Infrastructure as Code Multipass Multipass is a free tool from Canonical that runs on macOS Windows and Linux Uses the platforms native hypervisor Only creates Ubuntu VMs Support Cloud Init for initializing VMs Designed for developers JohnRofrano 24 Infrastructure as Code Cloud init Example Cloud init file to use with multipass package update true packages git make vim zip curl wget python3 dev python3 venv python3 pip podman libgeos dev runcmd echo alias docker usr bin podman home ubuntu bashrc JohnRofrano 25 Infrastructure as Code Vagrant is Infrastructure as Code for Developers Vagrant is a developers tool for automating the creation of lightweight reproducible and portable virtual environments via command line It supports VirtualBox VMware SoftLayer Amazon AWS and Digital Ocean It supports con guration management utilities like Ansible Puppet Chef etc It supports Docker natively which makes is easy to use Docker containers in VMs JohnRofrano 26 Infrastructure as Code What is Docker Docker packages applications into Containers that include all of their dependencies but share the kernel with other containers Containers run as an isolated process in userspace on the host operating system Containers are not tied to any speci c infrastructure Docker containers run on any computer on any infrastructure and in any cloud This guarantees that it will always run the same regardless of the environment it is running in JohnRofrano 27 Infrastructure as Code VirtualBox VirtualBox is a free Hypervisor that runs on Intel macOS Windows and Linux Virtualizes CPU Memory Hard Disks CD Network Adapters etc Similar to VMware Workstation on a PC or VMware Fusions and Parallels Desktop on a Mac Allows you to run applications in a Virtual No emulation does not work on Apple M1 Machine Silicon JohnRofrano 28 Infrastructure as Code Vagrant is the Puppet
View Full Document
Unlocking...