Skip to content

Commit 2ac3a76

Browse files
committed
support --tags for triggering puppet agent
1 parent 05715a1 commit 2ac3a76

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

REFERENCE.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,6 +1051,12 @@ Data type: `Optional[String[1]]`
10511051

10521052
The desired puppet code environment to use
10531053

1054+
##### `tags`
1055+
1056+
Data type: `Optional[String[1]]`
1057+
1058+
Optional string that will be passed to --tags
1059+
10541060
### <a name="version"></a>`version`
10551061

10561062
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:
10831089
* [`targets`](#-puppet_agent--run--targets)
10841090
* [`noop`](#-puppet_agent--run--noop)
10851091
* [`environment`](#-puppet_agent--run--environment)
1092+
* [`tags`](#-puppet_agent--run--tags)
10861093

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

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

11071114
Default value: `undef`
11081115

1116+
##### <a name="-puppet_agent--run--tags"></a>`tags`
1117+
1118+
Data type: `Optional[String[1]]`
1119+
1120+
an optional string that will be passed to --tags
1121+
1122+
Default value: `undef`
1123+

plans/run.pp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
# @param targets The targets to start a Puppet agent run on.
44
# @param noop if true, all runs will use --noop
55
# @param environment the desired puppet code environment
6+
# @param tags an optional string that will be passed to --tags
67
plan puppet_agent::run (
78
TargetSpec $targets,
89
Boolean $noop = false,
910
Optional[String[1]] $environment = undef,
11+
Optional[String[1]] $tags = undef
1012
) {
1113
# Check which targets have the agent installed by checking
1214
# the version of the agent. No point in trying to run the
@@ -65,7 +67,11 @@
6567
true => { 'noop' => true, },
6668
default => {},
6769
}
68-
$args = $arg_env + $arg_noop + { '_catch_errors' => true }
70+
$arg_tags = $tags ? {
71+
true => { 'tags' => $tags },
72+
default => {},
73+
}
74+
$args = $arg_env + $arg_noop + $arg_tags + { '_catch_errors' => true }
6975
$run_results = run_task(
7076
'puppet_agent::run',
7177
$agent_results.targets,

tasks/run.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
"environment": {
1010
"description": "The desired puppet code environment to use",
1111
"type": "Optional[String[1]]"
12+
},
13+
"tags": {
14+
"description": "Optional string that will be passed to --tags",
15+
"type": "Optional[Variant[String[1],Array[String[1]]]]"
1216
}
1317
},
1418
"files": ["puppet_agent/files/rb_task_helper.rb"],

tasks/run.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ def noop(params)
141141
(params['noop'] == true) ? '--noop' : ''
142142
end
143143

144+
def tags(params)
145+
(params['tags'] && !params['tags'].empty?) ? "--tags=#{[params['tags']].join(',')}" : ''
146+
end
147+
144148
def environment(params)
145149
(params['environment'] && !params['environment'].empty?) ? "--environment=#{params['environment']}" : ''
146150
end
@@ -150,7 +154,7 @@ def environment(params)
150154
def try_run(last_run_report, params)
151155
start_time = get_start_time(last_run_report)
152156

153-
command = [puppet_bin, 'agent', '-t', '--color', 'false', noop(params), environment(params)]
157+
command = [puppet_bin, 'agent', '-t', '--color', 'false', noop(params), environment(params), tags(params)]
154158

155159
options = {
156160
failonfail: false,

0 commit comments

Comments
 (0)