diff --git a/REFERENCE.md b/REFERENCE.md index a6839cb2..bdaba6f1 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[String[1]]` + +Optional string 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[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..2c049a2c 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[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 ? { + true => { 'tags' => $tags }, + default => {}, + } + $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..ac13be53 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 string that will be passed to --tags", + "type": "Optional[Array[String[1]]]" } }, "files": ["puppet_agent/files/rb_task_helper.rb"], diff --git a/tasks/run.rb b/tasks/run.rb index bdf429cf..8671ce91 100755 --- a/tasks/run.rb +++ b/tasks/run.rb @@ -141,6 +141,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 @@ -150,7 +154,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,