diff --git a/REFERENCE.md b/REFERENCE.md index a6839cb2..cb647556 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -1051,6 +1051,12 @@ Data type: `Optional[String[1]]` The desired puppet code environment to use +##### `tags` + +Data type: `Optional[Variant[String[1],Array[String[1]]]]` + +Optional tag or array of tags that will be passed to --tags + ### `version` Get the version of the Puppet agent package installed. Returns nothing if none present. @@ -1083,6 +1089,7 @@ The following parameters are available in the `puppet_agent::run` plan: * [`targets`](#-puppet_agent--run--targets) * [`noop`](#-puppet_agent--run--noop) * [`environment`](#-puppet_agent--run--environment) +* [`tags`](#-puppet_agent--run--tags) ##### `targets` @@ -1106,3 +1113,11 @@ the desired puppet code environment Default value: `undef` +##### `tags` + +Data type: `Optional[Variant[String[1],Array[String[1]]]]` + +an optional string that will be passed to --tags + +Default value: `undef` + diff --git a/plans/run.pp b/plans/run.pp index 8c56845c..97b45512 100644 --- a/plans/run.pp +++ b/plans/run.pp @@ -3,10 +3,12 @@ # @param targets The targets to start a Puppet agent run on. # @param noop if true, all runs will use --noop # @param environment the desired puppet code environment +# @param tags an optional string that will be passed to --tags plan puppet_agent::run ( TargetSpec $targets, Boolean $noop = false, Optional[String[1]] $environment = undef, + Optional[Variant[String[1],Array[String[1]]]] $tags = undef ) { # Check which targets have the agent installed by checking # the version of the agent. No point in trying to run the @@ -65,7 +67,11 @@ true => { 'noop' => true, }, default => {}, } - $args = $arg_env + $arg_noop + { '_catch_errors' => true } + $arg_tags = $tags ? { + Undef => {}, + default => { 'tags' => $tags }, + } + $args = $arg_env + $arg_noop + $arg_tags + { '_catch_errors' => true } $run_results = run_task( 'puppet_agent::run', $agent_results.targets, diff --git a/tasks/run.json b/tasks/run.json index 1e162d77..e2447b8d 100644 --- a/tasks/run.json +++ b/tasks/run.json @@ -9,6 +9,10 @@ "environment": { "description": "The desired puppet code environment to use", "type": "Optional[String[1]]" + }, + "tags": { + "description": "Optional tag or array of tags that will be passed to --tags", + "type": "Optional[Variant[String[1],Array[String[1]]]]" } }, "files": ["puppet_agent/files/rb_task_helper.rb"], diff --git a/tasks/run.rb b/tasks/run.rb index d3037dea..4f6aadae 100755 --- a/tasks/run.rb +++ b/tasks/run.rb @@ -149,6 +149,10 @@ def noop(params) (params['noop'] == true) ? '--noop' : '' end + def tags(params) + (params['tags'] && !params['tags'].empty?) ? "--tags=#{[params['tags']].join(',')}" : '' + end + def environment(params) (params['environment'] && !params['environment'].empty?) ? "--environment=#{params['environment']}" : '' end @@ -158,7 +162,7 @@ def environment(params) def try_run(last_run_report, params) start_time = get_start_time(last_run_report) - command = [puppet_bin, 'agent', '-t', '--color', 'false', noop(params), environment(params)] + command = [puppet_bin, 'agent', '-t', '--color', 'false', noop(params), environment(params), tags(params)] options = { failonfail: false,