Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support --tags for triggering puppet agent #732

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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[Variant[String[1],Array[String[1]]]]`

Optional tag or array of tags 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[Variant[String[1],Array[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[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
Expand Down Expand Up @@ -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,
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 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"],
Expand Down
6 changes: 5 additions & 1 deletion tasks/run.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
Loading