From 5333754a5dffd56ac574723bbca4bac750036cd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Tarti=C3=A8re?= Date: Tue, 3 Sep 2024 09:47:03 -0700 Subject: [PATCH 1/3] Extract the logic to generate choria modules name This code will be needed in another file. Modulesync does not seem to have built-in support for adding utility methods, so just put them in a local file and require it where the methods are needed. --- lib/util.rb | 14 ++++++++++++++ moduleroot/data/defaults.yaml.erb | 25 ++++++------------------- 2 files changed, 20 insertions(+), 19 deletions(-) create mode 100644 lib/util.rb diff --git a/lib/util.rb b/lib/util.rb new file mode 100644 index 0000000..0e58b33 --- /dev/null +++ b/lib/util.rb @@ -0,0 +1,14 @@ +def choria_module_name + case @metadata[:module_name] + when "action-policy" + "mcollective_util_actionpolicy" + when "mcollective_choria" + "mcollective_choria" + when "tasks-agent" + "mcollective_agent_bolt_tasks" + when /-agent$/ + "mcollective_agent_#{@metadata[:module_name].sub(/-agent$/, '')}" + else + raise "Don't know how to construct module name" + end +end diff --git a/moduleroot/data/defaults.yaml.erb b/moduleroot/data/defaults.yaml.erb index 551d7cd..87c6a67 100644 --- a/moduleroot/data/defaults.yaml.erb +++ b/moduleroot/data/defaults.yaml.erb @@ -1,30 +1,17 @@ -<% - module_name = case @metadata[:module_name] - when "action-policy" - "mcollective_util_actionpolicy" - when "mcollective_choria" - "mcollective_choria" - when "tasks-agent" - "mcollective_agent_bolt_tasks" - when /-agent$/ - "mcollective_agent_#{@metadata[:module_name].sub(/-agent$/, '')}" - else - raise "Don't know how to construct module name" - end --%> +<% require_relative '../../lib/util.rb' -%> lookup_options: - <%= module_name %>::gem_dependencies: + <%= choria_module_name %>::gem_dependencies: merge: strategy: deep - <%= module_name %>::package_dependencies: + <%= choria_module_name %>::package_dependencies: merge: strategy: deep - <%= module_name %>::config: + <%= choria_module_name %>::config: merge: strategy: deep - <%= module_name %>::client_config: + <%= choria_module_name %>::client_config: merge: strategy: deep - <%= module_name %>::server_config: + <%= choria_module_name %>::server_config: merge: strategy: deep From 298c043ea33fd150f61f67c03c3e880379f88c07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Tarti=C3=A8re?= Date: Tue, 3 Sep 2024 09:50:37 -0700 Subject: [PATCH 2/3] Add a template for the module class This file is supposed to provide access to the same parameters for all choria modules, but some modules are lacking one or more of these parameters. By managing its content with modulesync, we ensure we have consistent interface for all modules. --- moduleroot/manifests/init.pp.erb | 53 ++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 moduleroot/manifests/init.pp.erb diff --git a/moduleroot/manifests/init.pp.erb b/moduleroot/manifests/init.pp.erb new file mode 100644 index 0000000..46e1072 --- /dev/null +++ b/moduleroot/manifests/init.pp.erb @@ -0,0 +1,53 @@ +<% require_relative '../../lib/util.rb' -%> +# Managed by modulesync - DO NOT EDIT +# https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ +class <%= choria_module_name %> ( + String $config_name, + Array[String] $client_files = [], + Array[String] $client_directories = [], + Array[String] $server_files = [], + Array[String] $server_directories = [], + Array[String] $common_files = [], + Array[String] $common_directories = [], + Array[String] $executable_files = [], + Boolean $manage_gem_dependencies = true, + Hash $gem_dependencies = {}, + Boolean $manage_package_dependencies = true, + Hash $package_dependencies = {}, + Boolean $manage_class_dependencies = true, + Array[String] $class_dependencies = [], + Mcollective::Policy_action $policy_default = $mcollective::policy_default, + Array[Mcollective::Policy] $policies = [], + Array[Mcollective::Policy] $site_policies = $mcollective::site_policies, + Hash $config = {}, + Hash $client_config = {}, + Hash $server_config = {}, + Boolean $client = $mcollective::client, + Boolean $server = $mcollective::server, + Enum["present", "absent"] $ensure = "present" +) { + mcollective::module_plugin{$name: + config_name => $config_name, + client_files => $client_files, + server_files => $server_files, + common_files => $common_files, + executable_files => $executable_files, + client_directories => $client_directories, + server_directories => $server_directories, + common_directories => $common_directories, + gem_dependencies => $gem_dependencies, + manage_gem_dependencies => $manage_gem_dependencies, + package_dependencies => $package_dependencies, + manage_package_dependencies => $manage_package_dependencies, + class_dependencies => $class_dependencies, + policy_default => $policy_default, + policies => $policies, + site_policies => $site_policies, + config => $config, + client_config => $client_config, + server_config => $server_config, + client => $client, + server => $server, + ensure => $ensure + } +} From f8eb84a00eee33d53dce26ae47776ca130b34a6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Tarti=C3=A8re?= Date: Tue, 3 Sep 2024 10:04:09 -0700 Subject: [PATCH 3/3] Fix some style issues in Puppet manifests These checks are performed on the Puppet Forge to give quality scores to modules, and are failing for the choria repositories: * The `ensure` parameter must be the first one in resource declaration; * Non-interpolated strings should be single, not double-quoted. A bunch of other issues are reported by puppet-lint, but as of today they do not seem to be part of the module score calculation, so in order to minimize changes, this commit do not address them. While these changes are gratuitous, they will allow the scoring of the modules to increase, giving users a more positive view of the care taken to maintain them. --- moduleroot/manifests/init.pp.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/moduleroot/manifests/init.pp.erb b/moduleroot/manifests/init.pp.erb index 46e1072..5eb47b2 100644 --- a/moduleroot/manifests/init.pp.erb +++ b/moduleroot/manifests/init.pp.erb @@ -24,9 +24,10 @@ class <%= choria_module_name %> ( Hash $server_config = {}, Boolean $client = $mcollective::client, Boolean $server = $mcollective::server, - Enum["present", "absent"] $ensure = "present" + Enum['present', 'absent'] $ensure = 'present' ) { mcollective::module_plugin{$name: + ensure => $ensure, config_name => $config_name, client_files => $client_files, server_files => $server_files, @@ -48,6 +49,5 @@ class <%= choria_module_name %> ( server_config => $server_config, client => $client, server => $server, - ensure => $ensure } }