Skip to content

Instantly share code, notes, and snippets.

@nicklewis
Last active September 6, 2018 01:27
Show Gist options
  • Save nicklewis/bc3bbbfc45b8171665fcb39c63e04ba0 to your computer and use it in GitHub Desktop.
Save nicklewis/bc3bbbfc45b8171665fcb39c63e04ba0 to your computer and use it in GitHub Desktop.
A Bolt plan to show aggregated package versions, using only built-in content.
# Example:
# $ bolt plan run package_versions nodes=foo.example.com,bar.example.com,baz.example.com package=openssl
# Starting: plan package_versions
# Finished: plan package_versions in 7.62 sec
# {
# "1:1.0.2k-12.el7": [
# "foo.example.com",
# "bar.example.com"
# ],
# "1:1.0.2k-8.el7": [
# "baz.example.com"
# ]
# }
plan package_versions(
TargetSpec $nodes,
String $package
) {
# Tell Bolt not to log "starting task [...]" for cleaner output
without_default_logging() || {
# Install the puppet-agent package on the hosts, which is required in order
# to use the built-in package task.
$nodes.apply_prep
# Gather the package version on all hosts. This uses the built-in package
# task, which depends on having puppet installed on the targets.
# Alternately, you could write a package task in another language, or just
# do run_command() here.
$results = run_task(package, $nodes, action => status, name => $package)
# Group hosts by package version and return the result
return aggregate::nodes($results)['version']
}
}
# Example:
# $ bolt plan run package_versions nodes=foo.example.com,bar.example.com,baz.example.com package=openssl
# Starting: plan package_versions
# Starting: command 'rpm -qa openssl --qf %{epoch}:%{version}-%{release}' on foo.example.com, bar.example.com, baz.example.com
# Finished: command 'rpm -qa openssl --qf %{epoch}:%{version}-%{release}' with 0 failures in 1.06 sec
# Finished: plan test::package_version in 1.07 sec
# {
# "1:1.0.2k-12.el7": [
# "foo.example.com",
# "bar.example.com"
# ],
# "1:1.0.2k-8.el7": [
# "baz.example.com"
# ]
# }
plan package_versions(
TargetSpec $nodes,
String $package
) {
# Gather the package version on all hosts
$results = run_command("rpm -qa ${package} --qf %{epoch}:%{version}-%{release}", $nodes)
# Aggregate the stdout
return aggregate::nodes($results)['stdout']
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment