diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index ae4123a..2fd4a2f 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -8,7 +8,7 @@ jobs: name: 'Static code analysys' runs-on: ubuntu-latest timeout-minutes: 10 - container: puppet/puppet-dev-tools:4.x + container: puppet/pdk:3.4.0.1.55.g4519dd0 steps: - uses: actions/checkout@v2 - name: Run static validations @@ -20,7 +20,7 @@ jobs: name: 'Unit tests' runs-on: ubuntu-latest timeout-minutes: 60 - container: puppet/puppet-dev-tools:4.x + container: puppet/pdk:3.4.0.1.55.g4519dd0 steps: - uses: actions/checkout@v2 - name: Run unit tests diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 805ece3..4f8a71c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -14,7 +14,7 @@ jobs: name: 'Deploy to forge' runs-on: ubuntu-latest if: github.repository_owner == 'example42' - container: puppet/puppet-dev-tools:4.x + container: puppet/pdk:3.4.0.1.55.g4519dd0 steps: - name: Checkout repository uses: actions/checkout@v2 diff --git a/.gitignore b/.gitignore index bf5a5ab..2803e56 100644 --- a/.gitignore +++ b/.gitignore @@ -15,9 +15,11 @@ /junit/ /log/ /pkg/ -/spec/fixtures/modules/ +/spec/fixtures/manifests/ +/spec/fixtures/modules/* /tmp/ /vendor/ +/.vendor/ /convert_report.txt /update_report.txt .DS_Store @@ -25,3 +27,9 @@ .envrc /inventory.yaml /spec/fixtures/litmus_inventory.yaml +.resource_types +.modules +.task_cache.json +.plan_cache.json +.rerun.json +bolt-debug.log diff --git a/.pdkignore b/.pdkignore index c538bea..84684be 100644 --- a/.pdkignore +++ b/.pdkignore @@ -16,9 +16,10 @@ /log/ /pkg/ /spec/fixtures/manifests/ -/spec/fixtures/modules/ +/spec/fixtures/modules/* /tmp/ /vendor/ +/.vendor/ /convert_report.txt /update_report.txt .DS_Store @@ -26,20 +27,23 @@ .envrc /inventory.yaml /spec/fixtures/litmus_inventory.yaml -/appveyor.yml -/.editorconfig +.resource_types +.modules +.task_cache.json +.plan_cache.json +.rerun.json +bolt-debug.log /.fixtures.yml /Gemfile /.gitattributes +/.github/ /.gitignore -/.gitlab-ci.yml /.pdkignore /.puppet-lint.rc /Rakefile /rakelib/ /.rspec -/.rubocop.yml -/.travis.yml +/..yml /.yardopts /spec/ /.vscode/ diff --git a/.puppet-lint.rc b/.puppet-lint.rc index b25e492..9e15c6e 100644 --- a/.puppet-lint.rc +++ b/.puppet-lint.rc @@ -1,5 +1,9 @@ +--fail-on-warnings --relative -# --no-parameter_documentation -# --no-file_ensure-check -# --no-params-empty-string-assignment-check - +--no-80chars-check +--no-140chars-check +--no-class_inherits_from_params_class-check +--no-autoloader_layout-check +--no-documentation-check +--no-single_quote_string_with_variables-check +--ignore-paths=.vendor/**/*.pp,.bundle/**/*.pp,pkg/**/*.pp,spec/**/*.pp,tests/**/*.pp,types/**/*.pp,vendor/**/*.pp diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 2f1e4f7..6da8d47 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -1,6 +1,6 @@ { "recommendations": [ "puppet.puppet-vscode", - "rebornix.Ruby" + "Shopify.ruby-lsp" ] } diff --git a/CHANGELOG.md b/CHANGELOG.md index d3477ef..5e0f695 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to this project will be documented in this file. +## Release 0.1.1 + +* Puppet 8 support + ## Release 0.1.0 * First release with several profiles moved from psick module diff --git a/Gemfile b/Gemfile index 556928c..18df10e 100644 --- a/Gemfile +++ b/Gemfile @@ -13,36 +13,54 @@ def location_for(place_or_version, fake_version = nil) end end -ruby_version_segments = Gem::Version.new(RUBY_VERSION.dup).segments -minor_version = ruby_version_segments[0..1].join('.') - group :development do - gem "json", '= 2.0.4', require: false if Gem::Requirement.create('~> 2.4.2').satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) - gem "json", '= 2.1.0', require: false if Gem::Requirement.create(['>= 2.5.0', '< 2.7.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) - gem "json", '= 2.3.0', require: false if Gem::Requirement.create(['>= 2.7.0', '< 2.8.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) - gem "puppet-module-posix-default-r#{minor_version}", '~> 1.0', require: false, platforms: [:ruby] - gem "puppet-module-posix-dev-r#{minor_version}", '~> 1.0', require: false, platforms: [:ruby] - gem "puppet-module-win-default-r#{minor_version}", '~> 1.0', require: false, platforms: [:mswin, :mingw, :x64_mingw] - gem "puppet-module-win-dev-r#{minor_version}", '~> 1.0', require: false, platforms: [:mswin, :mingw, :x64_mingw] -# gem "voxpupuli-puppet-lint-plugins", '>= 3.0', require: false + gem "json", '= 2.6.1', require: false if Gem::Requirement.create(['>= 3.1.0', '< 3.1.3']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) + gem "json", '= 2.6.3', require: false if Gem::Requirement.create(['>= 3.2.0', '< 4.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) + gem "racc", '~> 1.4.0', require: false if Gem::Requirement.create(['>= 2.7.0', '< 3.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) + gem "deep_merge", '~> 1.2.2', require: false + gem "voxpupuli-puppet-lint-plugins", '~> 5.0', require: false + gem "facterdb", '~> 2.1', require: false if Gem::Requirement.create(['< 3.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) + gem "facterdb", '~> 3.0', require: false if Gem::Requirement.create(['>= 3.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) + gem "metadata-json-lint", '~> 4.0', require: false + gem "json-schema", '< 5.1.1', require: false + gem "rspec-puppet-facts", '~> 4.0', require: false if Gem::Requirement.create(['< 3.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) + gem "rspec-puppet-facts", '~> 5.0', require: false if Gem::Requirement.create(['>= 3.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) + gem "dependency_checker", '~> 1.0.0', require: false + gem "parallel_tests", '= 3.12.1', require: false + gem "pry", '~> 0.10', require: false + gem "simplecov-console", '~> 0.9', require: false + gem "puppet-debugger", '~> 1.0', require: false + gem "rubocop", '~> 1.50.0', require: false + gem "rubocop-performance", '= 1.16.0', require: false + gem "rubocop-rspec", '= 2.19.0', require: false + gem "rb-readline", '= 0.5.5', require: false, platforms: [:mswin, :mingw, :x64_mingw] +end +group :development, :release_prep do + gem "puppet-strings", '~> 4.0', require: false + gem "puppetlabs_spec_helper", '~> 8.0', require: false + gem "puppet-blacksmith", '~> 7.0', require: false end group :system_tests do - gem "puppet-module-posix-system-r#{minor_version}", '~> 1.0', require: false, platforms: [:ruby] - gem "puppet-module-win-system-r#{minor_version}", '~> 1.0', require: false, platforms: [:mswin, :mingw, :x64_mingw] + gem "puppet_litmus", '~> 1.0', require: false, platforms: [:ruby, :x64_mingw] + gem "CFPropertyList", '< 3.0.7', require: false, platforms: [:mswin, :mingw, :x64_mingw] + gem "serverspec", '~> 2.41', require: false end -puppet_version = ENV['PUPPET_GEM_VERSION'] -facter_version = ENV['FACTER_GEM_VERSION'] -hiera_version = ENV['HIERA_GEM_VERSION'] - gems = {} +puppet_version = ENV.fetch('PUPPET_GEM_VERSION', nil) +facter_version = ENV.fetch('FACTER_GEM_VERSION', nil) +hiera_version = ENV.fetch('HIERA_GEM_VERSION', nil) -gems['puppet'] = location_for(puppet_version) - -# If facter or hiera versions have been specified via the environment -# variables +# If PUPPET_FORGE_TOKEN is set then use authenticated source for both puppet and facter, since facter is a transitive dependency of puppet +# Otherwise, do as before and use location_for to fetch gems from the default source +if !ENV['PUPPET_FORGE_TOKEN'].to_s.empty? + gems['puppet'] = ['~> 8.11', { require: false, source: 'https://rubygems-puppetcore.puppet.com' }] + gems['facter'] = ['~> 4.11', { require: false, source: 'https://rubygems-puppetcore.puppet.com' }] +else + gems['puppet'] = location_for(puppet_version) + gems['facter'] = location_for(facter_version) if facter_version +end -gems['facter'] = location_for(facter_version) if facter_version gems['hiera'] = location_for(hiera_version) if hiera_version gems.each do |gem_name, gem_params| diff --git a/Rakefile b/Rakefile index 0f8754e..31b5930 100644 --- a/Rakefile +++ b/Rakefile @@ -1,89 +1,18 @@ # frozen_string_literal: true require 'bundler' -require 'puppet_litmus/rake_tasks' if Bundler.rubygems.find_name('puppet_litmus').any? +require 'puppet_litmus/rake_tasks' if Gem.loaded_specs.key? 'puppet_litmus' require 'puppetlabs_spec_helper/rake_tasks' require 'puppet-syntax/tasks/puppet-syntax' -require 'puppet_blacksmith/rake_tasks' if Bundler.rubygems.find_name('puppet-blacksmith').any? -require 'github_changelog_generator/task' if Bundler.rubygems.find_name('github_changelog_generator').any? -require 'puppet-strings/tasks' if Bundler.rubygems.find_name('puppet-strings').any? - -def changelog_user - return unless Rake.application.top_level_tasks.include? "changelog" - returnVal = nil || JSON.load(File.read('metadata.json'))['author'] - raise "unable to find the changelog_user in .sync.yml, or the author in metadata.json" if returnVal.nil? - puts "GitHubChangelogGenerator user:#{returnVal}" - returnVal -end - -def changelog_project - return unless Rake.application.top_level_tasks.include? "changelog" - - returnVal = nil - returnVal ||= begin - metadata_source = JSON.load(File.read('metadata.json'))['source'] - metadata_source_match = metadata_source && metadata_source.match(%r{.*\/([^\/]*?)(?:\.git)?\Z}) - - metadata_source_match && metadata_source_match[1] - end - - raise "unable to find the changelog_project in .sync.yml or calculate it from the source in metadata.json" if returnVal.nil? - - puts "GitHubChangelogGenerator project:#{returnVal}" - returnVal -end - -def changelog_future_release - return unless Rake.application.top_level_tasks.include? "changelog" - returnVal = "v%s" % JSON.load(File.read('metadata.json'))['version'] - raise "unable to find the future_release (version) in metadata.json" if returnVal.nil? - puts "GitHubChangelogGenerator future_release:#{returnVal}" - returnVal -end +require 'puppet-strings/tasks' if Gem.loaded_specs.key? 'puppet-strings' PuppetLint.configuration.send('disable_relative') - - -if Bundler.rubygems.find_name('github_changelog_generator').any? - GitHubChangelogGenerator::RakeTask.new :changelog do |config| - raise "Set CHANGELOG_GITHUB_TOKEN environment variable eg 'export CHANGELOG_GITHUB_TOKEN=valid_token_here'" if Rake.application.top_level_tasks.include? "changelog" and ENV['CHANGELOG_GITHUB_TOKEN'].nil? - config.user = "#{changelog_user}" - config.project = "#{changelog_project}" - config.future_release = "#{changelog_future_release}" - config.exclude_labels = ['maintenance'] - config.header = "# Change log\n\nAll notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org)." - config.add_pr_wo_labels = true - config.issues = false - config.merge_prefix = "### UNCATEGORIZED PRS; LABEL THEM ON GITHUB" - config.configure_sections = { - "Changed" => { - "prefix" => "### Changed", - "labels" => ["backwards-incompatible"], - }, - "Added" => { - "prefix" => "### Added", - "labels" => ["enhancement", "feature"], - }, - "Fixed" => { - "prefix" => "### Fixed", - "labels" => ["bug", "documentation", "bugfix"], - }, - } - end -else - desc 'Generate a Changelog from GitHub' - task :changelog do - raise < 1.15' - condition: "Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.3.0')" -EOM - end -end +PuppetLint.configuration.send('disable_80chars') +PuppetLint.configuration.send('disable_140chars') +PuppetLint.configuration.send('disable_class_inherits_from_params_class') +PuppetLint.configuration.send('disable_autoloader_layout') +PuppetLint.configuration.send('disable_documentation') +PuppetLint.configuration.send('disable_single_quote_string_with_variables') +PuppetLint.configuration.fail_on_warnings = true +PuppetLint.configuration.ignore_paths = [".vendor/**/*.pp", ".bundle/**/*.pp", "pkg/**/*.pp", "spec/**/*.pp", "tests/**/*.pp", "types/**/*.pp", "vendor/**/*.pp"] diff --git a/manifests/apache/tp.pp b/manifests/apache/tp.pp index ba7751b..1588b05 100644 --- a/manifests/apache/tp.pp +++ b/manifests/apache/tp.pp @@ -167,7 +167,7 @@ settings_hash => $settings_hash, }, 'exec' => { - path => $::path, + path => $facts['path'], }, 'file' => { ensure => $file_ensure, diff --git a/manifests/crowdsec.pp b/manifests/crowdsec.pp index 895fcc8..27dee02 100644 --- a/manifests/crowdsec.pp +++ b/manifests/crowdsec.pp @@ -5,8 +5,8 @@ # @example # include psick_profile::crowdsec class psick_profile::crowdsec ( - String $install_class = 'psick_profile::crowdsec::tp', - Hash $collections_hash = {}, + String $install_class = 'psick_profile::crowdsec::tp', + Hash $collections_hash = {}, Boolean $manage = $::psick::manage, Boolean $noop_manage = $::psick::noop_manage, Boolean $noop_value = $::psick::noop_value, diff --git a/manifests/docker/tp.pp b/manifests/docker/tp.pp index 4a1bce8..67b91b0 100644 --- a/manifests/docker/tp.pp +++ b/manifests/docker/tp.pp @@ -167,7 +167,7 @@ settings_hash => $settings_hash, }, 'exec' => { - path => $::path, + path => $facts['path'], }, 'file' => { ensure => $file_ensure, diff --git a/manifests/foreman/tp.pp b/manifests/foreman/tp.pp index ee91a9f..989858a 100644 --- a/manifests/foreman/tp.pp +++ b/manifests/foreman/tp.pp @@ -167,7 +167,7 @@ settings_hash => $settings_hash, }, 'exec' => { - path => $::path, + path => $facts['path'], }, 'file' => { ensure => $file_ensure, diff --git a/manifests/gitlab.pp b/manifests/gitlab.pp index f6ded6b..0d8c71c 100644 --- a/manifests/gitlab.pp +++ b/manifests/gitlab.pp @@ -8,7 +8,7 @@ # @param manage_installation Set to true to atually install GitLab. Default, # false, just manages symlink in /etc/ssh/auth_keys # @param use_https Define if you want gitlab services to use ssl. -# @param server_name The name to use for the GitLab website. Default: $::fqdn, +# @param server_name The name to use for the GitLab website. Default: $::networking['fqdn'], # If you set a name different from the local machine fqdn, # provide custom cert files via *_file_source params # @param ca_file_source Puppet source for the ca certificate. By default Puppet CA is diff --git a/manifests/grafana/datasource.pp b/manifests/grafana/datasource.pp index 5f4f6e4..3ba1d1e 100644 --- a/manifests/grafana/datasource.pp +++ b/manifests/grafana/datasource.pp @@ -37,7 +37,7 @@ Optional[Hash] $json_data = undef, Optional[Hash] $secure_json_data = undef, Optional[Boolean] $editable = undef, - Optional[Hash] $options = {}, + Hash $options = {}, ) { tp::conf { "grafana::${file_name}": content => template($template), diff --git a/manifests/grafana/plugin.pp b/manifests/grafana/plugin.pp index 96e9428..e486f00 100644 --- a/manifests/grafana/plugin.pp +++ b/manifests/grafana/plugin.pp @@ -26,7 +26,7 @@ unless => "grafana-cli plugins ls | grep ${plugin} | grep '${version}'", notify => $exec_notify, require => $exec_require, - path => $::path, + path => $facts['path'], } } else { exec { "grafana plugins uninstall ${plugin}": @@ -34,7 +34,7 @@ onlyif => "grafana-cli plugins ls | grep ${plugin}", notify => $exec_notify, require => $exec_require, - path => $::path, + path => $facts['path'], } } } diff --git a/manifests/grafana/tp.pp b/manifests/grafana/tp.pp index 1ff3582..f2ba180 100644 --- a/manifests/grafana/tp.pp +++ b/manifests/grafana/tp.pp @@ -167,7 +167,7 @@ settings_hash => $settings_hash, }, 'exec' => { - path => $::path, + path => $facts['path'], }, 'file' => { ensure => $file_ensure, diff --git a/manifests/grafana/user.pp b/manifests/grafana/user.pp index 89e4705..077dcbe 100644 --- a/manifests/grafana/user.pp +++ b/manifests/grafana/user.pp @@ -32,7 +32,7 @@ exec { "grafana user add ${title}": command => "${user_dir_path}/${user}_${host}", require => $exec_require, - path => $::path, + path => $facts['path'], refreshonly => true, } } diff --git a/manifests/influxdb/database.pp b/manifests/influxdb/database.pp index c4fe868..e7e3e09 100644 --- a/manifests/influxdb/database.pp +++ b/manifests/influxdb/database.pp @@ -69,7 +69,7 @@ # Attempt to autoconfigure dependencies based on server host. Can be # overridden with param $exec_params $exec_require = $server_host ? { - /(localhost|127.0.0.1|$fqdn|$hostname|$ipaddress)/ => [Package[influxdb],Service[influxdb]], + /(localhost|127.0.0.1|$::networking['fqdn']|$::networking['hostname']|$::networking['ip'])/ => [Package[influxdb],Service[influxdb]], default => [Package[influxdb]], } $exec_default_options = { diff --git a/manifests/influxdb/grant.pp b/manifests/influxdb/grant.pp index df1ba88..00d7da6 100644 --- a/manifests/influxdb/grant.pp +++ b/manifests/influxdb/grant.pp @@ -81,7 +81,7 @@ # Attempt to autoconfigure dependencies based on server host. Can be # overridden with param $exec_params $exec_require = $server_host ? { - /(localhost|127.0.0.1|$fqdn|$hostname|$ipaddress)/ => [Package[influxdb],Service[influxdb]], + /(localhost|127.0.0.1|$::networking['fqdn']|$::networking['hostname']|$::networking['ip'])/ => [Package[influxdb],Service[influxdb]], default => [Package[influxdb]], } $exec_default_options = { diff --git a/manifests/influxdb/tp.pp b/manifests/influxdb/tp.pp index aafd5be..6f7ea27 100644 --- a/manifests/influxdb/tp.pp +++ b/manifests/influxdb/tp.pp @@ -167,7 +167,7 @@ settings_hash => $settings_hash, }, 'exec' => { - path => $::path, + path => $facts['path'], }, 'file' => { ensure => $file_ensure, diff --git a/manifests/influxdb/user.pp b/manifests/influxdb/user.pp index c030935..96d56f4 100644 --- a/manifests/influxdb/user.pp +++ b/manifests/influxdb/user.pp @@ -80,7 +80,7 @@ # Attempt to autoconfigure dependencies based on server host. Can be # overridden with param $exec_params $exec_require = $server_host ? { - /(localhost|127.0.0.1|$fqdn|$hostname|$ipaddress)/ => [Package[influxdb],Service[influxdb]], + /(localhost|127.0.0.1|$::networking['fqdn']|$::networking['hostname']|$::networking['ip'])/ => [Package[influxdb],Service[influxdb]], default => [Package[influxdb]], } $exec_default_options = { diff --git a/manifests/jenkins/tp.pp b/manifests/jenkins/tp.pp index f592458..d2aae1c 100644 --- a/manifests/jenkins/tp.pp +++ b/manifests/jenkins/tp.pp @@ -167,7 +167,7 @@ settings_hash => $settings_hash, }, 'exec' => { - path => $::path, + path => $facts['path'], }, 'file' => { ensure => $file_ensure, diff --git a/manifests/keepalived.pp b/manifests/keepalived.pp index 0f0f964..0e9e51a 100644 --- a/manifests/keepalived.pp +++ b/manifests/keepalived.pp @@ -48,7 +48,7 @@ # split vs to get role to find correct mapping in hieradata for the configured role-loadbalancing-variables like # vip, vip_mask and options # write File for vrrp_instance via given function - $virtualservers=hiera_array('virtualservers', []) + $virtualservers=lookup('virtualservers', Array, 'unique', []) $virtualservers.each | String $vs | { $vs_split=split($vs,'-') $app_role=$vs_split[1] diff --git a/manifests/mariadb/tp.pp b/manifests/mariadb/tp.pp index ccbb87c..e55613d 100644 --- a/manifests/mariadb/tp.pp +++ b/manifests/mariadb/tp.pp @@ -167,7 +167,7 @@ settings_hash => $settings_hash, }, 'exec' => { - path => $::path, + path => $facts['path'], }, 'file' => { ensure => $file_ensure, diff --git a/manifests/mongo/tp.pp b/manifests/mongo/tp.pp index c0df769..3ef6ee2 100644 --- a/manifests/mongo/tp.pp +++ b/manifests/mongo/tp.pp @@ -167,7 +167,7 @@ settings_hash => $settings_hash, }, 'exec' => { - path => $::path, + path => $facts['path'], }, 'file' => { ensure => $file_ensure, diff --git a/manifests/mysql/install.pp b/manifests/mysql/install.pp index b1e9d02..685dea6 100644 --- a/manifests/mysql/install.pp +++ b/manifests/mysql/install.pp @@ -167,7 +167,7 @@ settings_hash => $settings_hash, }, 'exec' => { - path => $::path, + path => $facts['path'], }, 'file' => { ensure => $file_ensure, diff --git a/manifests/nginx/tp.pp b/manifests/nginx/tp.pp index e6be4af..80e5482 100644 --- a/manifests/nginx/tp.pp +++ b/manifests/nginx/tp.pp @@ -167,7 +167,7 @@ settings_hash => $settings_hash, }, 'exec' => { - path => $::path, + path => $facts['path'], }, 'file' => { ensure => $file_ensure, diff --git a/manifests/openswan/tp.pp b/manifests/openswan/tp.pp index 0226773..0697f8d 100644 --- a/manifests/openswan/tp.pp +++ b/manifests/openswan/tp.pp @@ -167,7 +167,7 @@ settings_hash => $settings_hash, }, 'exec' => { - path => $::path, + path => $facts['path'], }, 'file' => { ensure => $file_ensure, diff --git a/manifests/openvpn/tp.pp b/manifests/openvpn/tp.pp index 2e9c3d4..f96e21d 100644 --- a/manifests/openvpn/tp.pp +++ b/manifests/openvpn/tp.pp @@ -167,7 +167,7 @@ settings_hash => $settings_hash, }, 'exec' => { - path => $::path, + path => $facts['path'], }, 'file' => { ensure => $file_ensure, diff --git a/manifests/postfix/tp.pp b/manifests/postfix/tp.pp index 561ca80..bba725e 100644 --- a/manifests/postfix/tp.pp +++ b/manifests/postfix/tp.pp @@ -167,7 +167,7 @@ settings_hash => $settings_hash, }, 'exec' => { - path => $::path, + path => $facts['path'], }, 'file' => { ensure => $file_ensure, diff --git a/manifests/postgresql/tp.pp b/manifests/postgresql/tp.pp index b909518..47321db 100644 --- a/manifests/postgresql/tp.pp +++ b/manifests/postgresql/tp.pp @@ -167,7 +167,7 @@ settings_hash => $settings_hash, }, 'exec' => { - path => $::path, + path => $facts['path'], }, 'file' => { ensure => $file_ensure, diff --git a/manifests/puppetserver/tp.pp b/manifests/puppetserver/tp.pp index 27f1553..96b3b1c 100644 --- a/manifests/puppetserver/tp.pp +++ b/manifests/puppetserver/tp.pp @@ -167,7 +167,7 @@ settings_hash => $settings_hash, }, 'exec' => { - path => $::path, + path => $facts['path'], }, 'file' => { ensure => $file_ensure, diff --git a/manifests/rabbitmq/tp.pp b/manifests/rabbitmq/tp.pp index e790ae0..b02dfaa 100644 --- a/manifests/rabbitmq/tp.pp +++ b/manifests/rabbitmq/tp.pp @@ -167,7 +167,7 @@ settings_hash => $settings_hash, }, 'exec' => { - path => $::path, + path => $facts['path'], }, 'file' => { ensure => $file_ensure, diff --git a/manifests/redis/tp.pp b/manifests/redis/tp.pp index 0b7c4a9..9f3da63 100644 --- a/manifests/redis/tp.pp +++ b/manifests/redis/tp.pp @@ -167,7 +167,7 @@ settings_hash => $settings_hash, }, 'exec' => { - path => $::path, + path => $facts['path'], }, 'file' => { ensure => $file_ensure, diff --git a/manifests/remediate.pp b/manifests/remediate.pp index 12e316e..aa09762 100644 --- a/manifests/remediate.pp +++ b/manifests/remediate.pp @@ -95,7 +95,7 @@ if $swarm_init { exec { 'docker swarm init remediate': command => "docker swarm init && touch ${remediate_dir}/.docker-swarn-init-remediate.lock", - path => $::path, + path => $facts['path'], user => $user, cwd => $remediate_dir, creates => "${remediate_dir}/.docker-swarn-init-remediate.lock", @@ -103,7 +103,7 @@ } exec { 'docker-compose run remediate': command => 'docker-compose run remediate start --license-file license.json', # lint:ignore:140char - path => $::path, + path => $facts['path'], cwd => $remediate_dir, user => $user, provider => 'shell', diff --git a/manifests/sensu/uchiwa.pp b/manifests/sensu/uchiwa.pp index 61fd1c2..7fe5663 100644 --- a/manifests/sensu/uchiwa.pp +++ b/manifests/sensu/uchiwa.pp @@ -1,7 +1,7 @@ # class psick_profile::sensu::uchiwa # class psick_profile::sensu::uchiwa ( - Stdlib::Compat::Ip_address $host = '0.0.0.0', + Stdlib::IP::Address $host = '0.0.0.0', Integer $port = 3000, Variant[String,Sensitive] $user = 'sensu', Variant[String,Sensitive] $pass = 'sensu', diff --git a/manifests/vagrant.pp b/manifests/vagrant.pp index 1467fd9..079da0e 100644 --- a/manifests/vagrant.pp +++ b/manifests/vagrant.pp @@ -6,11 +6,12 @@ # @param The user to use for plugins installation # class psick_profile::vagrant ( - Variant[Undef,String] $version = undef, + Psick::Ensure $version = undef, Array $plugins = [], Array $default_plugins = ['vagrant-vbguest' , 'vagrant-cachier'], String $user = 'root', + String $module = 'psick_profile', Boolean $manage = $::psick::manage, Boolean $noop_manage = $::psick::noop_manage, Boolean $noop_value = $::psick::noop_value, @@ -19,15 +20,24 @@ if $noop_manage { noop($noop_value) } - class { 'vagrant': - version => $version, - } - - $all_plugins = $default_plugins + $plugins + # Intallation management + case $module { + 'psick_profile': { + class { 'psick_profile::vagrant::tp': + ensure => $version, + } + } + default: { + class { 'vagrant': + version => $version, + } + $all_plugins = $default_plugins + $plugins - $all_plugins.each | $plugin | { - ::vagrant::plugin { $plugin: - user => $user, + $all_plugins.each | $plugin | { + ::vagrant::plugin { $plugin: + user => $user, + } + } } } } diff --git a/manifests/vagrant/tp.pp b/manifests/vagrant/tp.pp new file mode 100644 index 0000000..9eba0b7 --- /dev/null +++ b/manifests/vagrant/tp.pp @@ -0,0 +1,185 @@ +# psick_profile::vagrant::tp +# +# @summary This tp profile manages vagrant with Tiny Puppet (tp) +# +# When you include this class the relevant tp::install define is declared +# which is expected to install vagrant package and manage its service. +# Via the resources_hash parameter is possible to pass hashes of tp::conf and +# tp::dir defines which can manage vagrant configuration files and +# whole dirs. +# All the parameters ending with the _hash suffix expect and Hash and are looked +# up on Hiera via the deep merge lookup option. +# +# @example Just include it to install vagrant +# include psick_profile::vagrant::tp +# +# @example Include via psick module classification (yaml) +# psick::profiles::linux_classes: +# vagrant: psick_profile::vagrant::tp +# +# @example To use upstream repos instead of OS defaults (if tinydata available) as packages source: +# psick_profile::vagrant::tp::upstream_repo: true +# +# @example Manage extra configs via hiera (yaml) with templates based on custom options +# psick_profile::vagrant::tp::ensure: present +# psick_profile::vagrant::tp::resources: +# tp::conf: +# vagrant: +# epp: profile/vagrant/vagrant.conf.epp +# vagrant::dot.conf: +# epp: profile/vagrant/dot.conf.epp +# base_dir: conf +# exec: +# vagrant::setup: +# command: '/usr/local/bin/vagrant_setup' +# creates: '/opt/vagrant' +# psick_profile::vagrant::tp::options: +# key: value +# +# @example Enable default auto configuration, if configurations are available +# for the underlying system and the given auto_conf value, they are +# automatically added. +# psick_profile::vagrant::tp::auto_conf: true +# +# @param manage If to actually manage any resource in this profile or not. +# @param ensure If to install or remove vagrant. Valid values are present, absent, latest +# or any version string, matching the expected vagrant package version. +# @param upstream_repo If to use vagrant upstream repos as source for packages +# or rely on default packages from the underlying OS. +# +# @param install_hash An hash of valid params to pass to tp::install defines. Useful to +# manage specific params that are not automatically defined. +# @param options An open hash of options to use in the templates referenced +# in the tp::conf entries of the $resources_hash. +# @param settings_hash An hash of tp settings to override default vagrant file +# paths, package names, repo info and whatever tinydata that matches Tp::Settings data type: +# https://github.com/example42/puppet-tp/blob/master/types/settings.pp. +# +# @param auto_conf If to enable automatic configuration of vagrant based on the +# resources_auto_conf_hash and options_auto_conf_hash parameters, if present in +# data/common/vagrant.yaml. You can both override them in your Hiera files +# and merge them with your resources and options. +# @param resources_auto_conf_hash The default resources hash if auto_conf is true. +# The final resources managed are the ones specified here and in $resources. +# Check psick_profile::vagrant::tp::resources_auto_conf_hash in +# data/common/vagrant.yaml for the auto_conf defaults. +# @param options_auto_conf_hash The default options hash if auto_conf is set. +# Check psick_profile::vagrant::tp::options_auto_conf_hash in +# data/common/vagrant.yaml for the auto_conf defaults. +# +# @param resources An hash of any resource, like tp::conf, tp::dir, exec or whatever +# to declare for vagrant confiuration. Can also come from a third-party +# component modules with dedicated vagrant resources. +# tp::conf params: https://github.com/example42/puppet-tp/blob/master/manifests/conf.pp +# tp::dir params: https://github.com/example42/puppet-tp/blob/master/manifests/dir.pp +# any other Puppet resource type, with relevant params can be actually used +# The Hiera lookup method used for this parameter is defined with the $resource_lookup_method +# parameter. +# @param resource_lookup_method What lookup method to use for psick_profile::vagrant::tp::resources +# @param resources_defaults An Hash of resources with their default params, to be merged with +# $resources. +# +# @param auto_prereq If to automatically install eventual dependencies for vagrant. +# Set to false if you have problems with duplicated resources, being sure that you +# manage the prerequistes to install vagrant (other packages, repos or tp installs). +# +# @param noop_manage If to manage noop mode via the noop() function for the resources of +# this class. This must be true for noop_value to have effect. +# @param noop_value. The parameter passed to the noop() function (from trlinkin-noop module) +# When true, noop in enforced on all the class' resources. +# When false, no-noop in enforced on all the class' resources and overrides any other noop +# setting (also from clients' puppet.conf +# +class psick_profile::vagrant::tp ( + Psick::Ensure $ensure = 'present', + Boolean $manage = true, + Optional[Boolean] $upstream_repo = undef, + + Hash $install_hash = {}, + Hash $settings_hash = {}, + +# This param is looked up in code according to $resources_lookup_method +# Hash $resources = {}, + Hash $resources_defaults = {}, + Enum['first','deep','hash'] $resources_lookup_method = 'deep', + +# This param is looked up in code according to $options_lookup_method +# Hash $options = {}, + Enum['first','deep','hash'] $options_lookup_method = 'deep', + + Boolean $auto_conf = false, + Hash $resources_auto_conf_hash = {}, + Hash $options_auto_conf_hash = {}, + + Boolean $auto_prereq = true, + + Boolean $noop_manage = false, + Boolean $noop_value = false, +) { + $options=lookup('psick_profile::vagrant::tp::options', Hash, $options_lookup_method, {}) + + if $manage { + if $noop_manage { + noop($noop_value) + } + $options_all = $auto_conf ? { + true => $options_auto_conf_hash + $options, + false => $options, + } + + $install_defaults = { + ensure => $ensure, + options_hash => $options_all, + settings_hash => $settings_hash, + auto_repo => $auto_prereq, + auto_prereq => $auto_prereq, + upstream_repo => $upstream_repo, + } + tp::install { 'vagrant': + * => $install_defaults + $install_hash, + } + + $file_ensure = $ensure ? { + 'absent' => 'absent', + default => 'present', + } + $dir_ensure = $ensure ? { + 'absent' => 'absent', + default => 'directory', + } + + # Declaration of psick_profile::vagrant::tp::resources + $resources=lookup('psick_profile::vagrant::tp::resources', Hash, $resources_lookup_method, {}) + $resources.each |String $resource_type, Hash $content| { + $resources_all = $auto_conf ? { + true => pick($resources_auto_conf_hash[$resource_type], {}) + pick($resources[$resource_type], {}), + false => pick($resources[$resource_type], {}), + } + $resources_all.each |String $resource_name, Hash $resource_params| { + $resources_params_default = $resource_type ? { + 'tp::conf' => { + ensure => $file_ensure, + options_hash => $options_all, + settings_hash => $settings_hash, + }, + 'tp::dir' => { + ensure => $dir_ensure, + settings_hash => $settings_hash, + }, + 'exec' => { + path => $facts['path'], + }, + 'file' => { + ensure => $file_ensure, + }, + 'package' => { + ensure => $file_ensure, + }, + default => {}, + } + $resource_params_all = deep_merge($resources_defaults[$resource_type], $resources_params_default, $resource_params) + ensure_resource($resource_type,$resource_name,$resource_params_all) + } + } + } +} diff --git a/manifests/virtualbox/tp.pp b/manifests/virtualbox/tp.pp index 23e4b63..9c85adb 100644 --- a/manifests/virtualbox/tp.pp +++ b/manifests/virtualbox/tp.pp @@ -167,7 +167,7 @@ settings_hash => $settings_hash, }, 'exec' => { - path => $::path, + path => $facts['path'], }, 'file' => { ensure => $file_ensure, diff --git a/manifests/wordpress.pp b/manifests/wordpress.pp index fa746de..66f93ac 100644 --- a/manifests/wordpress.pp +++ b/manifests/wordpress.pp @@ -48,8 +48,8 @@ Boolean $web_manage = true, String $web_base_dir = '/var/www/html', - String $wordpress_sitename = "wordpress.${::domain}", - String $wordpress_alias = "www.wordpress.${::domain}", + String $wordpress_sitename = "wordpress.${facts['networking']['domain']}", + String $wordpress_alias = "www.wordpress.${facts['networking']['domain']}", String $web_template = 'psick_profile/wordpress/httpd.conf.erb', String $web_virtualhost_template = 'psick_profile/wordpress/wordpress.conf.erb', Hash $web_options = {}, diff --git a/manifests/wordpress/instance.pp b/manifests/wordpress/instance.pp index 6c4c813..d6ff208 100644 --- a/manifests/wordpress/instance.pp +++ b/manifests/wordpress/instance.pp @@ -21,8 +21,8 @@ Boolean $web_manage = true, String $web_base_dir = '/var/www/html', - String $wordpress_sitename = "${title}.${::domain}", - String $wordpress_alias = "www.${title}.${::domain}", + String $wordpress_sitename = "${title}.${facts['networking']['domain']}", + String $wordpress_alias = "www.${title}.${facts['networking']['domain']}", String $web_template = 'psick_profile/wordpress/httpd.conf.erb', String $web_virtualhost_template = 'psick_profile/wordpress/wordpress.conf.erb', Hash $web_options = {}, diff --git a/metadata.json b/metadata.json index 0b639e9..ce20140 100644 --- a/metadata.json +++ b/metadata.json @@ -1,6 +1,6 @@ { "name": "example42-psick_profile", - "version": "0.1.0", + "version": "0.1.1", "author": "Alessandro Franceschi", "summary": "A collection of opinionated, reusable Puppet profiles for common applications", "license": "Apache-2.0", @@ -71,7 +71,7 @@ "version_requirement": ">= 6.21.0 < 9.0.0" } ], - "pdk-version": "2.4.0", + "pdk-version": "3.4.0", "template-url": "https://github.com/puppetlabs/pdk-templates#main", - "template-ref": "tags/2.5.0-0-g369d483" + "template-ref": "heads/main-0-g05d2de4" } diff --git a/spec/classes/vagrant/tp_spec.rb b/spec/classes/vagrant/tp_spec.rb new file mode 100644 index 0000000..aa4e0a3 --- /dev/null +++ b/spec/classes/vagrant/tp_spec.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe 'psick_profile::vagrant::tp' do + on_supported_os.each do |os, os_facts| + context "on #{os}" do + let(:facts) { os_facts } + + it { is_expected.to compile.with_all_deps } + end + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 9b1fa6f..ae7c1f6 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -25,15 +25,16 @@ next unless File.exist?(f) && File.readable?(f) && File.size?(f) begin - default_facts.merge!(YAML.safe_load(File.read(f), [], [], true)) - rescue => e + require 'deep_merge' + default_facts.deep_merge!(YAML.safe_load(File.read(f), permitted_classes: [], permitted_symbols: [], aliases: true)) + rescue StandardError => e RSpec.configuration.reporter.message "WARNING: Unable to load #{f}: #{e}" end end # read default_facts and merge them over what is provided by facterdb default_facts.each do |fact, value| - add_custom_fact fact, value + add_custom_fact fact, value, merge_facts: true end RSpec.configure do |c| @@ -46,6 +47,7 @@ end c.filter_run_excluding(bolt: true) unless ENV['GEM_BOLT'] c.after(:suite) do + RSpec::Puppet::Coverage.report!(0) end # Filter backtrace noise diff --git a/templates/gitlab/runner/sudo.erb b/templates/gitlab/runner/sudo.erb index bb01d96..ecb175b 100644 --- a/templates/gitlab/runner/sudo.erb +++ b/templates/gitlab/runner/sudo.erb @@ -1,4 +1,4 @@ # File is managed by Puppet -Cmnd_Alias ALLOWED_COMMANDS_ROOT = /opt/puppetlabs/bin/puppet preview *, /usr/bin/cat /etc/puppetlabs/code/environments/*/.r10k-deploy.json, /opt/puppetlabs/bin/puppet-query * +Cmnd_Alias ALLOWED_COMMANDS_ROOT = /opt/puppetlabs/bin/puppet preview *, /usr/bin/cat /etc/puppetlabs/code/environments/*/.r10k-deploy.json, /usr/bin/cat /etc/puppetlabs/puppetserver/code/environments/*/.r10k-deploy.json, /opt/puppetlabs/bin/puppet-query * gitlab-runner ALL=(root) NOPASSWD: ALLOWED_COMMANDS_ROOT Defaults!ALLOWED_COMMANDS_ROOT !requiretty