DevOps: Falando um pouco sobre desenvolvimento orientado a testes com Puppet

Post on 15-Jan-2017

781 views 0 download

Transcript of DevOps: Falando um pouco sobre desenvolvimento orientado a testes com Puppet

DevOps: Falando um pouco sobredesenvolvimento orientado a testes

com Puppet

DevOps: Falando um pouco sobredesenvolvimento orientado a testes

com Puppet

http://about.me/mfandrade

Quem sou eu?

Puppet?

MANIFEST

MANIFEST

MANIFEST

MANIFEST

RESOURCE

RESOURCE

RESOURCE

MANIFEST

RESOURCE

RESOURCE

MANIFEST

RESOURCE

MANIFEST

CATALOG

RESOURCE

RESOURCE

RESOURCE

MANIFEST

RESOURCE

RESOURCE

MANIFEST

RESOURCE

compile

DECLARATIVA

IDEMPOTENTE

// rpm basedpackage { 'mysql':  ensure => installed,}

file { '/etc/my.cnf':  ensure  => present,  source  => 'puppet:///modules/mysql/my.cnf',   require => Package['mysql'],}

service { 'mysqld':  ensure    => running,  enabled   => true,  subscribe => File['/etc/my.cnf'],}

1

// deb basedpackage { 'mysql­server':  ensure => installed,}

file { '/etc/mysql/my.cnf':  ensure  => present,  source  => 'puppet:///modules/mysql/my.cnf',   require => Package['mysql­server'],}

service { 'mysql':  ensure    => running,  enabled   => true,  subscribe => File['/etc/mysql/my.cnf'],}

2

// mysql.pp // rpm and deb based$pkg = 'mysql'$cfg = '/etc/my.cnf'$srv = 'mysqld'

if $::osfamily == 'Debian' {  $pkg = 'mysql­server'  $cfg = '/etc/mysql/my.cnf'  $srv = 'mysql'

}

// cont...

// mysql.pp // rpm and deb based$pkg = 'mysql'$cfg = '/etc/my.cnf'$srv = 'mysqld'

if $::osfamily == 'Debian' {  $pkg = 'mysql­server'  $cfg = '/etc/mysql/my.cnf'  $srv = 'mysql'

}

// cont...

3// mysql.pp // rpm and deb basedif $::osfamily == 'Debian' {  $pkg = 'mysql­server'  $cfg = '/etc/mysql/my.cnf'  $srv = 'mysql'

} elsif $::osfamily == 'RedHat' {  $pkg = 'mysql'  $cfg = '/etc/my.cnf'  $srv = 'mysqld'

} else fail('Unsupported osfamily')

// cont...

3// cont...package { $pkg:  ensure => installed,}

file { $cfg:  ensure  => present,  source  => 'puppet:///modules/mysql/my.cnf',   require => Package[$pkg],}

service { $srv:  ensure    => running,  enabled   => true,  subscribe => File[$cfg],}

Como testar isso?

Como testar isso?

cucumber-puppethttp://projects.puppetlabs.com/projects/cucumber-puppet/

rspec-puppethttp://rspec-puppet.com/tutorial/

puppet-lint * http://puppet-lint.com/

rspec-puppet

rspec-puppetrequire 'rspec'require 'rspec­puppet'

describe 'when installing mysql' do  it { should contain_package('mysql').with {    :ensure => 'installed'  }}

  it { should contain_file('/etc/my.cnf').with {    :ensure => 'present',    :source => 'puppet:///modules/mysql/my.cnf',  }}

  it { should contain_service('mysqld').with {    :ensure => 'running',    :enable => true  }}end

rspec-puppetrequire 'rspec'require 'rspec­puppet'

describe 'when installing mysql' do  it { should compile }

end

rspec-puppetrequire 'rspec'require 'rspec­puppet'

describe 'when installing mysql' do  it { should compile }

end

SMOKE TE

STSMOK

E TEST

$ puppet apply ­­noop ­­verbose mysql.pp

$ puppet apply ­­noop ­­verbose mysql.ppError: Syntax error at 'fail'; expected '}' at mysql.pp:13 on localhostError: Invalid parameter enabled on Service[mysql] at mysql.pp:28 on localhost

// mysql.pp // rpm and deb basedif $::osfamily == 'Debian' {  $pkg = 'mysql­server'  $cfg = '/etc/mysql/my.cnf'  $srv = 'mysql'

} elsif $::osfamily == 'RedHat' {  $pkg = 'mysql'  $cfg = '/etc/my.cnf'  $srv = 'mysqld'

} else fail('Unsupported osfamily')

// cont...

// mysql.pp // rpm and deb basedif $::osfamily == 'Debian' {  $pkg = 'mysql­server'  $cfg = '/etc/mysql/my.cnf'  $srv = 'mysql'

} elsif $::osfamily == 'RedHat' {  $pkg = 'mysql'  $cfg = '/etc/my.cnf'  $srv = 'mysqld'

} else { fail('Unsupported osfamily') }

// cont...

// cont...package { $pkg:  ensure => installed,}

file { $cfg:  ensure  => present,  source  => 'puppet:///modules/mysql/my.cnf',   require => Package[$pkg],}

service { $srv:  ensure    => running,  enabled   => true,  subscribe => File[$cfg],}

// cont...package { $pkg:  ensure => installed,}

file { $cfg:  ensure  => present,  source  => 'puppet:///modules/mysql/my.cnf',   require => Package[$pkg],}

service { $srv:  ensure    => running,  enable    => true,  subscribe => File[$cfg],}

$ puppet apply ­­noop ­­verbose mysql.ppNotice: Compiled catalog for notebook in environment production in 3.30 secondsInfo: Applying configuration version '1444280295'Notice: /Stage[main]/Mysql/Package[mysql­server]/ensure: current_value purged, should be present (noop)Notice: /Stage[main]/Mysql/Service[mysql]/ensure: current_value stopped, should be running (noop)Info: /Stage[main]/Mysql/Service[mysql]: Unscheduling refresh on Service[mysql]Notice: Class[Mysql]: Would have triggered 'refresh' from 2 eventsNotice: Stage[main]: Would have triggered 'refresh' from 1 eventsNotice: Finished catalog run in 0.53 seconds

Características

Simplicidade

Curva de aprendizado

Pouca profundidade

Design evolutivo

https://docs.puppetlabs.com/

OBRIGADOOBRIGADO