Skip to content

Commit

Permalink
support --tags for triggering puppet agent
Browse files Browse the repository at this point in the history
  • Loading branch information
bastelfreak committed Nov 21, 2024
1 parent 26310e3 commit 71c2024
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
15 changes: 15 additions & 0 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

### <a name="version"></a>`version`

Get the version of the Puppet agent package installed. Returns nothing if none present.
Expand Down Expand Up @@ -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)

##### <a name="-puppet_agent--run--targets"></a>`targets`

Expand All @@ -1106,3 +1113,11 @@ the desired puppet code environment

Default value: `undef`

##### <a name="-puppet_agent--run--tags"></a>`tags`

Data type: `Optional[String[1]]`

an optional string that will be passed to --tags

Default value: `undef`

8 changes: 7 additions & 1 deletion plans/run.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions tasks/run.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
6 changes: 5 additions & 1 deletion tasks/run.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down

0 comments on commit 71c2024

Please sign in to comment.