Managing Infrastructure with Python, Fabric and Ansible. By Tim Henderson hackthology.com github.com/timtadh

Similar documents
Garment Documentation

ANSIBLE BEST PRACTICES: THE ESSENTIALS Ansible Automates: DC. Jamie

Automate all the things. Sebastian Feldmann

ANSIBLE BEST PRACTICES: THE ESSENTIALS

Automating All The Things. Sebastian Feldmann

Gunnery Documentation

Inventory. PlayBook. Python. Ansible Config. Modules SSH

Pulp Python Support Documentation

coxtactoe Documentation

My network deploys. How about yours? EOS APIs. Andrei Dvornic

Technical Manual. Software Quality Analysis as a Service (SQUAAD) Team No.1. Implementers: Aleksandr Chernousov Chris Harman Supicha Phadungslip

Git & Github Fundamental by Rajesh Kumar.

Adding Transparency and Automation into the Galaxy Tool Installation Process

TangeloHub Documentation

Platform Migrator Technical Report TR

RandoPony Documentation

RDO container registry Documentation

Ansible Cookbook 2014

Aldryn Installer Documentation

DevOps Workflow. From 0 to kube in 60 min. Christian Kniep, v Technical Account Manager, Docker Inc.

Niv Mizrahi. VP github.com/nivm

Version Control: Gitting Started

This tutorial provides a basic understanding of the infrastructure and fundamental concepts of managing an infrastructure using Chef.

open-helpdesk Documentation

Hands-On Tutorial: Developing and Onboarding Services in CORD

Created by: Nicolas Melillo 4/2/2017 Elastic Beanstalk Free Tier Deployment Instructions 2017

Beginners guide to at #phpworld

withenv Documentation

Deployability. of Python. web applications

Advanced Continuous Delivery Strategies for Containerized Applications Using DC/OS

Python Project Example Documentation

bootmachine Documentation

mongodb-tornado-angular Documentation

flask-dynamo Documentation

Verteego VDS Documentation

nacelle Documentation

Game Server Manager Documentation

Step 1: Setup a Gitlab account

Overhauling Dev Arch with Ansible Tower and Docker

django-baton Documentation

Developing and Testing Java Microservices on Docker. Todd Fasullo Dir. Engineering

NetDevOps Style Configuration Management for the Network

Tissu for Fabric Documentation

ameh Documentation Release Eric Pierce

django-reinhardt Documentation

Software Development I

Automate NetScaler with Ansible

chatterbot-weather Documentation

Ansible Tower Quick Setup Guide

Graphene Documentation

Life Without DevStack: OpenStack Development With OSA. Miguel

A Sample Approach to your Project

Google Domain Shared Contacts Client Documentation

BanzaiDB Documentation

devops with

Cloud Computing II. Exercises

GETTING STARTED WITH. Michael Lessard Senior Solutions Architect June 2017

DC/OS on Google Compute Engine

" Qué me estás container?" Docker for dummies

Getting Started with the Google Cloud SDK on ThingsPro 2.0 to Publish Modbus Data and Subscribe to Cloud Services

A Cloud-based Architecture for Processing 3D Mars Terrain

kayobe Documentation OpenStack Foundation

Pulp OSTree Documentation

django-fabric Documentation

datapusher Documentation

django-baton Documentation

EnhancedEndpointTracker Documentation

apostello Documentation

CREATING A CLOUD STRONGHOLD: Strategies and Methods to Manage and Secure Your Cloud

Python Schema Generator Documentation

Splunk & Git. The joys and pitfalls of managing your Splunk deployment with Git. Copyright 2018

PyCon APAC 2014 Documentation

I hate money. Release 1.0

The Road to Digital Transformation: Increase Agility Building and Managing Cloud Infrastructure. Albert Law Solution Architect Manager

SAROS MasterNode Guide V1.1

Automation and Programmability using Cisco Open NXOS and DevOps Tools

django-telegram-bot Documentation

IoC Documentation. Release Thomas Rabaix

TPS Documentation. Release Thomas Roten

We are ready to serve Latest Testing Trends, Are you ready to learn?? New Batches Info

Who is Docker and how he can help us? Heino Talvik

Orchestrate JBoss Middleware with Ansible Tower Red Hat Summit San Francisco

puppet-diamond Documentation

Lecture 01 - Working with Linux Servers and Git

Industry-leading Application PaaS Platform

Lab 4: Configuring node.js apps with ATP

Automate your IX s RS Config

Jinkun Jang Samsung Electronics

Dell EMC Networking Saltstack Integration Documentation

GIT. A free and open source distributed version control system. User Guide. January, Department of Computer Science and Engineering

Introduction to the UNIX command line

Installing and Using Docker Toolbox for Mac OSX and Windows

I2C LCD Documentation

Bitnami MEAN for Huawei Enterprise Cloud

viki-fabric-helpers Documentation

Agenda. - Final Project Info. - All things Git. - Make sure to come to lab for Python next week

Python simple arp table reader Documentation

cfgmgmt for cfgmgmt fosdem 2019

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. Gerrit

Source Control. Deployment. What usync Does. usync Versions

Transcription:

Managing Infrastructure with Python, Fabric and Ansible By Tim Henderson tadh@case.edu hackthology.com github.com/timtadh

part 00

death of a sys-admin

there are too many machines

now, we have become root

the world is changing

operations are a programming problem

A programmer's delight? Server management should be: 1. Simple 2. Well documented 3. Repeatable 4. Testable 5. Auditable

part 01

- step 0: - desc: never type commands on a server reasons: - hard to keep servers in sync - hard to audit - hard to know server state - step 1: - desc: use a tool reasons: - easy to review changes - server state is known - step 2: - desc: standardize all processes reason: no special servers

definitions your servers you your programs

definitions you

a single service database tier web tier app tier

your app db web app db web app db web app

we provision individual network services onto individual servers. db web app db web app db web app

but we also need to be able to control whole logical services and connect them together db web app db web app db web app

lifecycle of a network service Bootstrap Provision Configure Deploy Migrate?

part 10

Enough Philosophizing SHOW ME THE CODE

fabric $ mkdir ops-example && cd ops-example $ virtualenv --no-site-packages env $ source./env/bin/activate && pip install fabric $ cat >fabfile.py <<EOF from fabric import api > > > > def who(): api.run('echo $(whoami) on $(uname -s)') > > EOF $ fab -H localhost who [localhost] Executing task 'who' [localhost] run: echo $(whoami) on $(uname -s) [localhost] out: hendersont on Linux [localhost] out: Done. Disconnecting from localhost... done.

provision - config - deploy from fabric import api def provision(): api.sudo( apt-get install python python-dev python-pip ) api.sudo( pip install virtualenv ) api.run( git clone git@host:group/app ) api.run( virtualenv --no-site-packages app/env ) def config(): api.put( startup.sh, startup.sh ) api.sudo( mv startup.sh /etc/init.d/app ) api.put( app-config.ini, app/config.ini ) def deploy(): api.run( git -C app/ pull ) api.run( source app/env/bin/activate && pip install -U -r requirements ) api.sudo( service app restart )

simple, but brittle

enter ansible, a higher level tool

ansible $ mkdir ops-example && cd ops-example $ virtualenv --no-site-packages env $ source./env/bin/activate && pip install ansible $ cat >HOSTS <<EOF > yourhost > EOF $ ansible all -i HOSTS -m shell \ > -a 'echo $(whoami) on $(uname -s)' yourhost SUCCESS rc=0 >> hendersont on Linux $ cat >playbook.yml <<EOF > - hosts: all > tasks: > - shell: echo $(whoami) on $(uname -s) > EOF

ansible $ cat >playbook.yml <<EOF - hosts: all tasks: > > > - shell: echo $(whoami) on $(uname -s) > EOF $ ansible-playbook -v -i HOSTS playbook.yml PLAY [all] TASK [setup] ************************************************************ ok: [yourhost] TASK [command] ************************************************************ changed: [yourhost] => {"changed": true, "stdout_lines": ["hendersont on Linux"]} PLAY RECAP ************************************************************ yourhost : ok=2 changed=1 unreachable=0 failed=0

so far just a complicated ssh

modules, roles, and templates make ansible worthwhile

a motivating module: git $ cat >gitplay.yml <<EOF > - hosts: all > tasks: > - name: update code for app repo > git: > repo: https://host.com/group/app.git > dest: /opt/app/ > accept_hostkey: True > force: yes > update: yes > version: stable-branch > EOF $ ansible-playbook -i HOSTS gitplay.yml... TASK [command] ************************************************************ changed: [yourhost] => {"after": "9c46a49a73103de9a929718c223326149cb9accd", "before": null, "changed": true}...

roles add structure to your code $ tree -L 3.. HOSTS playbook.yml roles base files/ handlers/ tasks/ go tasks/ templates/ hadoop:base files/ handlers/ tasks/ templates/ vars/ hdfs:datanode meta/ tasks/ templates/ vars/ hdfs:namenode handlers/ meta/ tasks/ templates/ vars/

roles are directories, with a specified structure $ tree roles/hdfs:namenode/ roles/hdfs:namenode/ handlers main.yml meta main.yml tasks config.yml main.yml provision.yml templates hdfs-namenode.conf hdfs-nfs.conf hdfs-portmap.conf vars main.yml

tasks/main.yml is the execution entry point $ cat roles/hdfs:namenode/tasks/main.yml - include: "{{mode}}.yml"

the mode variable is set in the calling playbook $ cat roles/hdfs:namenode/tasks/main.yml - include: "{{mode}}.yml" $ cat provision.yml - hosts: hdfs_namenodes user: admin vars: mode: provision roles: - role: hdfs:namenode tags: - hdfs - hdfs:namenode

which causes main.yml to load the correct tasks $ cat roles/hdfs:namenode/tasks/main.yml - include: "{{mode}}.yml" $ cat provision.yml - hosts: hdfs_namenodes user: admin vars: mode: provision roles: - role: hdfs:namenode tags: - hdfs - hdfs:namenode $ tree roles/hdfs:namenode/ roles/hdfs:namenode/ handlers main.yml meta main.yml tasks config.yml main.yml provision.yml templates hdfs-namenode.conf hdfs-nfs.conf hdfs-portmap.conf vars main.yml

implementing lifecycle phases at the service level $ cat roles/hdfs:namenode/tasks/main.yml - include: "{{mode}}.yml" $ cat provision.yml - hosts: hdfs_namenodes user: admin vars: mode: provision roles: - role: hdfs:namenode tags: - hdfs - hdfs:namenode $ tree roles/hdfs:namenode/ roles/hdfs:namenode/ handlers main.yml meta main.yml tasks config.yml main.yml provision.yml templates hdfs-namenode.conf hdfs-nfs.conf hdfs-portmap.conf vars main.yml

5 top level playbooks are used to run tasks $ ls *.yml bootstrap.yml provision.yml config.yml deploy.yml migrate.yml $ ansible-playbook -i HOSTS lifecycle.yml PLAY [hdfs_namenodes] ********************************************* TASK [setup] ********************************************* ok: [host]... Bootstrap Provision Configure Deploy Migrate?

each playbook lifecycle calls the appropriate roles $ cat config.yml - hosts: hdfs_namenodes user: admin vars: mode: config roles: - role: hdfs:namenode tags: - hdfs - hdfs:namenode - hosts: zookeeper user: admin vars: mode: config user: admin roles: - role: zookeeper tags: - zookeeper

templates enable shared configuration between files $ cat roles/hadoop\:base/templates/core-site.xml <?xml version="1.0" encoding="utf-8"?> <?xml-stylesheet type="text/xsl" href="configuration.xsl"?> <configuration> <property> <name>fs.defaultfs</name> <value> hdfs://{{hostvars[groups['hdfs_namenodes'][0]] ['ansible_fqdn']}}:{{hdfs_namenode_port}} </value> </property> <property> <name>io.file.buffer.size</name> <value>131072</value> </property>... </configuration>

let s stop here

takeaways High level 1. Devs increasingly are increasingly performing operational roles 2. Ops folk are increasingly performing developer roles 3. Operations now looks more like programming than before Practical 1. Don t run commands on servers 2. Use a tool 3. Follow a standardized process for everything

resources https://docs.ansible.com/ https://docs.ansible. com/ansible/playbooks_best_practices.html https://github.com/ansible/ansible-examples http://docs.fabfile.org/ http://docs.fabfile.org/en/1.12/tutorial.html https://www.vagrantup.com/ https://www.docker.com/