SlideShare ist ein Scribd-Unternehmen logo
1 von 31
Downloaden Sie, um offline zu lesen
Puppet Tasks:
Taming SSH in a for loop

Alex Dreyer
Principal Software Engineer 

Puppet
Agenda
1. About Tasks
2. Writing Tasks
3. Writing Plans
Why Tasks
! Live discovery or debugging across nodes
! Actions that don’t relate to desired state.
! Intermediate state during complex deploys
! Immediacy
Puppet’s declarative model isn’t enough
What are tasks
A task is a single action you can take on a node
! Tasks are scripts or executables written in any language
! Tasks are packaged in puppet modules
! Tasks are copied to and executed on the target
bolt vs puppet-task
! Bolt is OS vs puppet-task is PE
! Bolt is a ruby command line tool it loads tasks from the local disk
! puppet-task is a lightweight client for the orchestrator API
! Both should be functionally equivalent for running tasks where possible
Task Runners
Bolt vs Orchestrator
Bolt
! Bolt is commandline application
! Bolt does not require puppet
! Bolt can run plans
! Bolt code is installed locally
! Bolt uses ssh and winrm to connect to
nodes
Orchestrator
! Orchestrator is a service with multiple
clients(puppet-task, PE GUI)
! Orchestrator run s on a PE master and
agents on all nodes
! Orchestrator does not support plans yet
! Orchestrator uses code installed on the
master
! Orchestrator sends messages to the pxp-
agent running on nodes
Differences between the two task runners
Simple tasks
! Task parameters are passed as environment variables prefixed with PT_
! Version and deploy this with normal code management tools
! Grant PE rbac permissions and run the task in the console.
! Interact with your own simple scripts just like complex tasks from the Puppet Forge
Tasks are easy!
#!/usr/bin/env bash
touch $PT_file
Running tasks in the CLI
! "task" is the puppet or bolt subcommand
! "run" is the action
! "--nodes master.vm" is the target
! "touch" is the task to run
! "file=/tmp/foo" is the parameter to the task
! "--modules=./"
puppet task run --nodes master.vm touch file=/tmp/foo
bolt task run --nodes master.vm touch file=/tmp/foo --modules=./
Task Names
! A full task name has two parts: <module_name>::<task_name>
! Task names do not include the file extension
! Task names must match the puppet class name regex: /A[a-z][a-z0-9_]*Z/
! The init task's name is just <module_name> like the init class
! Task files must be at the top level of the tasks directory
! There must be only one task with any name
JSON Task API
! Accept typed or complex input without special parsing
! Return structured data that can be processed later
! Generate better errors and messages
! Even for simple tasks the Task Runner coerces their output in JSON
Using Structured Input
! A single JSON object will be passed to the task on stdin
! Parameter names must match the puppet parameter regex
! Don't treat absence and null values differently
! Use --params to pass typed JSON on the CLI
Structured input
1 #!/opt/puppetlabs/puppet/bin/ruby
2 #touch/tasks/array.rb
3
4 require 'json'
5 require 'fileutils'
6
7 params = JSON.parse(STDIN.read)
8
9 params['files'].each do |filename|
10 FileUtils.touch(filename)
11 puts "Updated file #{filename}"
12 end
Generating Structured output
! Print only a single JSON object to stdout
! Use only keys that match the parameter regex
! It's best to have defined keys at the top level
! Use standard '_' prefixed keys when appropriate.
! Use the '_output' key for a human readable summary of the result
1 #!/opt/puppetlabs/puppet/bin/ruby
2 #touch/tasks/output.rb
3 require 'json'
4 require 'fileutils'
5
6 params = JSON.parse(STDIN.read)
7 file_result = params['files'].reduce({}) do |files, filename|
8 files[filename] = {}
9 files[filename]['new'] = !File.exists?(filename)
10 FileUtils.touch(filename)
11 files[filename]['success'] = true
12 files
13 end
14
15 result = { '_output' => "Successfully touched all files.",
16 'files' => file_result }
17 STDOUT.puts(result.to_json)
Handling errors
! Put errors in an '_error' object
! Exit non-zero for errors
! Use 'msg' in the object for the error message
! Use 'kind' in the object like an error class.
! Use 'details' for any structured information.
! Try to catch all errors otherwise you have no control over the error object
{ "msg": "Failed to update file: '/tmp/foo'",
"kind": "touch/file-error",
"details": { "file": "/tmp/foo" } }
2 # touch/tasks/error.rb
..
9 exitcode = 0
10 result = {}
11 result['files'] = params['files'].reduce({}) do |files, filename|
12 begin
..
16 rescue StandardError => e
17 exitcode = 1
18 files[filename]['success'] = false
19 files[filename]['error'] = e.message
20 end
21 files
22 end
23 if exitcode == 0
24 result['_output'] = "Successfully touched all files."
25 STDOUT.puts(result.to_json)
26 else
27 errored_files = result.map { |filename, r| filename unless
r[:success] }.compact
28 STDOUT.puts({ _error: { kind: 'touch/file-error',
29 msg: "Failed to update files: #{errored_files.join(',')}",
30 details: { files: result['files'] } } }.to_json)
31 end
32 exit exitcode
Task Metadata
! Tasks with metadata are self documenting
! Tasks with metadata can have auto-generated Interfaces
! The Task runner will validate parameters against metadata
! Metadata can change how the task is executed
! Metadata can be used to enable features like noop
{ "description": "touch files on the target system",
"input_method": "stdin",
"supports_noop": true,
"parameters": {
"files": {
"description": "An array of files to touch",
"type": "Array[String]" } } }
--noop
! Tasks that support noop can be safely run in noop mode as a simulation
! When the task is called with '--noop' "_noop": true is sent with the params
! The author must make sure that no state on the system is changed when that flag is present
! Tasks that don't set "supports_noop" in metadata will not be run when a noop run is requested
2 # touch/tasks/noop.rb
16 if params['_noop']
17 raise StandardError "#{filename} isn't writable" unless File.writable?(filename)
18 dirname = File.basename(filename)
19 raise StandardError "Directory #{dirname} does not exist." unless File.directory?(dirname)
20 else
21 FileUtils.touch(filename)
22 files[filename]['success'] = true
23 end
Tasks on windows
Task execution program is hardcoded
Extension Program
.rb Puppet agent ruby
.pp puppet agent apply
.ps1 powershell
1 #.DESCRIPTION
2 #Updates the write time on a list of files similar to the 'touch' command.
3 #
4 #.PARAMETER files
5 #The files to touch
6 [CmdletBinding()]
7 Param(
8 [Parameter(Mandatory=$true,Position=1)]
9 [String[]] $files
10 )
11
12 $ErrorActionPreference = "Stop"
13 $fileresults = @{ }
14
15 ForEach ($file in $files) {
16 if(Test-Path $file) {
17 (Get-Item $file).LastWriteTime = Get-Date
18 $fileresults.add($file, @{ "success" = [bool]$true; "new" = [bool]$true })
19 } else {
20 echo $null > $file
21 $fileresults.add($file, @{ "success" = [bool]$true; "new" = [bool]$false })
22 }}
23 ConvertTo-Json -InputObject @{ "files" = $fileresults }
Puppet manifest tasks
! Puppet manifest can be applied as tasks
! Powerful tool for cross platform tasks
! Code needs to installed in the configured environment on the target
! Beware of conflicts and concat
1 #!/opt/puppetlabs/bin/puppet apply
2 $pkg = case $::osfamily {
3 'redhat': 'httpd',
4 'debian': 'apache2'}
5 package {$pkg: ensure => present }
Writing tasks for PE RBAC
! Grant permissions for specific tasks
! Use the type system and pattern type restrictively to prevent injections
! Create versions of tasks with fewer parameters
! Create versions of tasks that refuse to run on some nodes
Testing Tasks
! Use the unit testing library for the language you're working in.
! Use beaker to automate system level testing with a Task Runner
Tasks Plans
! The Plan language allows you to string tasks together
! Task plans are written in puppet language
! Task plans are executed top to bottom unlike puppet manifest
! Task plans call tasks with the run_task function
! Tasks plans are experimental and only available in bolt
run_task
! Create a plan object at the top scope of your plan
! Use the run_task function to call tasks
plan touch::promote([String] $tier = 'dev') {
$node = "db.${tier}.vm"
run_task('touch::noop', [$node], 'files' => ['/etc/postgres/trigger'])
}
1 plan canary::random(
2 String $task,
3 String $nodes,
4 Hash[String, Data] $params = {},
5 Integer $canary_size = 1
6 ) {
7 [$canaries, $rest] = canary::random_split($nodes.split(','),
$canary_size)
8
9 $canr = run_task($task, $canaries, $params)
10 if($canr.ok) {
11 util::print("Successfully deployed to canaries: ${canr.names}")
12 $restr = run_task($task, $rest, $params)
13 } else {
14 util::print("Deploy to canaries failed: ${canr.error_nodes.names}")
15 $restr = canary::skip($rest)
16 }
17
18 canary::merge($canr, $restr)
19 }
Extending Task Plans
! The Plan language is very small limited but there are a few extension points
! Tasks: Use tasks to capture anything you don't want to write in ruby or puppet. Run tasks
locally to send notifications or collect data.
! Functions: Use functions especially functions on ExecutionResult and Error objects
! Plans: Call plans from other other plans with run_plan. Use this to capture generic actions like
canary deployments.
Plans and PE
! In addition to running plans over ssh and winrm bolt supports using orchestrator as a
transport for running tasks.
! Install bolt
! Make sure puppet-task works, bolt will use the same config ~/.puppetlabs/client-tools/
orch.conf
! Make sure any tasks you need are available both in the production environment of your
master and in the --modules dir bolt is using
! If you want to run scripts, run commands or upload files make sure bolt is installed as a
module in the production environment of your master too. It has a single bolt task used for
these
! use the 'pcp' protocol to use orchestrator. ie --nodes pcp://agent1.example.com
Resources
! Code: https://github.com/adreyer/puppetconf-modules
! Task Tutorial: https://github.com/puppetlabs/tasks-hands-on-lab
! More content: https://github.com/puppetlabs/task-modules
! Forge: https://forge.puppet.com/modules?with_tasks=yes
! Docs: https://puppet.com/docs/bolt/0.5/writing_tasks_and_plans.html
! Slack: #puppet-tasks
! November Virtual PUG
PuppetConf 2017: Puppet Tasks: Taming ssh in a "for" loop- Alex Dreyer, Puppet

Weitere ähnliche Inhalte

Was ist angesagt?

PL/Perl - New Features in PostgreSQL 9.0
PL/Perl - New Features in PostgreSQL 9.0PL/Perl - New Features in PostgreSQL 9.0
PL/Perl - New Features in PostgreSQL 9.0Tim Bunce
 
Perl Memory Use 201209
Perl Memory Use 201209Perl Memory Use 201209
Perl Memory Use 201209Tim Bunce
 
Construire son JDK en 10 étapes
Construire son JDK en 10 étapesConstruire son JDK en 10 étapes
Construire son JDK en 10 étapesJosé Paumard
 
Puppet Systems Infrastructure Construction Kit
Puppet Systems Infrastructure Construction KitPuppet Systems Infrastructure Construction Kit
Puppet Systems Infrastructure Construction KitAlessandro Franceschi
 
Ansible tips & tricks
Ansible tips & tricksAnsible tips & tricks
Ansible tips & tricksbcoca
 
Perl at SkyCon'12
Perl at SkyCon'12Perl at SkyCon'12
Perl at SkyCon'12Tim Bunce
 
Devel::NYTProf v5 at YAPC::NA 201406
Devel::NYTProf v5 at YAPC::NA 201406Devel::NYTProf v5 at YAPC::NA 201406
Devel::NYTProf v5 at YAPC::NA 201406Tim Bunce
 
Puppet modules: An Holistic Approach
Puppet modules: An Holistic ApproachPuppet modules: An Holistic Approach
Puppet modules: An Holistic ApproachAlessandro Franceschi
 
Perl Memory Use 201207 (OUTDATED, see 201209 )
Perl Memory Use 201207 (OUTDATED, see 201209 )Perl Memory Use 201207 (OUTDATED, see 201209 )
Perl Memory Use 201207 (OUTDATED, see 201209 )Tim Bunce
 
Asynchronous Systems with Fn Flow
Asynchronous Systems with Fn FlowAsynchronous Systems with Fn Flow
Asynchronous Systems with Fn FlowJosé Paumard
 
Shared Object images in Docker: What you need is what you want.
Shared Object images in Docker: What you need is what you want.Shared Object images in Docker: What you need is what you want.
Shared Object images in Docker: What you need is what you want.Workhorse Computing
 
The Puppet Debugging Kit: Building Blocks for Exploration and Problem Solving...
The Puppet Debugging Kit: Building Blocks for Exploration and Problem Solving...The Puppet Debugging Kit: Building Blocks for Exploration and Problem Solving...
The Puppet Debugging Kit: Building Blocks for Exploration and Problem Solving...Puppet
 
PECL Picks - Extensions to make your life better
PECL Picks - Extensions to make your life betterPECL Picks - Extensions to make your life better
PECL Picks - Extensions to make your life betterZendCon
 
7 Stages of Unit Testing in iOS
7 Stages of Unit Testing in iOS7 Stages of Unit Testing in iOS
7 Stages of Unit Testing in iOSJorge Ortiz
 

Was ist angesagt? (20)

ReUse Your (Puppet) Modules!
ReUse Your (Puppet) Modules!ReUse Your (Puppet) Modules!
ReUse Your (Puppet) Modules!
 
Unit Testing Lots of Perl
Unit Testing Lots of PerlUnit Testing Lots of Perl
Unit Testing Lots of Perl
 
PL/Perl - New Features in PostgreSQL 9.0
PL/Perl - New Features in PostgreSQL 9.0PL/Perl - New Features in PostgreSQL 9.0
PL/Perl - New Features in PostgreSQL 9.0
 
Perl Memory Use 201209
Perl Memory Use 201209Perl Memory Use 201209
Perl Memory Use 201209
 
Construire son JDK en 10 étapes
Construire son JDK en 10 étapesConstruire son JDK en 10 étapes
Construire son JDK en 10 étapes
 
IO Streams, Files and Directories
IO Streams, Files and DirectoriesIO Streams, Files and Directories
IO Streams, Files and Directories
 
Puppet Systems Infrastructure Construction Kit
Puppet Systems Infrastructure Construction KitPuppet Systems Infrastructure Construction Kit
Puppet Systems Infrastructure Construction Kit
 
Ansible tips & tricks
Ansible tips & tricksAnsible tips & tricks
Ansible tips & tricks
 
Intro to-puppet
Intro to-puppetIntro to-puppet
Intro to-puppet
 
Perl at SkyCon'12
Perl at SkyCon'12Perl at SkyCon'12
Perl at SkyCon'12
 
Devel::NYTProf v5 at YAPC::NA 201406
Devel::NYTProf v5 at YAPC::NA 201406Devel::NYTProf v5 at YAPC::NA 201406
Devel::NYTProf v5 at YAPC::NA 201406
 
Power of Puppet 4
Power of Puppet 4Power of Puppet 4
Power of Puppet 4
 
Puppet modules: An Holistic Approach
Puppet modules: An Holistic ApproachPuppet modules: An Holistic Approach
Puppet modules: An Holistic Approach
 
Perl Memory Use 201207 (OUTDATED, see 201209 )
Perl Memory Use 201207 (OUTDATED, see 201209 )Perl Memory Use 201207 (OUTDATED, see 201209 )
Perl Memory Use 201207 (OUTDATED, see 201209 )
 
Asynchronous Systems with Fn Flow
Asynchronous Systems with Fn FlowAsynchronous Systems with Fn Flow
Asynchronous Systems with Fn Flow
 
Shared Object images in Docker: What you need is what you want.
Shared Object images in Docker: What you need is what you want.Shared Object images in Docker: What you need is what you want.
Shared Object images in Docker: What you need is what you want.
 
The Puppet Debugging Kit: Building Blocks for Exploration and Problem Solving...
The Puppet Debugging Kit: Building Blocks for Exploration and Problem Solving...The Puppet Debugging Kit: Building Blocks for Exploration and Problem Solving...
The Puppet Debugging Kit: Building Blocks for Exploration and Problem Solving...
 
PECL Picks - Extensions to make your life better
PECL Picks - Extensions to make your life betterPECL Picks - Extensions to make your life better
PECL Picks - Extensions to make your life better
 
7 Stages of Unit Testing in iOS
7 Stages of Unit Testing in iOS7 Stages of Unit Testing in iOS
7 Stages of Unit Testing in iOS
 
Effective Benchmarks
Effective BenchmarksEffective Benchmarks
Effective Benchmarks
 

Ähnlich wie PuppetConf 2017: Puppet Tasks: Taming ssh in a "for" loop- Alex Dreyer, Puppet

Bioinformatica 29-09-2011-p1-introduction
Bioinformatica 29-09-2011-p1-introductionBioinformatica 29-09-2011-p1-introduction
Bioinformatica 29-09-2011-p1-introductionProf. Wim Van Criekinge
 
Why Every Tester Should Learn Ruby
Why Every Tester Should Learn RubyWhy Every Tester Should Learn Ruby
Why Every Tester Should Learn RubyRaimonds Simanovskis
 
Scalable and Flexible Machine Learning With Scala @ LinkedIn
Scalable and Flexible Machine Learning With Scala @ LinkedInScalable and Flexible Machine Learning With Scala @ LinkedIn
Scalable and Flexible Machine Learning With Scala @ LinkedInVitaly Gordon
 
NYPHP March 2009 Presentation
NYPHP March 2009 PresentationNYPHP March 2009 Presentation
NYPHP March 2009 Presentationbrian_dailey
 
Bash is not a second zone citizen programming language
Bash is not a second zone citizen programming languageBash is not a second zone citizen programming language
Bash is not a second zone citizen programming languageRené Ribaud
 
Introduction to Ansible - Peter Halligan
Introduction to Ansible - Peter HalliganIntroduction to Ansible - Peter Halligan
Introduction to Ansible - Peter HalliganCorkOpenTech
 
Bioinformatics p1-perl-introduction v2013
Bioinformatics p1-perl-introduction v2013Bioinformatics p1-perl-introduction v2013
Bioinformatics p1-perl-introduction v2013Prof. Wim Van Criekinge
 
FireWorks workflow software
FireWorks workflow softwareFireWorks workflow software
FireWorks workflow softwareAnubhav Jain
 
PuppetDB: Sneaking Clojure into Operations
PuppetDB: Sneaking Clojure into OperationsPuppetDB: Sneaking Clojure into Operations
PuppetDB: Sneaking Clojure into Operationsgrim_radical
 
Introduction to Elixir
Introduction to ElixirIntroduction to Elixir
Introduction to ElixirDiacode
 
Best training-in-mumbai-shell scripting
Best training-in-mumbai-shell scriptingBest training-in-mumbai-shell scripting
Best training-in-mumbai-shell scriptingvibrantuser
 
(1) cpp introducing the_cpp_programming_language
(1) cpp introducing the_cpp_programming_language(1) cpp introducing the_cpp_programming_language
(1) cpp introducing the_cpp_programming_languageNico Ludwig
 
Programming Under Linux In Python
Programming Under Linux In PythonProgramming Under Linux In Python
Programming Under Linux In PythonMarwan Osman
 

Ähnlich wie PuppetConf 2017: Puppet Tasks: Taming ssh in a "for" loop- Alex Dreyer, Puppet (20)

Bioinformatica 29-09-2011-p1-introduction
Bioinformatica 29-09-2011-p1-introductionBioinformatica 29-09-2011-p1-introduction
Bioinformatica 29-09-2011-p1-introduction
 
Why Every Tester Should Learn Ruby
Why Every Tester Should Learn RubyWhy Every Tester Should Learn Ruby
Why Every Tester Should Learn Ruby
 
Scalable and Flexible Machine Learning With Scala @ LinkedIn
Scalable and Flexible Machine Learning With Scala @ LinkedInScalable and Flexible Machine Learning With Scala @ LinkedIn
Scalable and Flexible Machine Learning With Scala @ LinkedIn
 
NYPHP March 2009 Presentation
NYPHP March 2009 PresentationNYPHP March 2009 Presentation
NYPHP March 2009 Presentation
 
Bash is not a second zone citizen programming language
Bash is not a second zone citizen programming languageBash is not a second zone citizen programming language
Bash is not a second zone citizen programming language
 
Easy native wrappers with SWIG
Easy native wrappers with SWIGEasy native wrappers with SWIG
Easy native wrappers with SWIG
 
Introduction to Ansible - Peter Halligan
Introduction to Ansible - Peter HalliganIntroduction to Ansible - Peter Halligan
Introduction to Ansible - Peter Halligan
 
Shell scripting
Shell scriptingShell scripting
Shell scripting
 
Python build your security tools.pdf
Python build your security tools.pdfPython build your security tools.pdf
Python build your security tools.pdf
 
Bioinformatics p1-perl-introduction v2013
Bioinformatics p1-perl-introduction v2013Bioinformatics p1-perl-introduction v2013
Bioinformatics p1-perl-introduction v2013
 
Powershell notes
Powershell notesPowershell notes
Powershell notes
 
FireWorks workflow software
FireWorks workflow softwareFireWorks workflow software
FireWorks workflow software
 
PuppetDB: Sneaking Clojure into Operations
PuppetDB: Sneaking Clojure into OperationsPuppetDB: Sneaking Clojure into Operations
PuppetDB: Sneaking Clojure into Operations
 
Introduction to Elixir
Introduction to ElixirIntroduction to Elixir
Introduction to Elixir
 
Best training-in-mumbai-shell scripting
Best training-in-mumbai-shell scriptingBest training-in-mumbai-shell scripting
Best training-in-mumbai-shell scripting
 
(1) cpp introducing the_cpp_programming_language
(1) cpp introducing the_cpp_programming_language(1) cpp introducing the_cpp_programming_language
(1) cpp introducing the_cpp_programming_language
 
Introduction to Perl
Introduction to PerlIntroduction to Perl
Introduction to Perl
 
Programming Under Linux In Python
Programming Under Linux In PythonProgramming Under Linux In Python
Programming Under Linux In Python
 
PyCon 2011: IronPython Command Line
PyCon 2011:  IronPython Command LinePyCon 2011:  IronPython Command Line
PyCon 2011: IronPython Command Line
 
Bash production guide
Bash production guideBash production guide
Bash production guide
 

Mehr von Puppet

Puppet camp2021 testing modules and controlrepo
Puppet camp2021 testing modules and controlrepoPuppet camp2021 testing modules and controlrepo
Puppet camp2021 testing modules and controlrepoPuppet
 
Puppetcamp r10kyaml
Puppetcamp r10kyamlPuppetcamp r10kyaml
Puppetcamp r10kyamlPuppet
 
2021 04-15 operational verification (with notes)
2021 04-15 operational verification (with notes)2021 04-15 operational verification (with notes)
2021 04-15 operational verification (with notes)Puppet
 
Puppet camp vscode
Puppet camp vscodePuppet camp vscode
Puppet camp vscodePuppet
 
Modules of the twenties
Modules of the twentiesModules of the twenties
Modules of the twentiesPuppet
 
Applying Roles and Profiles method to compliance code
Applying Roles and Profiles method to compliance codeApplying Roles and Profiles method to compliance code
Applying Roles and Profiles method to compliance codePuppet
 
KGI compliance as-code approach
KGI compliance as-code approachKGI compliance as-code approach
KGI compliance as-code approachPuppet
 
Enforce compliance policy with model-driven automation
Enforce compliance policy with model-driven automationEnforce compliance policy with model-driven automation
Enforce compliance policy with model-driven automationPuppet
 
Keynote: Puppet camp compliance
Keynote: Puppet camp complianceKeynote: Puppet camp compliance
Keynote: Puppet camp compliancePuppet
 
Automating it management with Puppet + ServiceNow
Automating it management with Puppet + ServiceNowAutomating it management with Puppet + ServiceNow
Automating it management with Puppet + ServiceNowPuppet
 
Puppet: The best way to harden Windows
Puppet: The best way to harden WindowsPuppet: The best way to harden Windows
Puppet: The best way to harden WindowsPuppet
 
Simplified Patch Management with Puppet - Oct. 2020
Simplified Patch Management with Puppet - Oct. 2020Simplified Patch Management with Puppet - Oct. 2020
Simplified Patch Management with Puppet - Oct. 2020Puppet
 
Accelerating azure adoption with puppet
Accelerating azure adoption with puppetAccelerating azure adoption with puppet
Accelerating azure adoption with puppetPuppet
 
Puppet catalog Diff; Raphael Pinson
Puppet catalog Diff; Raphael PinsonPuppet catalog Diff; Raphael Pinson
Puppet catalog Diff; Raphael PinsonPuppet
 
ServiceNow and Puppet- better together, Kevin Reeuwijk
ServiceNow and Puppet- better together, Kevin ReeuwijkServiceNow and Puppet- better together, Kevin Reeuwijk
ServiceNow and Puppet- better together, Kevin ReeuwijkPuppet
 
Take control of your dev ops dumping ground
Take control of your  dev ops dumping groundTake control of your  dev ops dumping ground
Take control of your dev ops dumping groundPuppet
 
100% Puppet Cloud Deployment of Legacy Software
100% Puppet Cloud Deployment of Legacy Software100% Puppet Cloud Deployment of Legacy Software
100% Puppet Cloud Deployment of Legacy SoftwarePuppet
 
Puppet User Group
Puppet User GroupPuppet User Group
Puppet User GroupPuppet
 
Continuous Compliance and DevSecOps
Continuous Compliance and DevSecOpsContinuous Compliance and DevSecOps
Continuous Compliance and DevSecOpsPuppet
 
The Dynamic Duo of Puppet and Vault tame SSL Certificates, Nick Maludy
The Dynamic Duo of Puppet and Vault tame SSL Certificates, Nick MaludyThe Dynamic Duo of Puppet and Vault tame SSL Certificates, Nick Maludy
The Dynamic Duo of Puppet and Vault tame SSL Certificates, Nick MaludyPuppet
 

Mehr von Puppet (20)

Puppet camp2021 testing modules and controlrepo
Puppet camp2021 testing modules and controlrepoPuppet camp2021 testing modules and controlrepo
Puppet camp2021 testing modules and controlrepo
 
Puppetcamp r10kyaml
Puppetcamp r10kyamlPuppetcamp r10kyaml
Puppetcamp r10kyaml
 
2021 04-15 operational verification (with notes)
2021 04-15 operational verification (with notes)2021 04-15 operational verification (with notes)
2021 04-15 operational verification (with notes)
 
Puppet camp vscode
Puppet camp vscodePuppet camp vscode
Puppet camp vscode
 
Modules of the twenties
Modules of the twentiesModules of the twenties
Modules of the twenties
 
Applying Roles and Profiles method to compliance code
Applying Roles and Profiles method to compliance codeApplying Roles and Profiles method to compliance code
Applying Roles and Profiles method to compliance code
 
KGI compliance as-code approach
KGI compliance as-code approachKGI compliance as-code approach
KGI compliance as-code approach
 
Enforce compliance policy with model-driven automation
Enforce compliance policy with model-driven automationEnforce compliance policy with model-driven automation
Enforce compliance policy with model-driven automation
 
Keynote: Puppet camp compliance
Keynote: Puppet camp complianceKeynote: Puppet camp compliance
Keynote: Puppet camp compliance
 
Automating it management with Puppet + ServiceNow
Automating it management with Puppet + ServiceNowAutomating it management with Puppet + ServiceNow
Automating it management with Puppet + ServiceNow
 
Puppet: The best way to harden Windows
Puppet: The best way to harden WindowsPuppet: The best way to harden Windows
Puppet: The best way to harden Windows
 
Simplified Patch Management with Puppet - Oct. 2020
Simplified Patch Management with Puppet - Oct. 2020Simplified Patch Management with Puppet - Oct. 2020
Simplified Patch Management with Puppet - Oct. 2020
 
Accelerating azure adoption with puppet
Accelerating azure adoption with puppetAccelerating azure adoption with puppet
Accelerating azure adoption with puppet
 
Puppet catalog Diff; Raphael Pinson
Puppet catalog Diff; Raphael PinsonPuppet catalog Diff; Raphael Pinson
Puppet catalog Diff; Raphael Pinson
 
ServiceNow and Puppet- better together, Kevin Reeuwijk
ServiceNow and Puppet- better together, Kevin ReeuwijkServiceNow and Puppet- better together, Kevin Reeuwijk
ServiceNow and Puppet- better together, Kevin Reeuwijk
 
Take control of your dev ops dumping ground
Take control of your  dev ops dumping groundTake control of your  dev ops dumping ground
Take control of your dev ops dumping ground
 
100% Puppet Cloud Deployment of Legacy Software
100% Puppet Cloud Deployment of Legacy Software100% Puppet Cloud Deployment of Legacy Software
100% Puppet Cloud Deployment of Legacy Software
 
Puppet User Group
Puppet User GroupPuppet User Group
Puppet User Group
 
Continuous Compliance and DevSecOps
Continuous Compliance and DevSecOpsContinuous Compliance and DevSecOps
Continuous Compliance and DevSecOps
 
The Dynamic Duo of Puppet and Vault tame SSL Certificates, Nick Maludy
The Dynamic Duo of Puppet and Vault tame SSL Certificates, Nick MaludyThe Dynamic Duo of Puppet and Vault tame SSL Certificates, Nick Maludy
The Dynamic Duo of Puppet and Vault tame SSL Certificates, Nick Maludy
 

Kürzlich hochgeladen

Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 

Kürzlich hochgeladen (20)

Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 

PuppetConf 2017: Puppet Tasks: Taming ssh in a "for" loop- Alex Dreyer, Puppet

  • 1. Puppet Tasks: Taming SSH in a for loop
 Alex Dreyer Principal Software Engineer 
 Puppet
  • 2. Agenda 1. About Tasks 2. Writing Tasks 3. Writing Plans
  • 3. Why Tasks ! Live discovery or debugging across nodes ! Actions that don’t relate to desired state. ! Intermediate state during complex deploys ! Immediacy Puppet’s declarative model isn’t enough
  • 4. What are tasks A task is a single action you can take on a node ! Tasks are scripts or executables written in any language ! Tasks are packaged in puppet modules ! Tasks are copied to and executed on the target
  • 5. bolt vs puppet-task ! Bolt is OS vs puppet-task is PE ! Bolt is a ruby command line tool it loads tasks from the local disk ! puppet-task is a lightweight client for the orchestrator API ! Both should be functionally equivalent for running tasks where possible Task Runners
  • 6. Bolt vs Orchestrator Bolt ! Bolt is commandline application ! Bolt does not require puppet ! Bolt can run plans ! Bolt code is installed locally ! Bolt uses ssh and winrm to connect to nodes Orchestrator ! Orchestrator is a service with multiple clients(puppet-task, PE GUI) ! Orchestrator run s on a PE master and agents on all nodes ! Orchestrator does not support plans yet ! Orchestrator uses code installed on the master ! Orchestrator sends messages to the pxp- agent running on nodes Differences between the two task runners
  • 7.
  • 8. Simple tasks ! Task parameters are passed as environment variables prefixed with PT_ ! Version and deploy this with normal code management tools ! Grant PE rbac permissions and run the task in the console. ! Interact with your own simple scripts just like complex tasks from the Puppet Forge Tasks are easy! #!/usr/bin/env bash touch $PT_file
  • 9. Running tasks in the CLI ! "task" is the puppet or bolt subcommand ! "run" is the action ! "--nodes master.vm" is the target ! "touch" is the task to run ! "file=/tmp/foo" is the parameter to the task ! "--modules=./" puppet task run --nodes master.vm touch file=/tmp/foo bolt task run --nodes master.vm touch file=/tmp/foo --modules=./
  • 10. Task Names ! A full task name has two parts: <module_name>::<task_name> ! Task names do not include the file extension ! Task names must match the puppet class name regex: /A[a-z][a-z0-9_]*Z/ ! The init task's name is just <module_name> like the init class ! Task files must be at the top level of the tasks directory ! There must be only one task with any name
  • 11. JSON Task API ! Accept typed or complex input without special parsing ! Return structured data that can be processed later ! Generate better errors and messages ! Even for simple tasks the Task Runner coerces their output in JSON
  • 12. Using Structured Input ! A single JSON object will be passed to the task on stdin ! Parameter names must match the puppet parameter regex ! Don't treat absence and null values differently ! Use --params to pass typed JSON on the CLI
  • 13. Structured input 1 #!/opt/puppetlabs/puppet/bin/ruby 2 #touch/tasks/array.rb 3 4 require 'json' 5 require 'fileutils' 6 7 params = JSON.parse(STDIN.read) 8 9 params['files'].each do |filename| 10 FileUtils.touch(filename) 11 puts "Updated file #{filename}" 12 end
  • 14. Generating Structured output ! Print only a single JSON object to stdout ! Use only keys that match the parameter regex ! It's best to have defined keys at the top level ! Use standard '_' prefixed keys when appropriate. ! Use the '_output' key for a human readable summary of the result
  • 15. 1 #!/opt/puppetlabs/puppet/bin/ruby 2 #touch/tasks/output.rb 3 require 'json' 4 require 'fileutils' 5 6 params = JSON.parse(STDIN.read) 7 file_result = params['files'].reduce({}) do |files, filename| 8 files[filename] = {} 9 files[filename]['new'] = !File.exists?(filename) 10 FileUtils.touch(filename) 11 files[filename]['success'] = true 12 files 13 end 14 15 result = { '_output' => "Successfully touched all files.", 16 'files' => file_result } 17 STDOUT.puts(result.to_json)
  • 16. Handling errors ! Put errors in an '_error' object ! Exit non-zero for errors ! Use 'msg' in the object for the error message ! Use 'kind' in the object like an error class. ! Use 'details' for any structured information. ! Try to catch all errors otherwise you have no control over the error object { "msg": "Failed to update file: '/tmp/foo'", "kind": "touch/file-error", "details": { "file": "/tmp/foo" } }
  • 17. 2 # touch/tasks/error.rb .. 9 exitcode = 0 10 result = {} 11 result['files'] = params['files'].reduce({}) do |files, filename| 12 begin .. 16 rescue StandardError => e 17 exitcode = 1 18 files[filename]['success'] = false 19 files[filename]['error'] = e.message 20 end 21 files 22 end 23 if exitcode == 0 24 result['_output'] = "Successfully touched all files." 25 STDOUT.puts(result.to_json) 26 else 27 errored_files = result.map { |filename, r| filename unless r[:success] }.compact 28 STDOUT.puts({ _error: { kind: 'touch/file-error', 29 msg: "Failed to update files: #{errored_files.join(',')}", 30 details: { files: result['files'] } } }.to_json) 31 end 32 exit exitcode
  • 18. Task Metadata ! Tasks with metadata are self documenting ! Tasks with metadata can have auto-generated Interfaces ! The Task runner will validate parameters against metadata ! Metadata can change how the task is executed ! Metadata can be used to enable features like noop { "description": "touch files on the target system", "input_method": "stdin", "supports_noop": true, "parameters": { "files": { "description": "An array of files to touch", "type": "Array[String]" } } }
  • 19. --noop ! Tasks that support noop can be safely run in noop mode as a simulation ! When the task is called with '--noop' "_noop": true is sent with the params ! The author must make sure that no state on the system is changed when that flag is present ! Tasks that don't set "supports_noop" in metadata will not be run when a noop run is requested 2 # touch/tasks/noop.rb 16 if params['_noop'] 17 raise StandardError "#{filename} isn't writable" unless File.writable?(filename) 18 dirname = File.basename(filename) 19 raise StandardError "Directory #{dirname} does not exist." unless File.directory?(dirname) 20 else 21 FileUtils.touch(filename) 22 files[filename]['success'] = true 23 end
  • 20. Tasks on windows Task execution program is hardcoded Extension Program .rb Puppet agent ruby .pp puppet agent apply .ps1 powershell
  • 21. 1 #.DESCRIPTION 2 #Updates the write time on a list of files similar to the 'touch' command. 3 # 4 #.PARAMETER files 5 #The files to touch 6 [CmdletBinding()] 7 Param( 8 [Parameter(Mandatory=$true,Position=1)] 9 [String[]] $files 10 ) 11 12 $ErrorActionPreference = "Stop" 13 $fileresults = @{ } 14 15 ForEach ($file in $files) { 16 if(Test-Path $file) { 17 (Get-Item $file).LastWriteTime = Get-Date 18 $fileresults.add($file, @{ "success" = [bool]$true; "new" = [bool]$true }) 19 } else { 20 echo $null > $file 21 $fileresults.add($file, @{ "success" = [bool]$true; "new" = [bool]$false }) 22 }} 23 ConvertTo-Json -InputObject @{ "files" = $fileresults }
  • 22. Puppet manifest tasks ! Puppet manifest can be applied as tasks ! Powerful tool for cross platform tasks ! Code needs to installed in the configured environment on the target ! Beware of conflicts and concat 1 #!/opt/puppetlabs/bin/puppet apply 2 $pkg = case $::osfamily { 3 'redhat': 'httpd', 4 'debian': 'apache2'} 5 package {$pkg: ensure => present }
  • 23. Writing tasks for PE RBAC ! Grant permissions for specific tasks ! Use the type system and pattern type restrictively to prevent injections ! Create versions of tasks with fewer parameters ! Create versions of tasks that refuse to run on some nodes
  • 24. Testing Tasks ! Use the unit testing library for the language you're working in. ! Use beaker to automate system level testing with a Task Runner
  • 25. Tasks Plans ! The Plan language allows you to string tasks together ! Task plans are written in puppet language ! Task plans are executed top to bottom unlike puppet manifest ! Task plans call tasks with the run_task function ! Tasks plans are experimental and only available in bolt
  • 26. run_task ! Create a plan object at the top scope of your plan ! Use the run_task function to call tasks plan touch::promote([String] $tier = 'dev') { $node = "db.${tier}.vm" run_task('touch::noop', [$node], 'files' => ['/etc/postgres/trigger']) }
  • 27. 1 plan canary::random( 2 String $task, 3 String $nodes, 4 Hash[String, Data] $params = {}, 5 Integer $canary_size = 1 6 ) { 7 [$canaries, $rest] = canary::random_split($nodes.split(','), $canary_size) 8 9 $canr = run_task($task, $canaries, $params) 10 if($canr.ok) { 11 util::print("Successfully deployed to canaries: ${canr.names}") 12 $restr = run_task($task, $rest, $params) 13 } else { 14 util::print("Deploy to canaries failed: ${canr.error_nodes.names}") 15 $restr = canary::skip($rest) 16 } 17 18 canary::merge($canr, $restr) 19 }
  • 28. Extending Task Plans ! The Plan language is very small limited but there are a few extension points ! Tasks: Use tasks to capture anything you don't want to write in ruby or puppet. Run tasks locally to send notifications or collect data. ! Functions: Use functions especially functions on ExecutionResult and Error objects ! Plans: Call plans from other other plans with run_plan. Use this to capture generic actions like canary deployments.
  • 29. Plans and PE ! In addition to running plans over ssh and winrm bolt supports using orchestrator as a transport for running tasks. ! Install bolt ! Make sure puppet-task works, bolt will use the same config ~/.puppetlabs/client-tools/ orch.conf ! Make sure any tasks you need are available both in the production environment of your master and in the --modules dir bolt is using ! If you want to run scripts, run commands or upload files make sure bolt is installed as a module in the production environment of your master too. It has a single bolt task used for these ! use the 'pcp' protocol to use orchestrator. ie --nodes pcp://agent1.example.com
  • 30. Resources ! Code: https://github.com/adreyer/puppetconf-modules ! Task Tutorial: https://github.com/puppetlabs/tasks-hands-on-lab ! More content: https://github.com/puppetlabs/task-modules ! Forge: https://forge.puppet.com/modules?with_tasks=yes ! Docs: https://puppet.com/docs/bolt/0.5/writing_tasks_and_plans.html ! Slack: #puppet-tasks ! November Virtual PUG