choria-mcorpc-support 2.20.4 → 2.20.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a3f6b0f73405083156308dae503d0498332bc81c
4
- data.tar.gz: 7c780d21ec775ddbc5b17640682be709a343c94b
3
+ metadata.gz: f2b40e519fe1594ef21f3842e4786bdfbe9359f1
4
+ data.tar.gz: ae87678ad14ba3d22805143c59c5558f271286c4
5
5
  SHA512:
6
- metadata.gz: 70b7fb634326c07bf3940692641a4e66b734d2388647186d25080025f019c66ad39b07f4b7d60b90e6a8da7171f6f6dbfbb7f5f79aced3e146149f5cc94828be
7
- data.tar.gz: de2c15f4c16831773119ce0c167d3a17f9b55aa9f3546e0a90b017353879b74b198fd50b65839f251d387c93f3247faf81941bd54c7de4c85958953038da8b8c
6
+ metadata.gz: 92c39adc948b47af880815b13597c4205a4e0dcb3058c82d5e2c8e762cc11a15b7ae15028093bf3a04e9f01458bde03e3a91b678b783fbb49875ea93bbc85786
7
+ data.tar.gz: e49b19a7e16acec11b619e1492ef6e7f3cadb819bf93ac0759889fa1032e53529e7432404b8a10cbde6e8152204e069372d493bf0c6ff908ce87684bfd3add8b
@@ -54,7 +54,7 @@ module MCollective
54
54
  require "mcollective/util"
55
55
  require "mcollective/validator"
56
56
 
57
- VERSION = "2.20.4".freeze
57
+ VERSION = "2.20.5".freeze
58
58
 
59
59
  def self.version
60
60
  VERSION
@@ -36,8 +36,9 @@ class MCollective::Application::Facts<MCollective::Application
36
36
 
37
37
  rpcutil.get_fact(:fact => configuration[:fact]) do |resp|
38
38
  begin
39
- value = resp[:body][:data][:value]
40
- if value
39
+ value = resp[:body][:data][:value].to_s
40
+
41
+ if resp[:body][:data].include?(:value)
41
42
  if facts.include?(value)
42
43
  facts[value] << resp[:senderid]
43
44
  else
@@ -289,7 +289,7 @@ mco plugin package [options] <directory>
289
289
  # Creates the correct package plugin object.
290
290
  def prepare_plugin
291
291
  plugintype = set_plugin_type unless configuration[:plugintype]
292
- configuration[:format] = "ospackage" unless configuration[:format]
292
+ configuration[:format] = "puppet_module" unless configuration[:format]
293
293
  PluginPackager.load_packagers
294
294
  plugin_class = PluginPackager[configuration[:plugintype]]
295
295
 
@@ -0,0 +1,246 @@
1
+ require "yaml"
2
+
3
+ module MCollective
4
+ module PluginPackager
5
+ class PuppetmodulePackager
6
+ def initialize(plugin, pluginpath = nil, signature = nil, verbose = false, keep_artifacts = nil, module_template = nil)
7
+ @plugin = plugin
8
+ @verbose = verbose
9
+ @keep_artifacts = keep_artifacts
10
+ @module_template = module_template || File.join(File.dirname(__FILE__), 'templates', 'puppet_module')
11
+ end
12
+
13
+ def which(cmd)
14
+ exts = ENV["PATHEXT"] ? ENV["PATHEXT"].split(";") : [""]
15
+ ENV["PATH"].split(File::PATH_SEPARATOR).each do |path|
16
+ exts.each do |ext|
17
+ exe = File.join(path, "#{cmd}#{ext}")
18
+ return exe if File.executable?(exe) && !File.directory?(exe)
19
+ end
20
+ end
21
+ return nil
22
+ end
23
+
24
+ def create_packages
25
+ assert_new_enough_puppet
26
+ validate_environment
27
+
28
+ begin
29
+ puts("Building Choria module %s" % module_name)
30
+
31
+ @tmpdir = Dir.mktmpdir("mcollective_packager")
32
+
33
+ make_module_dirs
34
+ copy_module_files
35
+ generate_agent_json_ddls
36
+ render_templates
37
+ copy_additional_files
38
+ run_build
39
+ move_package
40
+
41
+ puts("Completed building module for %s" % module_name)
42
+ rescue
43
+ STDERR.puts("Failed to build plugin module: %s: %s" % [$!.class, $!.to_s])
44
+ ensure
45
+ if @keep_artifacts
46
+ puts("Keeping build artifacts")
47
+ puts("Build artifacts saved in %s" % @tmpdir)
48
+ else
49
+ cleanup_tmpdirs
50
+ end
51
+ end
52
+ end
53
+
54
+ def version
55
+ if Integer(@plugin.revision) > 1
56
+ "%s-%s" % [@plugin.metadata[:version], @plugin.revision]
57
+ else
58
+ @plugin.metadata[:version]
59
+ end
60
+ end
61
+
62
+ def module_name
63
+ "mcollective_%s_%s" % [
64
+ @plugin.plugintype.downcase,
65
+ @plugin.metadata[:name].downcase.gsub("-", "_")
66
+ ]
67
+ end
68
+
69
+ def module_file_name
70
+ "%s-%s-%s.tar.gz" % [@plugin.vendor, module_name, version]
71
+ end
72
+
73
+ def dirlist(type)
74
+ @plugin.packagedata[type][:files].map do |file|
75
+ file.gsub(/^\.\//, "") if File.directory?(file)
76
+ end.compact
77
+ rescue
78
+ []
79
+ end
80
+
81
+ def filelist(type)
82
+ @plugin.packagedata[type][:files].map do |file|
83
+ file.gsub(/^\.\//, "") unless File.directory?(file)
84
+ end.compact
85
+ rescue
86
+ []
87
+ end
88
+
89
+ def hierakey(var)
90
+ "%s::%s" % [module_name, var]
91
+ end
92
+
93
+ def module_override_data
94
+ YAML.safe_load(File.read(".plugin.yaml"))
95
+ rescue
96
+ {}
97
+ end
98
+
99
+ def plugin_hiera_data
100
+ {
101
+ hierakey(:config_name) => @plugin.metadata[:name].downcase,
102
+ hierakey(:common_files) => filelist(:common),
103
+ hierakey(:common_directories) => dirlist(:common),
104
+ hierakey(:server_files) => filelist(:agent),
105
+ hierakey(:server_directories) => dirlist(:agent),
106
+ hierakey(:client_files) => filelist(:client),
107
+ hierakey(:client_directories) => dirlist(:client),
108
+ }.merge(module_override_data)
109
+ end
110
+
111
+ def make_module_dirs
112
+ ["data", "manifests", "files/mcollective"].each do |dir|
113
+ FileUtils.mkdir_p(File.join(@tmpdir, dir))
114
+ end
115
+ end
116
+
117
+ def copy_additional_files
118
+ if File.exist?("puppet")
119
+ Dir.glob("puppet/*").each do |file|
120
+ FileUtils.cp_r(file, @tmpdir)
121
+ end
122
+ end
123
+ end
124
+
125
+ def copy_module_files
126
+ @plugin.packagedata.each do |klass, data|
127
+ data[:files].each do |file|
128
+ clean_dest_file = file.gsub("./lib/mcollective", "")
129
+ dest_dir = File.expand_path(File.join(@tmpdir, "files", "mcollective", File.dirname(clean_dest_file)))
130
+
131
+ FileUtils.mkdir_p(dest_dir) unless File.directory?(dest_dir)
132
+ FileUtils.cp(file, dest_dir) if File.file?(file)
133
+ end
134
+ end
135
+ end
136
+
137
+ def generate_agent_json_ddls
138
+ agent_dir = File.expand_path(File.join(@tmpdir, "files", "mcollective", "agent"))
139
+
140
+ if File.directory?(agent_dir)
141
+ Dir.glob(File.join(agent_dir, "*.ddl")) do |file|
142
+ agent_name = File.basename(file, ".ddl")
143
+ json_file = File.join(agent_dir, "%s.json" % agent_name)
144
+
145
+ ddl = DDL.new(agent_name, :agent, false)
146
+ ddl.instance_eval(File.read(file))
147
+
148
+ data = {
149
+ "$schema" => "https://choria.io/schemas/mcorpc/ddl/v1/agent.json",
150
+ "metadata" => ddl.meta,
151
+ "actions" => [],
152
+ }
153
+
154
+ ddl.actions.sort.each do |action|
155
+ data["actions"] << ddl.action_interface(action)
156
+ end
157
+
158
+ File.open(json_file, "w") do |jddl|
159
+ jddl.print(JSON.pretty_generate(data))
160
+ end
161
+
162
+ @plugin.packagedata[:common][:files] << "agent/%s.json" % agent_name
163
+ end
164
+ end
165
+ end
166
+
167
+ def render_templates
168
+ templates = Dir.chdir(@module_template) do |path|
169
+ Dir.glob("**/*.erb")
170
+ end
171
+
172
+ templates.each do |template|
173
+ infile = File.join(@module_template, template)
174
+ outfile = File.join(@tmpdir, template.gsub(/\.erb$/, ""))
175
+ render_template(infile, outfile)
176
+ end
177
+ end
178
+
179
+ def render_template(infile, outfile)
180
+ begin
181
+ erb = ERB.new(File.read(infile), nil, "-")
182
+ File.open(outfile, "w") do |f|
183
+ f.puts erb.result(binding)
184
+ end
185
+ rescue
186
+ STDERR.puts("Could not render template %s to %s" % [infile, outfile])
187
+ raise
188
+ end
189
+ end
190
+
191
+ def validate_environment
192
+ raise("Supplying a vendor is required, please use --vendor") if @plugin.vendor == "Puppet Labs"
193
+ raise("Vendor names may not have a space in them, please specify a valid vendor using --vendor") if @plugin.vendor.match(" ")
194
+ end
195
+
196
+ def assert_new_enough_puppet
197
+ puppet_bin = which("puppet")
198
+ puppet_bin = "/opt/puppetlabs/bin/puppet" if !puppet_bin
199
+ if !puppet_bin
200
+ raise("Cannot build package. 'puppet' not found on path, and '/opt/puppetlabs/bin/puppet' is not present on the system.")
201
+ end
202
+
203
+ s = Shell.new("#{puppet_bin} --version")
204
+ s.runcommand
205
+ actual_version = s.stdout.chomp
206
+ required_version = '4.5.1'
207
+
208
+ if Util.versioncmp(actual_version, required_version) < 0
209
+ raise("Cannot build package. puppet #{required_version} or greater required. We have #{actual_version}.")
210
+ end
211
+ end
212
+
213
+ def run_build
214
+ begin
215
+ PluginPackager.execute_verbosely(@verbose) do
216
+ Dir.chdir(@tmpdir) do
217
+ PluginPackager.safe_system('puppet module build')
218
+ end
219
+ end
220
+ rescue
221
+ STDERR.puts("Build process has failed")
222
+ raise
223
+ end
224
+ end
225
+
226
+ def move_package
227
+ begin
228
+ package_file = File.join(@tmpdir, "pkg", module_file_name)
229
+ FileUtils.cp(package_file, ".")
230
+ rescue
231
+ STDERR.puts("Could not copy package to working directory")
232
+ raise
233
+ end
234
+ end
235
+
236
+ def cleanup_tmpdirs
237
+ begin
238
+ FileUtils.rm_r(@tmpdir) if File.directory?(@tmpdir)
239
+ rescue
240
+ STDERR.puts("Could not remove temporary build directory %s" % [@tmpdir])
241
+ raise
242
+ end
243
+ end
244
+ end
245
+ end
246
+ end
@@ -0,0 +1,72 @@
1
+ # <%= module_name %> version <%= @plugin.metadata[:version] %>
2
+
3
+ #### Table of Contents
4
+
5
+ 1. [Overview](#overview)
6
+ 1. [Usage](#usage)
7
+ 1. [Configuration](#configuration)
8
+
9
+ ## Overview
10
+
11
+ <%= @plugin.metadata[:description] %>
12
+
13
+ The <%= module_name %> module is generated automatically, based on the source from <%= @plugin.metadata[:url] %>.
14
+ <%- if @plugin.plugintype == "Agent" -%>
15
+ <%-
16
+ ddl = DDL.new("package", :agent, false)
17
+ ddl.instance_eval(File.read(Dir.glob(File.join("**/agent/*.ddl")).first))
18
+ -%>
19
+
20
+ Available Actions:
21
+
22
+ <%- ddl.entities.keys.sort.each do |action| -%>
23
+ * **<%= action %>** - <%= ddl.entities[action][:description] %>
24
+ <%- end -%>
25
+ <%- end -%>
26
+
27
+ ## Usage
28
+
29
+ You can include this module into your infrastructure as any other module, but as it's designed to work with the [choria mcollective](http://forge.puppet.com/choria/mcollective) module you can configure it via Hiera:
30
+
31
+ ```yaml
32
+ mcollective::plugin_classes:
33
+ - <%= module_name %>
34
+ ```
35
+
36
+ ## Configuration
37
+
38
+ Server and Client configuration can be added via Hiera and managed through tiers in your site Hiera, they will be merged with any included in this module
39
+
40
+ ```yaml
41
+ <%= module_name %>::config:
42
+ example: value
43
+ ```
44
+
45
+ This will be added to both the `client.cfg` and `server.cfg`, you can likewise configure server and client specific settings using `<%= module_name %>::client_config` and `<%= module_name %>::server_config`.
46
+
47
+ These settings will be added to the `/etc/puppetlabs/mcollective/plugin.d/` directory in individual files.
48
+
49
+ For a full list of possible configuration settings see the module [source repository documentation](<%= @plugin.metadata[:url] %>).
50
+
51
+ ## Data Reference
52
+
53
+ * `<%= module_name %>::gem_dependencies` - Deep Merged Hash of gem name and version this module depends on
54
+ * `<%= module_name %>::manage_gem_dependencies` - disable managing of gem dependencies
55
+ * `<%= module_name %>::package_dependencies` - Deep Merged Hash of package name and version this module depends on
56
+ * `<%= module_name %>::manage_package_dependencies` - disable managing of packages dependencies
57
+ * `<%= module_name %>::class_dependencies` - Array of classes to include when installing this module
58
+ * `<%= module_name %>::package_dependencies` - disable managing of class dependencies
59
+ * `<%= module_name %>::config` - Deep Merged Hash of common config items for this module
60
+ * `<%= module_name %>::server_config` - Deep Merged Hash of config items specific to managed nodes
61
+ * `<%= module_name %>::client_config` - Deep Merged Hash of config items specific to client nodes
62
+ * `<%= module_name %>::policy_default` - `allow` or `deny`
63
+ * `<%= module_name %>::policies` - List of `actionpolicy` policies to deploy with an agent
64
+ * `<%= module_name %>::client` - installs client files when true - defaults to `$mcollective::client`
65
+ * `<%= module_name %>::server` - installs server files when true - defaults to `$mcollective::server`
66
+ * `<%= module_name %>::ensure` - `present` or `absent`
67
+
68
+ ## Development:
69
+
70
+ To contribute to this MCollective plugin please visit <%= @plugin.metadata[:url] %>.
71
+
72
+ This module was generated using the Choria Plugin Packager based on templates found at the [GitHub Project](https://github.com/choria-io/).
@@ -0,0 +1,16 @@
1
+ lookup_options:
2
+ <%= module_name %>::gem_dependencies:
3
+ merge:
4
+ strategy: deep
5
+ <%= module_name %>::package_dependencies:
6
+ merge:
7
+ strategy: deep
8
+ <%= module_name %>::config:
9
+ merge:
10
+ strategy: deep
11
+ <%= module_name %>::client_config:
12
+ merge:
13
+ strategy: deep
14
+ <%= module_name %>::server_config:
15
+ merge:
16
+ strategy: deep
@@ -0,0 +1 @@
1
+ <%= YAML.dump(plugin_hiera_data) %>
@@ -0,0 +1,12 @@
1
+ ---
2
+ version: 5
3
+
4
+ defaults:
5
+ datadir: "data"
6
+ data_hash: yaml_data
7
+
8
+ hierarchy:
9
+ - name: "plugin"
10
+ path: "plugin.yaml"
11
+ - name: "defaults"
12
+ path: "defaults.yaml"
@@ -0,0 +1,46 @@
1
+ class <%= module_name %> (
2
+ String $config_name,
3
+ Array[String] $client_files = [],
4
+ Array[String] $client_directories = [],
5
+ Array[String] $server_files = [],
6
+ Array[String] $server_directories = [],
7
+ Array[String] $common_files = [],
8
+ Array[String] $common_directories = [],
9
+ Boolean $manage_gem_dependencies = true,
10
+ Hash $gem_dependencies = {},
11
+ Boolean $manage_package_dependencies = true,
12
+ Hash $package_dependencies = {},
13
+ Boolean $manage_class_dependencies = true,
14
+ Array[String] $class_dependencies = [],
15
+ Mcollective::Policy_action $policy_default = $mcollective::policy_default,
16
+ Array[Mcollective::Policy] $policies = [],
17
+ Hash $config = {},
18
+ Hash $client_config = {},
19
+ Hash $server_config = {},
20
+ Boolean $client = $mcollective::client,
21
+ Boolean $server = $mcollective::server,
22
+ Enum["present", "absent"] $ensure = "present"
23
+ ) {
24
+ mcollective::module_plugin{$name:
25
+ config_name => $config_name,
26
+ client_files => $client_files,
27
+ server_files => $server_files,
28
+ common_files => $common_files,
29
+ client_directories => $client_directories,
30
+ server_directories => $server_directories,
31
+ common_directories => $common_directories,
32
+ gem_dependencies => $gem_dependencies,
33
+ manage_gem_dependencies => $manage_gem_dependencies,
34
+ package_dependencies => $package_dependencies,
35
+ manage_package_dependencies => $manage_package_dependencies,
36
+ class_dependencies => $class_dependencies,
37
+ policy_default => $policy_default,
38
+ policies => $policies,
39
+ config => $config,
40
+ client_config => $client_config,
41
+ server_config => $server_config,
42
+ client => $client,
43
+ server => $server,
44
+ ensure => $ensure
45
+ }
46
+ }
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "<%= @plugin.vendor %>-<%= module_name %>",
3
+ "version": "<%= version %>",
4
+ "author": "<%= @plugin.metadata[:author] %>",
5
+ "license": "<%= @plugin.metadata[:license] %>",
6
+ "summary": "<%= @plugin.metadata[:description] %>",
7
+ "source": "<%= @plugin.metadata[:url] %>",
8
+ "project_page": "<%= @plugin.metadata[:url] %>",
9
+ "dependencies": [
10
+ {"name": "choria/mcollective", "version_requirement": ">= 0.4.0 < 2.0.0"}
11
+ ],
12
+ "requirements": [
13
+ {
14
+ "name": "puppet",
15
+ "version_requirement": ">= 4.9.0"
16
+ }
17
+ ]
18
+ }
19
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: choria-mcorpc-support
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.20.4
4
+ version: 2.20.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - R.I.Pienaar
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-12-27 00:00:00.000000000 Z
11
+ date: 2019-03-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: systemu
@@ -138,6 +138,7 @@ files:
138
138
  - lib/mcollective/pluginpackager/debpackage_packager.rb
139
139
  - lib/mcollective/pluginpackager/modulepackage_packager.rb
140
140
  - lib/mcollective/pluginpackager/ospackage_packager.rb
141
+ - lib/mcollective/pluginpackager/puppet_module_packager.rb
141
142
  - lib/mcollective/pluginpackager/rpmpackage_packager.rb
142
143
  - lib/mcollective/pluginpackager/standard_definition.rb
143
144
  - lib/mcollective/pluginpackager/templates/debian/Makefile.erb
@@ -149,6 +150,12 @@ files:
149
150
  - lib/mcollective/pluginpackager/templates/module/Modulefile.erb
150
151
  - lib/mcollective/pluginpackager/templates/module/README.md.erb
151
152
  - lib/mcollective/pluginpackager/templates/module/_manifest.pp.erb
153
+ - lib/mcollective/pluginpackager/templates/puppet_module/README.md.erb
154
+ - lib/mcollective/pluginpackager/templates/puppet_module/data/defaults.yaml.erb
155
+ - lib/mcollective/pluginpackager/templates/puppet_module/data/plugin.yaml.erb
156
+ - lib/mcollective/pluginpackager/templates/puppet_module/hiera.yaml.erb
157
+ - lib/mcollective/pluginpackager/templates/puppet_module/manifests/init.pp.erb
158
+ - lib/mcollective/pluginpackager/templates/puppet_module/metadata.json.erb
152
159
  - lib/mcollective/pluginpackager/templates/redhat/rpm_spec.erb
153
160
  - lib/mcollective/registration/base.rb
154
161
  - lib/mcollective/rpc.rb