Class: Lita::Handlers::Puppet
Instance Method Summary
collapse
#agent_command, #as_code, #class_camel, #r10k_command, #sanitze_for_chat
#calculate_result, #over_ssh, #simple_ssh_command
#class_nodes, #db_connect, #node_info, #node_roles_and_profiles, #query_fact
Instance Method Details
#cert_clean(response) ⇒ Object
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/lita/handlers/puppet.rb', line 69
def cert_clean(response)
cert = response.matches[0][3]
response.reply_with_mention(t('replies.cert_clean.working'))
result = cert_clean_result(config.master_hostname, config.ssh_user, cert)
if result[:exception]
fail_message response, t('replies.cert_clean.failure'), result[:exception].message
else
success_message(
response,
t('replies.cert_clean.success'),
(result[:stdout] + result[:stderr]).join("\n")
)
end
end
|
#node_facts(response) ⇒ Object
144
145
146
147
148
149
150
151
152
153
154
155
|
# File 'lib/lita/handlers/puppet.rb', line 144
def node_facts(response)
host = response.matches[0][2]
fact = response.matches[0][3]
result = query_fact(host, fact)
if result.nil?
response.reply_with_mention(
t('replies.node_facts.error', host: host)
)
else
response.reply result
end
end
|
#node_profiles(response) ⇒ Object
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
# File 'lib/lita/handlers/puppet.rb', line 106
def node_profiles(response)
host = response.matches[0][2]
what = response.matches[0][1]
response.reply_with_mention(t('replies.node_profiles.working'))
profiles = node_roles_and_profiles(what, host)
if profiles.is_a? String
fail_message response, t('replies.node_profiles.failure', error: profiles)
elsif profiles == []
fail_message response, t('replies.node_profiles.failure_no_roles', host: host)
else
success_message(
response,
t('replies.node_profiles.success', things: what, host: host),
profiles.join("\n")
)
end
end
|
#nodes_info(response) ⇒ Object
157
158
159
160
161
162
163
164
165
166
167
|
# File 'lib/lita/handlers/puppet.rb', line 157
def nodes_info(response)
host = response.matches[0][1]
result = node_info(host)
if result.nil?
response.reply_with_mention(
t('replies.nodes_info.error', host: host)
)
else
response.reply result
end
end
|
#nodes_with_class(response) ⇒ Object
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
# File 'lib/lita/handlers/puppet.rb', line 127
def nodes_with_class(response)
puppet_class = response.matches[0][3]
response.reply_with_mention(t('replies.nodes_with_class.working'))
puppet_classes = class_nodes(class_camel(puppet_class))
if puppet_classes.empty?
fail_message response, t('replies.nodes_with_class.failure', pclass: puppet_class)
else
success_message(
response,
t('replies.nodes_with_class.success', pclass: puppet_class),
puppet_classes.join("\n")
)
end
end
|
#puppet_agent_run(response) ⇒ Object
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
# File 'lib/lita/handlers/puppet.rb', line 87
def puppet_agent_run(response)
host = response.matches[0][4]
response.reply_with_mention(t('replies.puppet_agent_run.working'))
result = simple_ssh_command(host, config.ssh_user, agent_command)
if result[:exception]
fail_message response, t('replies.puppet_agent_run.failure'), result[:exception].message
else
success_message(
response,
t('replies.puppet_agent_run.success', status: result[:exit_status]),
result[:stdout].join("\n")
)
end
end
|
#r10k_deploy(response) ⇒ Object
rubocop:disable Metrics/AbcSize
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
|
# File 'lib/lita/handlers/puppet.rb', line 170
def r10k_deploy(response)
environment = response.matches[0][3]
mod = response.matches[0][5]
user = config.ssh_user
response.reply_with_mention(t('replies.r10k_deploy.working'))
result = simple_ssh_command(config.master_hostname, user, r10k_command(environment, mod))
if result[:exception]
fail_message response, t('replies.r10k_deploy.failure'), result[:exception].message
else
success_message(
response,
t('replies.r10k_deploy.success'),
[result[:stdout].join("\n"), result[:stderr].join("\n")].join("\n")
)
end
end
|