by Karol Kozakowski @cosaquee
Karol Kozakowski
Miejsce lub system w którym programista tworzy aplikacje
Jak wyglądają rozwiązania problemu środowisk produkcyjnych w innych firmach?
Jakie technologie są używane ?
Najpopularniejsze i polecane przez Puppetlabs :-(
Tak będziemy pracować na tym warsztacie
Najlepszy sposób pracy lecz zaawansowany
Typowe narzędzie fazy rozwoju i wstępnego testowania rozwiązań. Pozwala na:
# All commands as root
echo 'deb http://download.virtualbox.org/virtualbox/debian trusty contrib' >
/etc/apt/sources.list.d/virtualbox.list
wget -q https://www.virtualbox.org/download/oracle_vbox.asc -O- | apt-key add -
apt-get update
apt-get install virtualbox-5.0
curl -kL https://dl.bintray.com/mitchellh/vagrant/vagrant_1.7.2_x86_64.deb -o vagrant_1.7.2_x86_64.deb
dpkg -i vagrant_1.7.2_x86_64.deb
$ vagrant init puppetlabs/ubuntu-14.04-64-nocm
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.
$ _
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# Every Vagrant virtual environment requires a box to build off o
config.vm.box = "puppetlabs/ubuntu-14.04-64-nocm"
# Enable provisioning with Puppet stand alone. Puppet manifests
# are contained in a directory path relative to this Vagrantfile.
# You will need to create the manifests directory and a manifest
# the file default.pp in the manifests_path directory.
#
# config.vm.provision "puppet" do |puppet|
# puppet.manifests_path = "manifests"
# puppet.manifest_file = "site.pp"
# end
end
Vagrant.configure(2) do |config|
config.vm.network :private_network, ip: "192.168.50.4"
config.vm.provider :virtualbox do |v|
v.memory = 1024
v.cpus = 2
end
end
$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'puppetlabs/ubuntu-14.04-64-nocm'.
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'puppetlabs/ubuntu-14.04-64-nocm' is
==> default: Setting the name of the VM: tmp_default_1426727671461
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration..
default: Adapter 1: nat
==> default: Forwarding ports...
default: 22 => 2222 (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minu
default: SSH address: 127.0.0.1:2222
default: SSH username: vagrant
default: SSH auth method: private key
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
==> default: Mounting shared folders...
default: /vagrant => /tmp
$ _
$ vagrant ssh
Welcome to Ubuntu 14.04 LTS (GNU/Linux 3.13.0-24-generic x86_64)
* Documentation: https://help.ubuntu.com/
vagrant@localhost:~$ uptime
18:17:47 up 3 min, 1 user, load average: 0.00, 0.00, 0.00
vagrant@localhost:~$ logout
Connection to 127.0.0.1 closed.
$ _
Aby sprawdzić jaki jest aktualny stan maszyny w ramach konfiguracji, należy wywołać polecenie vagrant status
.
Aby skasować maszynę wykonać należy polecenie vagrant destroy
.
Vagrant.configure("2") do |config|
config.vm.box = "puppetlabs/ubuntu-14.04-64-puppet"
# Provision with Bash
config.vm.provision :shell, inline: "echo Hi $(cat /etc/issue)"
# Provision with Puppet apply
config.vm.provision :puppet do |puppet|
puppet.manifests_path = "manifests"
# contains: "package { 'elinks': ensure => 'installed', }"
puppet.manifest_file = "default.pp"
end
end
$ vagrant provision
==> default: Running provisioner: shell...
default: Running: inline script
==> default: Hi Ubuntu 14.04.2 LTS \n \l
==> default: Running provisioner: puppet...
==> default: Running Puppet with default.pp...
==> default: Notice: Compiled catalog for localhost.suszynski.org
in environment production in 0.08 seconds
==> default: Notice: /Stage[main]/Main/Package[elinks]/ensure:
ensure changed 'purged' to 'present'
==> default: Notice: Finished catalog run in 4.88 seconds
$ _
github.com/mitchellh/vagrant/wiki/Available-Vagrant-Plugins
puppetlabs/ubuntu-14.04-64-nocm
Jedno z najbardziej dojrzałych narzędzi DevOps
package { 'postgresql':
ensure => 'installed',
}
service { 'postgresql':
ensure => 'running',
enable => true,
require => Package['postgresql'],
}
Nawet ludzie nie znający Puppeta są w stanie odgadnąć co może oznaczać taki zapis
Zasobem jest każdy pojedynczy deklaratywny element, który puppet może wymusić
service { 'apache2':
ensure => 'running',
enable => true,
}
Puppet posiada wiele wbudowanych zasobów
Zasoby tworzą graf w którym określamy kolejność wykonania
service { 'apache2':
ensure => 'running',
require => Package['apache2'],
}
package { 'apache2':
ensure => 'installed',
}
require, before, subscribe, notify
install -> configure ~> service
package { 'openssh-server':
ensure => 'installed',
}
file { '/etc/ssh/sshd_config.conf':
ensure => 'file',
content => template('myssh/sshd_config.conf.erb'),
require => Package['openssh-server'],
}
service { 'ssh':
ensure => 'installed',
subscribe => File['/etc/ssh/sshd_config.conf'],
}
puppetlabs/ubuntu-14.04-64-nocm
wget https://apt.puppetlabs.com/puppetlabs-release-trusty.deb
sudo dpkg -i puppetlabs-release-trusty.deb
sudo apt-get update && sudo apt-get install -y puppet
javascript
/home/javascript
, /home/javascript/.ssh
puppet parser validate plik.pp
Kod puppet umieszczamy w:
mymodule # This outermost directory’s name matches the
│ # name of the module.
├── manifests # Contains all of the manifests in the module.
│ └── init.pp # Contains a class definition. This class’s
│ # name must match the module’s name.
├── metadata.json # Contains META information about module
├── spec # Contains spec tests for any plugins in the
│ # lib directory.
├── templates # Contains templates, which the module’s
│ # manifests can use.
├── files # Contains files to be sourced
├── tests # Contains examples showing how to declare
│ │ # the module's classes and defined types.
│ └── init.pp
└── lib # Contains plugins, like custom facts and
│ # custom resource types.
└── puppet
├── provider
└── type
Wiecej: http://slides.com/cardil/...
puppet module generate company/modulename
Generuje strukturę modułu
class apache ($version = 'latest') {
package {'httpd':
ensure => $version, # Using the class parameter from above
before => File['/etc/httpd.conf'],
}
file {'/etc/httpd.conf':
ensure => file,
owner => 'httpd',
content => template('apache/httpd.conf.erb'), # Template from a module
}
service {'httpd':
ensure => running,
enable => true,
subscribe => File['/etc/httpd.conf'],
}
}
# only once in catalog
# class is a resource
class { 'apache':
version => 'latest',
}
# or simply
include apache
include apache
# /etc/puppet/modules/apache/manifests/vhost.pp
define apache::vhost ($port, $docroot, $servername = $title, $vhost_name = '*') {
include apache # contains Package['httpd'] and Service['httpd']
include apache::params # contains common config settings
$vhost_dir = $apache::params::vhost_dir
file { "${vhost_dir}/${servername}.conf":
content => template('apache/vhost-default.conf.erb'),
# This template can access all of the parameters and variables from above.
owner => 'www',
group => 'www',
mode => '644',
require => Package['httpd'],
notify => Service['httpd'],
}
}
inazwisko/javascript
i przenieść kod do klas i definicjipuppet module
puppet module list # listuje moduły
puppet search apt # szuka modułu po słowie kluczowym
puppet module install puppetlabs/apt # instaluje moduł
pisane przez Puppetlabs, testowane na wielu platformach
pisane przez innych autorów, zaakceptowane przez Puppetlabs jako jedne z najlepszych spełniających wymagania
Ilość ściągnięć, historia, kto developuje, zależności, instalacja pakietów systemu, wartości na sztywno
Puppetfile
forge 'https://forge.puppetlabs.com/'
mod 'puppetlabs/apt'
mod 'puppetlabs/firewall', '1.8.0'
gem install librarian-puppet
librarian-puppet update --verbose
w katalogu pliku Puppetfile
librarian-puppet
(instalacja ruby-dev, File, Package)/etc/puppet/Puppetfile
librarian-puppet update --verbose
package
https://forge.puppetlabs.com/puppetlabs/nodejs
puppetlabs/nodejs
(za pomocą librarian-puppet)include nodejs
node
Istenieje możliwość wymuszenia konkretnego providera dla każdego typu
package { 'lolcat':
ensure => 'present',
provider => 'gem',
}
lolcat
z RubyGems przy pomocy zasobu package
i providera gem
lolcat -h
include nodejs
Po wywołaniu będziemy mogli wywołać polecenie node
package { 'express':
ensure => 'present',
provider => 'npm',
}
Instalacja paczki express
dla każdego użytkownika w systemie.
nodejs::npm { 'express from the npm registry':
ensure => 'present',
package => 'express',
target => '~/node_modules',
}
Instalacja biblioteke express
do ~/node_modules
dla aktualnego użytkownika w systemie.
Nie możemy wykorzystać zasobu package
bo instaluje on w scieżkach systemowych
grunt-cli
przy użyciu puppetlabs/nodejsmongodb
przy użyciu puppetlabs/nodejsnpm install
grunt
Co poznaliśmy? Powtórka