Skip to content

Commit 161e612

Browse files
committed
2 parents 5bc9bc3 + 3a2f7b0 commit 161e612

18 files changed

Lines changed: 227 additions & 245 deletions

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.
44

55
## Development
66

7+
* **BREAKING CHANGE**
8+
Converted from `nodes` to `targets` for all plans and tasks. This is in support of Bolt `2.0`.
9+
Any calling plans or CLI will need to use the `targets` parameter to pass in the hosts
10+
to be patched. (Feature)
11+
12+
Contributed by Nick Maludy (@nmaludy)
13+
714

815
## Release 0.5.0 (2020-02-20)
916

plans/available_updates.pp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# @summary Checks all nodes for available updates reported by their Operating System.
1+
# @summary Checks all targets for available updates reported by their Operating System.
22
#
33
# This uses the <code>patching::available_updates</code> task to query each Target's
44
# Operating System for available updates. The results from the OS are parsed and formatted
@@ -13,7 +13,7 @@
1313
# - Chocolatey: If installed, runs <code>choco outdated</code>.
1414
# If not installed, Chocolatey is ignored.
1515
#
16-
# @param [TargetSpec] nodes
16+
# @param [TargetSpec] targets
1717
# Set of targets to run against.
1818
# @param [Enum['none', 'pretty', 'csv']] format
1919
# Output format for printing user-friendly information during the plan run.
@@ -31,27 +31,25 @@
3131
# In this case, noop mode has no effect.
3232
#
3333
# @example CLI - Basic Usage
34-
# bolt plan run patching::available_updates --nodes linux_hosts
34+
# bolt plan run patching::available_updates --targets linux_hosts
3535
#
3636
# @example CLI - Get available update information in CSV format for creating reports
37-
# bolt plan run patching::available_updates --nodes linux_hosts format=csv
37+
# bolt plan run patching::available_updates --targets linux_hosts format=csv
3838
#
3939
# @example Plan - Basic Usage
40-
# run_plan('patching::available_updates',
41-
# nodes => $linux_hosts)
40+
# run_plan('patching::available_updates', $linux_hosts)
4241
#
4342
# @example Plan - Get available update information in CSV format for creating reports
44-
# run_plan('patching::available_updates',
45-
# nodes => $linux_hosts,
43+
# run_plan('patching::available_updates', $linux_hosts,
4644
# format => 'csv')
4745
#
4846
plan patching::available_updates (
49-
TargetSpec $nodes,
47+
TargetSpec $targets,
5048
# TODO JSON
5149
Enum['none', 'pretty', 'csv'] $format = 'pretty',
5250
Boolean $noop = false,
5351
) {
54-
$available_results = run_task('patching::available_updates', $nodes,
52+
$available_results = run_task('patching::available_updates', $targets,
5553
_noop => $noop)
5654
case $format {
5755
'none': {

plans/check_online.pp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
# Online checks are done querying for the node's Puppet version using the
44
# <code>puppet_agent::version</code> task.
55
# This plan is designed to be used ad-hoc as a quick health check of your inventory.
6-
# It is the intention of this plan to be used as "first pass" when onboarding new nodes
6+
# It is the intention of this plan to be used as "first pass" when onboarding new targets
77
# into a Bolt rotation.
8-
# One would build their inventory file of all nodes from their trusted data sources.
9-
# Then take the inventory files and run this plan against them to isolate problem nodes
8+
# One would build their inventory file of all targets from their trusted data sources.
9+
# Then take the inventory files and run this plan against them to isolate problem targets
1010
# and remediate them.
1111
# Once this plan runs successfuly on your inventory, you know that Bolt can connect
1212
# and can begin the patching proces.
@@ -24,20 +24,20 @@
2424
# The idea here is to give the end-user a easily digestible summary so that action
2525
# can be taken to remediate these hosts.
2626
#
27-
# @param [TargetSpec] nodes
27+
# @param [TargetSpec] targets
2828
# Set of targets to run against.
2929
#
3030
# @example CLI - Basic usage
3131
# bolt plan run patching::check_online
3232
#
3333
plan patching::check_online (
34-
TargetSpec $nodes,
34+
TargetSpec $targets,
3535
) {
36-
$targets = get_targets($nodes)
37-
## This will check all nodes to verify online by checking their Puppet agent version
38-
$targets_version = run_task('puppet_agent::version', $targets,
36+
$_targets = get_targets($targets)
37+
## This will check all targets to verify online by checking their Puppet agent version
38+
$targets_version = run_task('puppet_agent::version', $_targets,
3939
_catch_errors => true)
40-
# if we're filtering out offline nodes, then only accept the ok_set from the task above
40+
# if we're filtering out offline targets, then only accept the ok_set from the task above
4141
if !$targets_version.error_set.empty() {
4242
$errors_array = Array($targets_version.error_set)
4343
$sorted_errors = $errors_array.sort|$a, $b| {
@@ -61,6 +61,6 @@
6161
fail_plan('Unable to connect to the targets above!')
6262
}
6363
else {
64-
out::message('All nodes succeeded!')
64+
out::message('All targets succeeded!')
6565
}
6666
}

plans/check_puppet.pp

Lines changed: 33 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,64 @@
1-
# @summary Checks each node to see if Puppet is installed, then gather Facts on all nodes.
1+
# @summary Checks each node to see if Puppet is installed, then gather Facts on all targets.
22
#
33
# Executes the <code>puppet_agent::version</code> task to check if Puppet is installed
4-
# on all of the nodes. Once finished, the result is split into two groups:
4+
# on all of the targets. Once finished, the result is split into two groups:
55
#
6-
# 1. Nodes with puppet
7-
# 2. Nodes with no puppet
6+
# 1. Targets with puppet
7+
# 2. Targets with no puppet
88
#
9-
# The nodes with puppet are queried for facts using the <code>patching::puppet_facts</code> plan.
10-
# Nodes without puppet are queried for facts using the simpler <code>facts</code> plan.
9+
# The targets with puppet are queried for facts using the <code>patching::puppet_facts</code> plan.
10+
# Targets without puppet are queried for facts using the simpler <code>facts</code> plan.
1111
#
1212
# This plan is designed to be the first plan executed in a patching workflow.
1313
# It can be used to stop the patching process if any hosts are offline by setting
14-
# <code>filter_offline_nodes=false</code> (default). It can also be used
15-
# to patch any hosts that are currently available and ignoring any offline nodes
16-
# by setting <code>filter_offline_nodes=true</code>.
14+
# <code>filter_offline_targets=false</code> (default). It can also be used
15+
# to patch any hosts that are currently available and ignoring any offline targets
16+
# by setting <code>filter_offline_targets=true</code>.
1717
#
18-
# @param [TargetSpec] nodes
18+
# @param [TargetSpec] targets
1919
# Set of targets to run against.
20-
# @param [Boolean] filter_offline_nodes
21-
# Flag to determine if offline nodes should be filtered out of the list of targets
20+
# @param [Boolean] filter_offline_targets
21+
# Flag to determine if offline targets should be filtered out of the list of targets
2222
# returned by this plan. If true, when running the <code>puppet_agent::version</code>
23-
# check, any nodes that return an error will be filtered out and ignored.
23+
# check, any targets that return an error will be filtered out and ignored.
2424
# Those targets will not be returned in any of the data structures in the result of
25-
# this plan. If false, then any nodes that are offline will cause this plan to error
25+
# this plan. If false, then any targets that are offline will cause this plan to error
2626
# immediately when performing the online check. This will result in a halt of the
2727
# patching process.
2828
#
2929
# @return [Struct[{has_puppet => Array[TargetSpec],
3030
# no_puppet => Array[TargetSpec],
3131
# all => Array[TargetSpec]}]]
3232
#
33-
# @example CLI - Basic usage (error if any nodes are offline)
34-
# bolt plan run patching::check_puppet --nodes linux_hosts
33+
# @example CLI - Basic usage (error if any targets are offline)
34+
# bolt plan run patching::check_puppet --targets linux_hosts
3535
#
36-
# @example CLI - Filter offline nodes (only return online nodes)
37-
# bolt plan run patching::check_puppet --nodes linux_hosts filter_offline_nodes=true
36+
# @example CLI - Filter offline targets (only return online targets)
37+
# bolt plan run patching::check_puppet --targets linux_hosts filter_offline_targets=true
3838
#
39-
# @example Plan - Basic usage (error if any nodes are offline)
40-
# $results = run_plan('patching::check_puppet',
41-
# nodes => $linux_hosts)
39+
# @example Plan - Basic usage (error if any targets are offline)
40+
# $results = run_plan('patching::check_puppet', $linux_hosts)
4241
# $targets_has_puppet = $results['has_puppet']
4342
# $targets_no_puppet = $results['no_puppet']
4443
# $targets_all = $results['all']
4544
#
46-
# @example Plan - Filter offline nodes (only return online nodes)
47-
# $results = run_plan('patching::check_puppet',
48-
# nodes => $linux_hosts,
49-
# filter_offline_nodes => true)
45+
# @example Plan - Filter offline targets (only return online targets)
46+
# $results = run_plan('patching::check_puppet', $linux_hosts,
47+
# filter_offline_targets => true)
5048
# $targets_online_has_puppet = $results['has_puppet']
5149
# $targets_online_no_puppet = $results['no_puppet']
5250
# $targets_online = $results['all']
5351
#
5452
plan patching::check_puppet (
55-
TargetSpec $nodes,
56-
Boolean $filter_offline_nodes = false,
53+
TargetSpec $targets,
54+
Boolean $filter_offline_targets = false,
5755
) {
58-
$targets = get_targets($nodes)
59-
## This will check all nodes to verify online by checking their Puppet agent version
60-
$targets_version = run_task('puppet_agent::version', $targets,
61-
_catch_errors => $filter_offline_nodes)
62-
# if we're filtering out offline nodes, then only accept the ok_set from the task above
63-
if $filter_offline_nodes {
56+
$_targets = get_targets($targets)
57+
## This will check all targets to verify online by checking their Puppet agent version
58+
$targets_version = run_task('puppet_agent::version', $_targets,
59+
_catch_errors => $filter_offline_targets)
60+
# if we're filtering out offline targets, then only accept the ok_set from the task above
61+
if $filter_offline_targets {
6462
$targets_filtered = $targets_version.ok_set
6563
}
6664
else {
@@ -74,13 +72,11 @@
7472
if !$targets_with_puppet.empty() {
7573
# run `puppet facts` on targets with Puppet because it returns a more complete
7674
# set of facts than just running `facter`
77-
run_plan('patching::puppet_facts',
78-
nodes => $targets_with_puppet)
75+
run_plan('patching::puppet_facts', $targets_with_puppet)
7976
}
8077
if !$targets_no_puppet.empty() {
8178
# run `facter` if it's available otherwise get basic facts
82-
run_plan('facts',
83-
nodes => $targets_no_puppet)
79+
run_plan('facts', $targets_no_puppet)
8480
}
8581

8682
return({

plans/deploy_scripts.pp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# TODO support deploying without Puppet on the end node?
44
#
5-
# @param [TargetSpec] nodes
5+
# @param [TargetSpec] targets
66
# Set of targets to run against.
77
#
88
# @param [Hash] scripts
@@ -32,7 +32,7 @@
3232
# @example CLI deploy a pre and post patching script
3333
# bolt plan run patching::deploy_scripts scripts='{"pre_patch.sh": {"source": "puppet:///modules/test/patching/pre_patch.sh"}, "post_patch.sh": {"source": "puppet:///modules/test/patching/post_patch.sh"}}'
3434
plan patching::deploy_scripts(
35-
TargetSpec $nodes,
35+
TargetSpec $targets,
3636
Hash $scripts,
3737
Optional[String] $patching_dir = undef,
3838
Optional[String] $bin_dir = undef,
@@ -41,8 +41,8 @@
4141
Optional[String] $group = undef,
4242
Optional[String] $mode = undef,
4343
) {
44-
$targets = run_plan('patching::get_targets', nodes => $nodes)
45-
return apply($targets) {
44+
$_targets = run_plan('patching::get_targets', $targets)
45+
return apply($_targets) {
4646
include patching::params
4747
class { 'patching':
4848
scripts => $scripts,

plans/get_targets.pp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,34 @@
22
#
33
# A very common requirement when running individual plans from the commandline is that
44
# each plan would need to perform the following steps:
5-
# - Convert the TargetSpec from a string into an Array[Target] using <code>get_targets($nodes)</code>
6-
# - Check for nodes that are online (calls plan <code>patching::check_puppet</code>
7-
# - Gather facts about the nodes
5+
# - Convert the TargetSpec from a string into an Array[Target] using <code>get_targets($targets)</code>
6+
# - Check for targets that are online (calls plan <code>patching::check_puppet</code>
7+
# - Gather facts about the targets
88
#
99
# This plan combines all of that into one so that it can be reused in all of the other
1010
# plans within this module. It also adds some smart checking so that, if multiple plans
1111
# invoke each other, each of which call this plan. The online check and facts gathering
1212
# only hapens once.
1313
#
14-
# @param [TargetSpec] nodes
14+
# @param [TargetSpec] targets
1515
# Set of targets to run against.
1616
#
1717
# @return [Array[Target]] Targets converted to an array for use later in the calling plan
1818
#
1919
# @example Plan - Basic usage
2020
# plan mymodule::myplan (
21-
# TargetSpec $nodes
21+
# TargetSpec $targets
2222
# ) {
23-
# $targets = run_plan('patching::get_targets', nodes => $ndoes)
23+
# $targets = run_plan('patching::get_targets', $targets)
2424
# # do normal stuff with your $targets
2525
# }
2626
plan patching::get_targets (
27-
TargetSpec $nodes,
27+
TargetSpec $targets,
2828
) {
29-
$targets = get_targets($nodes)
30-
$target_first_facts = facts($targets[0])
29+
$_targets = get_targets($targets)
30+
$target_first_facts = facts($_targets[0])
3131
if !$target_first_facts['os'] or !$target_first_facts['os']['family'] {
32-
run_plan('patching::check_puppet', nodes => $targets)
32+
run_plan('patching::check_puppet', $_targets)
3333
}
34-
return $targets
34+
return $_targets
3535
}

0 commit comments

Comments
 (0)