ruby, the language of devops

68
Ruby The Language of Devops

Upload: rob-kinyon

Post on 10-Apr-2017

2.632 views

Category:

Software


0 download

TRANSCRIPT

Page 1: Ruby, the language of devops

RubyThe Language of Devops

Page 2: Ruby, the language of devops

Who am I?● Rob Kinyon

o @rkinyono [email protected]

● Devops lead for many years

Page 3: Ruby, the language of devops

What is Devops?● The Cloud?● Jenkins Automation?● Continuous integration & deployment?● A new title?

o with no extra pay . . .● Developers doing Operations??

o And fire all the sysadmins? (NO-OPS!)● Automating away your coworkers??!

Page 4: Ruby, the language of devops

TheProgramming

of Operations

Page 5: Ruby, the language of devops

The Programming of Operations● Operations is:

o Build serverso Packagingo Monitoringo Provisioningo Virtualizationo Environment/Stack Managemento Many many many more things

Page 6: Ruby, the language of devops

The Programming of Operations

Page 7: Ruby, the language of devops

The Programming of Operations● Lots of helpers

o Build thiso Package thato Move things from here to there

Page 8: Ruby, the language of devops

The Programming of Operations● Lots of helpers

o Build thiso Package thato Move things from here to there

● Templatingo Homegrown templates for Nagios

Page 9: Ruby, the language of devops

The Programming of Operations● Lots of helpers

o Build thiso Package thato Move things from here to there

● Templatingo Homegrown templates for Nagios

● Lots of manual activities

Page 10: Ruby, the language of devops

The Programming of Operations

Manual===

Broken

Page 11: Ruby, the language of devops

TARGET=${1:-"monitor-prod"}for rule in /nagios/rules/*.tmpl; do process_template.pl $rule $TARGET mv ${rule##tmpl#cfg} /nagios/finaldone

scp /nagios/final/*.cfg $TARGET.company.com:/var/nagios/ssh $TARGET.company.com -c "sudo service nagios3 restart”

The Programming of Operations

Page 12: Ruby, the language of devops

The Programming of Operations● As a single script, it's okay.

o Concise, clear - what else do you need?

Page 13: Ruby, the language of devops

The Programming of Operations● As a single script, it's okay.

o Concise, clear - what else do you need?● Problems:

o No tests (untestable!)o No reusability or extensibilityo Inscrutable code

Page 14: Ruby, the language of devops

The Programming of Operations● As a single script, it's okay.

o Concise, clear - what else do you need?● Problems:

o No tests (untestable!)o No reusability or extensibilityo Inscrutable code

● Bugs:o Assumes the contents of $PWD and $PATHo Assumes a human will know if it worked

Page 15: Ruby, the language of devops

The Programming of Operations● Operations staff are not developers

Page 16: Ruby, the language of devops

The Programming of Operations● Operations staff are not developers● Operational focus is about

maintenanceo Keep it ono Keep it upo Keep it responding

Page 17: Ruby, the language of devops

The Programming of Operations

Page 18: Ruby, the language of devops

The Programming of Operations● Operations staff are not developers● Operational focus is about

maintenanceo Keep it ono Keep it upo Keep it responding

● Operations has to manage changes by those pesky developerso Right now. While something is on fire.

(Really!)

Page 19: Ruby, the language of devops

The Programming of OperationsWhat is the perfect language?

● Multi-system● Quick to boot● Easy to learn● Easy to maintain● Large community / Lots of modules● Easy to find good staff

Page 20: Ruby, the language of devops

Languages we won't discuss● C/C++● .NET (C#, F#, etc)● JVM languages● Functional languages

o Especially Erlang● Node.JS

Page 21: Ruby, the language of devops

Bash/Shell scripts (Good and Bad)● Easy to write● Everyone has written Bash scripts● Horrible control structures● Horrible variable structures● Non-existent code structuring● “Libraries” don’t exist● Only really works on *nix

o Git-Bash doesn't count

Page 22: Ruby, the language of devops

Perl (the Good)● What most sysadmins use other than

Bash● Great variable structures● Great control structures● Excellent reusability

o CPAN is the largest single-language repository● Works everywhere (literally)● Good programmers can manage

500kLOC

Page 23: Ruby, the language of devops

Perl (the Bad)● Everyone thinks they know Perl

o Bad Perl is really really bad.

Page 24: Ruby, the language of devops

Perl (the Bad)● Everyone thinks they know Perl

o Bad Perl is really really bad.● Standard language facilities require

librarieso Exceptions, objects, case statements

Page 25: Ruby, the language of devops

Perl (the Bad)● Everyone thinks they know Perl

o Bad Perl is really really bad.● Standard language facilities require

librarieso Exceptions, objects, case statements

● CPAN is 80%+ useless

Page 26: Ruby, the language of devops

Perl (the Bad)● Everyone thinks they know Perl

o Bad Perl is really really bad.● Standard language facilities require

librarieso Exceptions, objects, case statements

● CPAN is 80%+ useless● Really old Perls are installed

everywhereo 5.005_003 (March, 1998)o 5.6.1(April, 2001)

Page 27: Ruby, the language of devops

Perl (the Ugly)● Solving a problem with regular

expressions means you have two problems.

Page 28: Ruby, the language of devops

Perl (the Ugly)● Solving a problem with regular

expressions means you have two problems.

● Sigils ($, @, %, etc) make code hard to reado Ironically, the idea was to make code easier to

read

Page 29: Ruby, the language of devops

Perl (the Ugly)● Solving a problem with regular

expressions means you have two problems.

● Sigils ($, @, %, etc) make code hard to reado Ironically, the idea was to make code easier to

read● Too many places where hidden globals

make you cry.o E.g., namespaces aren't namespaced.

Page 30: Ruby, the language of devops

Python (Strengths)● Great variable structures

Page 31: Ruby, the language of devops

Python (Strengths)● Great variable structures● Great control structures

Page 32: Ruby, the language of devops

Python (Strengths)● Great variable structures● Great control structures● All the advanced features

o Exceptionso Objectso Case statements

Page 33: Ruby, the language of devops

Python (Strengths)● Great variable structures● Great control structures● All the advanced features

o Exceptionso Objectso Case statements

● Runs everywhere that we care about

Page 34: Ruby, the language of devops

Python (Weaknesses)● Significant whitespace is difficult for

non-developers.

Page 35: Ruby, the language of devops

Python (Weaknesses)● Significant whitespace is difficult for

non-developers.● System programming libraries aren't

mature

Page 36: Ruby, the language of devops

Python (Weaknesses)● Significant whitespace is difficult for

non-developers.● System programming libraries aren't

mature● Writing libraries isn't self-evident

o Tutorials and scaffolding also immature

Page 37: Ruby, the language of devops

Ruby (Strengths)● Great variable structures

Page 38: Ruby, the language of devops

Ruby (Strengths)● Great variable structures● Great control structures

Page 39: Ruby, the language of devops

Ruby (Strengths)● Great variable structures● Great control structures● All the advanced features

o Exceptionso Objectso Case statements

Page 40: Ruby, the language of devops

Ruby (Strengths)● Great variable structures● Great control structures● All the advanced features

o Exceptionso Objectso Case statements

● Runs everywhere that we care about

Page 41: Ruby, the language of devops

Ruby (Strengths)● Great variable structures● Great control structures● All the advanced features

o Exceptionso Objectso Case statements

● Runs everywhere that we care about● Already used as a sysadmin language

Page 42: Ruby, the language of devops

Ruby (Weaknesses)● Minor versions changing syntax

o 1.8.7 vs. 1.9.3 vs 2.x

Page 43: Ruby, the language of devops

Ruby (Weaknesses)● Minor versions changing syntax

o 1.8.7 vs. 1.9.3 vs 2.x● Ruby is not Rails

o Really!

Page 44: Ruby, the language of devops

Ruby (Superpowers)1. Install multiple versions of same library2.Newbies are a way of life3.Blocks

Page 45: Ruby, the language of devops

Multiple library versions● Sysadmins are pessimistic

o Foo-bar 1.3.9 works, so don't change it!!

Page 46: Ruby, the language of devops

Multiple library versions● Sysadmins are pessimistic

o Foo-bar 1.3.9 works, so don't change it!!● Not everyone can use the same

versiono Something needs a feature in Foo-bar 2.1.5

Page 47: Ruby, the language of devops

Multiple library versions● Sysadmins are pessimistic

o Foo-bar 1.3.9 works, so don't change it!!● Not everyone can use the same

versiono Something needs a feature in Foo-bar 2.1.5

● So install both and specify at runtimegem 'Foo-bar', '=1.3.9'require 'foobar'

Page 48: Ruby, the language of devops

Newbie friendly● Rails is how many new web-developers

start

Page 49: Ruby, the language of devops

Newbie friendly● Rails is how many new web-developers

start● Rails is Ruby (plus, but still)

Page 50: Ruby, the language of devops

Newbie friendly● Rails is how many new web-developers

start● Rails is Ruby (plus, but still)● Thousands of great tutorials, skeletons,

and communities.o Google "ruby tutorial XYZ" for all values of

XYZ)

Page 51: Ruby, the language of devops

Newbie friendly● Rails is how many new web-developers

start● Rails is Ruby (plus, but still)● Thousands of great tutorials, skeletons,

and communities.o Google "ruby tutorial XYZ" for all values of

XYZ● Syntax is very easy to read and write

o Reading code is very hardo Anything that makes it easier is a "Good

Thing"(tm)

Page 52: Ruby, the language of devops

Blocks (Temporary File)require 'tempfile'Tempfile.open('some-prefix') do |tmp| tmp.write "Some text" # Do something with tmp hereend

Page 53: Ruby, the language of devops

Blocks (Reading from a file)

File.foreach('/some/file') do |line| puts “Line read: #{line}” do_something(line)end

Page 54: Ruby, the language of devops

Blocks (Writing to a file)

File.open('/some/file') do |file| file.puts 'first line' file.puts 'second line'end

Page 55: Ruby, the language of devops

Blocks (Writing to a file)

File.open '/some/file' { |file| file.puts 'first line' file.puts 'second line'}

Page 56: Ruby, the language of devops

Blocks (Changing Directory)

Dir.chdir('/some/place') do |dir| do_something_in_some_place(dir)end

do_something_in_original_dir()

Page 57: Ruby, the language of devops

Blocks (Nested blocks)Dir.chdir('/some/dir') do %w{sub1 sub2}.each do |subdir| Dir.chdir(subdir) do # In /some/dir/sub[12] end endend

Page 58: Ruby, the language of devops

Why blocks?● Same construct for iteration and

closureso A logical new lexical scope

Page 59: Ruby, the language of devops

Why blocks?● Same construct for iteration and

closureso A logical new lexical scope

● Automatic cleanupo (Not necessarily guaranteed in all cases)

Page 60: Ruby, the language of devops

Why blocks?● Same construct for iteration and

closureso A logical new lexical scope

● Automatic cleanupo (Not necessarily guaranteed in all cases)

● Clean delination of concernso Relevant code is in one place

Page 61: Ruby, the language of devops

Why blocks? (as a sysadmin)Because my job isn't where I can faff about until everything is perfectly just-so and my HammerFactoryFactoryFactory has 103% test coverage in Jenkins.

I need to be done yesterday and I need to be sure it works by looking at it.

Page 62: Ruby, the language of devops

Why blocks? (as a devops)Because it's the easiest way to convert a sysadmin into a developer.

Page 63: Ruby, the language of devops

Tooling● Vagrant● Chef / Puppet● Logstash● fpm● Cucumber● AWS / Rackspace clients● Rake / Capistrano

Page 64: Ruby, the language of devops

Tooling (why do I care it's in Ruby?)Three reasons:1.Plugins

Page 65: Ruby, the language of devops

Tooling (why do I care it's in Ruby?)Three reasons:1.Plugins2.Plugins

Page 66: Ruby, the language of devops

Tooling (why do I care it's in Ruby?)Three reasons:1.Plugins2.Plugins3.Plugins

Page 67: Ruby, the language of devops

Tooling (why do I care it's in Ruby?)Three reasons:1.Plugins2.Plugins3.Plugins

4.Some of them require Ruby (Vagrant)

Page 68: Ruby, the language of devops

Questions?