Slide 1

Slide 1 text

Fabric: Deploy with Python Rick Copeland CTO, Synapp.io @rick446

Slide 2

Slide 2 text

What is Fabric? • Library and command-line tool • Streamlines SSH • Use for deployment and sysadmin tasks

Slide 3

Slide 3 text

Why is Fabric?

Slide 4

Slide 4 text

Set up a playground (virtualenv) (master %) rick446@Elrond: ~/src/fabric-demo! $ virtualenv env-fabric! New python executable in env-fabric/bin/python2.7! Also creating executable in env-fabric/bin/python! Installing Setuptools................................................................................ .......................................................................................... ....................................................done.! Installing Pip....................................................................................... .......................................................................................... .......................................................................................... ..........................................................done.! (master %) rick446@Elrond: ~/src/fabric-demo! $ source env-fabric/bin/activate! (env-fabric)(master %) rick446@Elrond: ~/src/fabric-demo! $ pip install fabric! ... lots of stuff ...! Successfully installed fabric paramiko pycrypto ecdsa! Cleaning up...! (env-fabric)(master %) rick446@Elrond: ~/src/fabric-demo! $

Slide 5

Slide 5 text

Hello, Fabric # fab-hello.py! ! def hello():! print 'Hello, Fabric!' (env-fabric)(master %) rick446@Elrond: ~/src/fabric-demo! $ fab -f fab-hello.py -l! Available commands:! ! hello! (env-fabric)(master %) rick446@Elrond: ~/src/fabric-demo! $ fab -f fab-hello.py hello! Hello, Fabric!! ! Done.

Slide 6

Slide 6 text

Command-line Fabric # fab-arguments.py! ! def hello():! print 'Hello, Fabric!'! ! def greet(name):! print 'Hello, {}!'.format(name)! ! def args_n_kwargs(*args, **kwargs):! print 'args: {}'.format(args)! print 'kwargs: {}'.format(kwargs)

Slide 7

Slide 7 text

[1]

Slide 8

Slide 8 text

What about • ssh? • deployment? • sysadmin? ! • For that, we need a bigger playground….

Slide 9

Slide 9 text

What is Vagrant • Bunch of Ruby scripts that help you manage virtual machines (by default, the free VirtualBox) • [See January’s excellent talk by Daniel Rocco for more details.] • We’ll use it as a deployment playground

Slide 10

Slide 10 text

Build the Playground • Prerequisite: Install Virtualbox and Vagrant • https://www.virtualbox.org/ • http://www.vagrantup.com/ (master) rick446@Elrond: ~/src/fabric-demo! $ vagrant box add saucy64 https://cloud-images.ubuntu.com/vagrant/saucy/current/saucy-server-cloudimg- amd64-vagrant-disk1.box! Downloading or copying the box...! Extracting box...te: 3973k/s, Estimated time remaining: --:--:--)! Successfully added box 'saucy64' with provider ‘virtualbox'!! ! (master) rick446@Elrond: ~/src/fabric-demo! $ vagrant init saucy64! A `Vagrantfile` has been placed in this directory. You are now! ready to `vagrant up` your first virtual environment! Please read! the comments in the Vagrantfile as well as documentation on! `vagrantup.com` for more information on using Vagrant.! ! (env-fabric)(master %) rick446@Elrond: ~/src/fabric-demo! $ vagrant plugin install vagrant-vbguest! ! (master) rick446@Elrond: ~/src/fabric-demo! $ vagrant up! …! [default] Mounting shared folders...! [default] -- /vagrant

Slide 11

Slide 11 text

Something simple (env-fabric)(master %) rick446@Elrond: ~/src/fabric-demo! $ vagrant ssh-config > vagrant-ssh-config! (env-fabric)(master %) rick446@Elrond: ~/src/fabric-demo! $ fab --ssh-config vagrant-ssh-config --set use_ssh_config=True -H default host_type! [default] Executing task 'host_type'! [default] run: uname -s! [default] out: Linux! [default] out:! ! ! Done.! Disconnecting from [email protected]:2222... done. # fabfile.py! ! from fabric import api! ! def host_type():! api.run('uname -s')

Slide 12

Slide 12 text

$ fab --ssh-config vagrant-ssh-config --set use_ssh_config=True -H default host_type ?! ! This is SIMPLE?!

Slide 13

Slide 13 text

What is Fabtools? • Useful functions to help you write your Fabric files. • Make it easier to manage system users, packages, databases, etc. • Low-level actions, as well as a higher level interface called fabtools.require. • fabtools.require allows a more declarative style, similar to Chef or Puppet. • Lots of cool stuff, but let’s start with fabtools.vagrant…

Slide 14

Slide 14 text

–Rick Copeland “I’m tired of making slides now.” https://github.com/rick446/fabric-demo

Slide 15

Slide 15 text

What else can you do? • Target multiple hosts (host lists or roles) “webservers” • Parallel mode • Compound tasks • Set host list • Execute sub-tasks in parallel

Slide 16

Slide 16 text

We are Hiring!

Slide 17

Slide 17 text

Image credits • [1] - http://upload.wikimedia.org/wikipedia/ commons/7/7d/ Barack_Obama_with_artistic_gymnastic_McKayl a_Maroney_2.jpg • [2] - http://pixabay.com/p-91536/?no_redirect