1metadata :name => "puppet",
2         :description => "Run Puppet agent, get its status, and enable/disable it",
3         :author => "R.I.Pienaar <rip@devco.net>",
4         :license => "ASL2.0",
5         :version => "1.14.0",
6         :url => "https://github.com/puppetlabs/mcollective-puppet-agent",
7         :timeout => 20
8
9requires :mcollective => "2.2.1"
10
11action "resource", :description => "Evaluate Puppet RAL resources" do
12    display :always
13
14    input :name,
15          :prompt      => "Name",
16          :description => "Resource Name",
17          :type        => :string,
18          :validation  => '^.+$',
19          :optional    => false,
20          :maxlength   => 150
21
22    input :type,
23          :prompt      => "Type",
24          :description => "Resource Type",
25          :type        => :string,
26          :validation  => '^.+$',
27          :optional    => false,
28          :maxlength   => 50
29
30    output :result,
31           :description => "The result from the Puppet resource",
32           :display_as  => "Result",
33           :default     => ""
34
35    output :changed,
36           :description => "Was a change applied based on the resource",
37           :display_as  => "Changed",
38           :default     => nil
39
40    summarize do
41        aggregate boolean_summary(:changed, {:true => "Changed", :false => "No Change"})
42    end
43end
44
45action "disable", :description => "Disable the Puppet agent" do
46    input :message,
47          :prompt      => "Message",
48          :description => "Supply a reason for disabling the Puppet agent",
49          :type        => :string,
50          :validation  => :shellsafe,
51          :optional    => true,
52          :maxlength   => 120
53
54    output :status,
55           :description => "Status",
56           :display_as  => "Status",
57           :default     => ""
58
59    output :enabled,
60           :description => "Is the agent currently locked",
61           :display_as  => "Enabled"
62
63    summarize do
64        aggregate boolean_summary(:enabled, {:true => "enabled", :false => "disabled"})
65    end
66end
67
68action "enable", :description => "Enable the Puppet agent" do
69    output :status,
70           :description => "Status",
71           :display_as  => "Status",
72           :default     => ""
73
74    output :enabled,
75           :description => "Is the agent currently locked",
76           :display_as  => "Enabled"
77
78    summarize do
79        aggregate boolean_summary(:enabled, {:true => "enabled", :false => "disabled"})
80    end
81end
82
83action "last_run_summary", :description => "Get the summary of the last Puppet run" do
84    display :always
85
86    input  :logs,
87           :description => "Whether or not to parse the logs from last_run_report.yaml",
88           :prompt      => "Parse log from last_run_report.yaml",
89           :optional    => true,
90           :type        => :boolean,
91           :default     => false
92
93    output :out_of_sync_resources,
94           :description => "Resources that were not in desired state",
95           :display_as  => "Out of Sync Resources",
96           :default     => -1
97
98    output :failed_resources,
99           :description => "Resources that failed to apply",
100           :display_as  => "Failed Resources",
101           :default     => -1
102
103    output :corrected_resources,
104           :description => "Resources that were correctively changed",
105           :display_as  => "Corrected Resources",
106           :default     => -1
107
108    output :changed_resources,
109           :description => "Resources that were changed",
110           :display_as  => "Changed Resources",
111           :default     => -1
112
113    output :total_resources,
114           :description => "Total resources managed on a node",
115           :display_as  => "Total Resources",
116           :default     => 0
117
118    output :config_retrieval_time,
119           :description => "Time taken to retrieve the catalog from the master",
120           :display_as  => "Config Retrieval Time",
121           :default     => -1
122
123    output :total_time,
124           :description => "Total time taken to retrieve and process the catalog",
125           :display_as  => "Total Time",
126           :default     => 0
127
128    output :logs,
129           :description => "Log lines from the last Puppet run",
130           :display_as  => "Last Run Logs",
131           :default     => {}
132
133    output :lastrun,
134           :description => "When the Agent last applied a catalog in local time",
135           :display_as  => "Last Run",
136           :default     => 0
137
138    output :since_lastrun,
139           :description => "How long ago did the Agent last apply a catalog in local time",
140           :display_as  => "Since Last Run",
141           :default     => "Unknown"
142
143    output :config_version,
144           :description => "Puppet config version for the previously applied catalog",
145           :display_as  => "Config Version",
146           :default     => nil
147
148    output :type_distribution,
149           :description => "Resource counts per type managed by Puppet",
150           :display_as  => "Type Distribution",
151           :default     => {}
152
153    output :summary,
154           :description => "Summary data as provided by Puppet",
155           :display_as  => "Summary",
156           :default     => {}
157
158    summarize do
159        aggregate average(:config_retrieval_time, :format => "Average: %0.2f")
160        aggregate average(:total_time, :format => "Average: %0.2f")
161        aggregate average(:total_resources, :format => "Average: %d")
162    end
163end
164
165action "status", :description => "Get the current status of the Puppet agent" do
166    display :always
167
168    output :applying,
169           :description => "Is a catalog being applied",
170           :display_as  => "Applying",
171           :default     => false
172
173    output :idling,
174           :description => "Is the Puppet agent daemon running but not doing any work",
175           :display_as  => "Idling",
176           :default     => false
177
178    output :enabled,
179           :description => "Is the agent currently locked",
180           :display_as  => "Enabled"
181
182    output :daemon_present,
183           :description => "Is the Puppet agent daemon running on this system",
184           :display_as  => "Daemon Running",
185           :default     => false
186
187    output :lastrun,
188           :description => "When the Agent last applied a catalog in local time",
189           :display_as  => "Last Run",
190           :default     => 0
191
192    output :since_lastrun,
193           :description => "How long ago did the Agent last apply a catalog in local time",
194           :display_as  => "Since Last Run",
195           :default     => "Unknown"
196
197    output :status,
198           :description => "Current status of the Puppet agent",
199           :display_as  => "Status",
200           :default     => "unknown"
201
202    output :disable_message,
203           :description => "Message supplied when agent was disabled",
204           :display_as  => "Lock Message",
205           :default     => ""
206
207    output :message,
208           :description => "Descriptive message defining the overall agent status",
209           :display_as  => "Message",
210           :default     => "unknown"
211
212    summarize do
213        aggregate boolean_summary(:enabled, {:true => "enabled", :false => "disabled"})
214        aggregate boolean_summary(:daemon_present, {:true => "running", :false => "stopped"})
215        aggregate summary(:applying)
216        aggregate summary(:status)
217        aggregate summary(:idling)
218    end
219end
220
221action "runonce", :description => "Invoke a single Puppet run" do
222    input :force,
223          :prompt      => "Force",
224          :description => "Will force a run immediately else subject to default splay time",
225          :type        => :boolean,
226          :optional    => true
227
228    input :server,
229          :prompt      => "Puppet Master",
230          :description => "Address and port of the Puppet Master in server:port format",
231          :type        => :string,
232          :validation  => :puppet_server_address,
233          :optional    => true,
234          :maxlength   => 50
235
236    input :tags,
237          :prompt      => "Tags",
238          :description => "Restrict the Puppet run to a comma list of tags",
239          :type        => :string,
240          :validation  => :puppet_tags,
241          :optional    => true,
242          :maxlength   => 120
243
244    input :noop,
245          :prompt      => "No-op",
246          :description => "Do a Puppet dry run",
247          :type        => :boolean,
248          :optional    => true
249
250    input :splay,
251          :prompt      => "Splay",
252          :description => "Sleep for a period before initiating the run",
253          :type        => :boolean,
254          :optional    => true
255
256    input :splaylimit,
257          :prompt      => "Splay Limit",
258          :description => "Maximum amount of time to sleep before run",
259          :type        => :number,
260          :optional    => true
261
262    input :environment,
263          :prompt      => "Environment",
264          :description => "Which Puppet environment to run",
265          :type        => :string,
266          :validation  => :puppet_variable,
267          :optional    => true,
268          :maxlength   => 50
269
270    input :use_cached_catalog,
271          :prompt      => "Use Cached Catalog",
272          :description => "Determine if to use the cached catalog or not",
273          :type        => :boolean,
274          :optional    => true
275
276    output :summary,
277           :description => "Summary of command run",
278           :display_as  => "Summary",
279           :default     => ""
280
281    output :initiated_at,
282           :description => "Timestamp of when the runonce command was issues",
283           :display_as  => "Initiated at",
284           :default     => 0
285end
286