From 9f81dc5139f171da285dc78695776dc949287433 Mon Sep 17 00:00:00 2001 From: Benedikt Trefzer Date: Fri, 5 Jan 2024 15:26:54 +0100 Subject: [PATCH 1/9] update pdk --- .gitignore | 2 +- .pdkignore | 9 +- .rubocop.yml | 216 +++++++++++++++++++++++++++++++++++++++-- Gemfile | 41 +++++--- Rakefile | 9 +- metadata.json | 6 +- spec/default_facts.yml | 7 +- spec/spec_helper.rb | 4 +- 8 files changed, 255 insertions(+), 39 deletions(-) diff --git a/.gitignore b/.gitignore index 988dcbb..3f15512 100644 --- a/.gitignore +++ b/.gitignore @@ -16,7 +16,7 @@ /log/ /pkg/ /spec/fixtures/manifests/ -/spec/fixtures/modules/ +/spec/fixtures/modules/* /tmp/ /vendor/ /convert_report.txt diff --git a/.pdkignore b/.pdkignore index c538bea..862847a 100644 --- a/.pdkignore +++ b/.pdkignore @@ -16,7 +16,7 @@ /log/ /pkg/ /spec/fixtures/manifests/ -/spec/fixtures/modules/ +/spec/fixtures/modules/* /tmp/ /vendor/ /convert_report.txt @@ -26,20 +26,17 @@ .envrc /inventory.yaml /spec/fixtures/litmus_inventory.yaml -/appveyor.yml -/.editorconfig /.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/.rubocop.yml b/.rubocop.yml index 31e8248..5be1f9f 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -4,7 +4,7 @@ require: - rubocop-rspec AllCops: DisplayCopNames: true - TargetRubyVersion: '2.5' + TargetRubyVersion: '2.6' Include: - "**/*.rb" Exclude: @@ -111,8 +111,14 @@ Style/MethodCalledOnDoEndBlock: Enabled: true Style/StringMethods: Enabled: true +Bundler/GemFilename: + Enabled: false Bundler/InsecureProtocolSource: Enabled: false +Capybara/CurrentPathExpectation: + Enabled: false +Capybara/VisibilityMatcher: + Enabled: false Gemspec/DuplicatedAssignment: Enabled: false Gemspec/OrderedDependencies: @@ -287,11 +293,9 @@ Performance/UriDefaultParser: Enabled: false RSpec/Be: Enabled: false -RSpec/Capybara/CurrentPathExpectation: - Enabled: false RSpec/Capybara/FeatureMethods: Enabled: false -RSpec/Capybara/VisibilityMatcher: +RSpec/ContainExactly: Enabled: false RSpec/ContextMethod: Enabled: false @@ -331,6 +335,8 @@ RSpec/LeakyConstantDeclaration: Enabled: false RSpec/LetBeforeExamples: Enabled: false +RSpec/MatchArray: + Enabled: false RSpec/MissingExampleGroupArgument: Enabled: false RSpec/MultipleExpectations: @@ -373,8 +379,6 @@ Style/AccessModifierDeclarations: Enabled: false Style/AccessorGrouping: Enabled: false -Style/AsciiComments: - Enabled: false Style/BisectedAttrAccessor: Enabled: false Style/CaseLikeIf: @@ -485,35 +489,235 @@ Style/TrailingMethodEndStatement: Enabled: false Style/UnpackFirst: Enabled: false +Capybara/MatchStyle: + Enabled: false +Capybara/NegationMatcher: + Enabled: false +Capybara/SpecificActions: + Enabled: false +Capybara/SpecificFinders: + Enabled: false +Capybara/SpecificMatcher: + Enabled: false +Gemspec/DeprecatedAttributeAssignment: + Enabled: false +Gemspec/DevelopmentDependencies: + Enabled: false +Gemspec/RequireMFA: + Enabled: false +Layout/LineContinuationLeadingSpace: + Enabled: false +Layout/LineContinuationSpacing: + Enabled: false +Layout/LineEndStringConcatenationIndentation: + Enabled: false +Layout/SpaceBeforeBrackets: + Enabled: false +Lint/AmbiguousAssignment: + Enabled: false +Lint/AmbiguousOperatorPrecedence: + Enabled: false +Lint/AmbiguousRange: + Enabled: false +Lint/ConstantOverwrittenInRescue: + Enabled: false +Lint/DeprecatedConstants: + Enabled: false Lint/DuplicateBranch: Enabled: false +Lint/DuplicateMagicComment: + Enabled: false Lint/DuplicateRegexpCharacterClassElement: Enabled: false Lint/EmptyBlock: Enabled: false Lint/EmptyClass: Enabled: false +Lint/EmptyInPattern: + Enabled: false +Lint/IncompatibleIoSelectWithFiberScheduler: + Enabled: false +Lint/LambdaWithoutLiteralBlock: + Enabled: false Lint/NoReturnInBeginEndBlocks: Enabled: false +Lint/NonAtomicFileOperation: + Enabled: false +Lint/NumberedParameterAssignment: + Enabled: false +Lint/OrAssignmentToConstant: + Enabled: false +Lint/RedundantDirGlobSort: + Enabled: false +Lint/RefinementImportMethods: + Enabled: false +Lint/RequireRangeParentheses: + Enabled: false +Lint/RequireRelativeSelfPath: + Enabled: false +Lint/SymbolConversion: + Enabled: false Lint/ToEnumArguments: Enabled: false +Lint/TripleQuotes: + Enabled: false Lint/UnexpectedBlockArity: Enabled: false Lint/UnmodifiedReduceAccumulator: Enabled: false +Lint/UselessRescue: + Enabled: false +Lint/UselessRuby2Keywords: + Enabled: false +Metrics/CollectionLiteralLength: + Enabled: false +Naming/BlockForwarding: + Enabled: false Performance/CollectionLiteralInLoop: Enabled: false +Performance/ConcurrentMonotonicTime: + Enabled: false +Performance/MapCompact: + Enabled: false +Performance/RedundantEqualityComparisonBlock: + Enabled: false +Performance/RedundantSplitRegexpArgument: + Enabled: false +Performance/StringIdentifierArgument: + Enabled: false +RSpec/BeEq: + Enabled: false +RSpec/BeNil: + Enabled: false +RSpec/ChangeByZero: + Enabled: false +RSpec/ClassCheck: + Enabled: false +RSpec/DuplicatedMetadata: + Enabled: false +RSpec/ExcessiveDocstringSpacing: + Enabled: false +RSpec/FactoryBot/ConsistentParenthesesStyle: + Enabled: false +RSpec/FactoryBot/FactoryNameStyle: + Enabled: false +RSpec/FactoryBot/SyntaxMethods: + Enabled: false +RSpec/IdenticalEqualityAssertion: + Enabled: false +RSpec/NoExpectationExample: + Enabled: false +RSpec/PendingWithoutReason: + Enabled: false +RSpec/Rails/AvoidSetupHook: + Enabled: false +RSpec/Rails/HaveHttpStatus: + Enabled: false +RSpec/Rails/InferredSpecType: + Enabled: false +RSpec/Rails/MinitestAssertions: + Enabled: false +RSpec/Rails/TravelAround: + Enabled: false +RSpec/RedundantAround: + Enabled: false +RSpec/SkipBlockInsideExample: + Enabled: false +RSpec/SortMetadata: + Enabled: false +RSpec/SubjectDeclaration: + Enabled: false +RSpec/VerifiedDoubleReference: + Enabled: false +Security/CompoundHash: + Enabled: false +Security/IoMethods: + Enabled: false Style/ArgumentsForwarding: Enabled: false +Style/ArrayIntersect: + Enabled: false Style/CollectionCompact: Enabled: false +Style/ComparableClamp: + Enabled: false +Style/ConcatArrayLiterals: + Enabled: false +Style/DirEmpty: + Enabled: false Style/DocumentDynamicEvalDefinition: Enabled: false +Style/EmptyHeredoc: + Enabled: false +Style/EndlessMethod: + Enabled: false +Style/EnvHome: + Enabled: false +Style/FetchEnvVar: + Enabled: false +Style/FileEmpty: + Enabled: false +Style/FileRead: + Enabled: false +Style/FileWrite: + Enabled: false +Style/HashConversion: + Enabled: false +Style/HashExcept: + Enabled: false +Style/IfWithBooleanLiteralBranches: + Enabled: false +Style/InPatternThen: + Enabled: false +Style/MagicCommentFormat: + Enabled: false +Style/MapCompactWithConditionalBlock: + Enabled: false +Style/MapToHash: + Enabled: false +Style/MapToSet: + Enabled: false +Style/MinMaxComparison: + Enabled: false +Style/MultilineInPatternThen: + Enabled: false Style/NegatedIfElseCondition: Enabled: false +Style/NestedFileDirname: + Enabled: false Style/NilLambda: Enabled: false +Style/NumberedParameters: + Enabled: false +Style/NumberedParametersLimit: + Enabled: false +Style/ObjectThen: + Enabled: false +Style/OpenStructUse: + Enabled: false +Style/OperatorMethodCall: + Enabled: false +Style/QuotedSymbols: + Enabled: false Style/RedundantArgument: Enabled: false +Style/RedundantConstantBase: + Enabled: false +Style/RedundantDoubleSplatHashBraces: + Enabled: false +Style/RedundantEach: + Enabled: false +Style/RedundantHeredocDelimiterQuotes: + Enabled: false +Style/RedundantInitialize: + Enabled: false +Style/RedundantSelfAssignmentBranch: + Enabled: false +Style/RedundantStringEscape: + Enabled: false +Style/SelectByRegexp: + Enabled: false +Style/StringChars: + Enabled: false Style/SwapValues: Enabled: false diff --git a/Gemfile b/Gemfile index fc28658..ca0e773 100644 --- a/Gemfile +++ b/Gemfile @@ -13,22 +13,37 @@ 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.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', '< 3.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) + gem "json", '= 2.5.1', require: false if Gem::Requirement.create(['>= 3.0.0', '< 3.0.5']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) + 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 "voxpupuli-puppet-lint-plugins", '~> 5.0', require: false + gem "facterdb", '~> 1.18', require: false + gem "metadata-json-lint", '~> 3.0', require: false + gem "puppetlabs_spec_helper", '~> 6.0', require: false + gem "rspec-puppet-facts", '~> 2.0', require: false + gem "codecov", '~> 0.2', require: false + 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.5', require: false + gem "puppet-debugger", '~> 1.0', require: false + gem "rubocop", '= 1.48.1', require: false + gem "rubocop-performance", '= 1.16.0', require: false + gem "rubocop-rspec", '= 2.19.0', require: false + gem "puppet-strings", '~> 4.0', require: false + gem "rb-readline", '= 0.5.5', require: false, platforms: [:mswin, :mingw, :x64_mingw] 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 "serverspec", '~> 2.41', require: false +end +group :release_prep do + gem "puppet-strings", '~> 4.0', require: false + gem "puppetlabs_spec_helper", '~> 6.0', require: false end puppet_version = ENV['PUPPET_GEM_VERSION'] diff --git a/Rakefile b/Rakefile index 0f8754e..74415a9 100644 --- a/Rakefile +++ b/Rakefile @@ -1,12 +1,11 @@ # 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? +require 'github_changelog_generator/task' if Gem.loaded_specs.key? 'github_changelog_generator' +require 'puppet-strings/tasks' if Gem.loaded_specs.key? 'puppet-strings' def changelog_user return unless Rake.application.top_level_tasks.include? "changelog" @@ -44,7 +43,7 @@ end PuppetLint.configuration.send('disable_relative') -if Bundler.rubygems.find_name('github_changelog_generator').any? +if Gem.loaded_specs.key? 'github_changelog_generator' 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}" diff --git a/metadata.json b/metadata.json index 7851e06..d9fca5d 100644 --- a/metadata.json +++ b/metadata.json @@ -37,7 +37,7 @@ "r10k", "puppet" ], - "pdk-version": "2.5.0", - "template-url": "pdk-default#2.5.0", - "template-ref": "tags/2.5.0-0-g369d483" + "pdk-version": "3.0.1", + "template-url": "pdk-default#3.0.1", + "template-ref": "tags/3.0.1-0-gd13288a" } diff --git a/spec/default_facts.yml b/spec/default_facts.yml index f777abf..3346c39 100644 --- a/spec/default_facts.yml +++ b/spec/default_facts.yml @@ -2,7 +2,8 @@ # # Facts specified here will override the values provided by rspec-puppet-facts. --- -ipaddress: "172.16.254.254" -ipaddress6: "FE80:0000:0000:0000:AAAA:AAAA:AAAA" +networking: + ip: "172.16.254.254" + ip6: "FE80:0000:0000:0000:AAAA:AAAA:AAAA" + mac: "AA:AA:AA:AA:AA:AA" is_pe: false -macaddress: "AA:AA:AA:AA:AA:AA" diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 07db734..6820ceb 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -25,8 +25,8 @@ next unless File.exist?(f) && File.readable?(f) && File.size?(f) begin - default_facts.merge!(YAML.safe_load(File.read(f), [], [], true)) - rescue => e + default_facts.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 From bdbb74a0112e2c18a1ddd2c557ec3c76b33430e4 Mon Sep 17 00:00:00 2001 From: Benedikt Trefzer Date: Fri, 5 Jan 2024 15:57:00 +0100 Subject: [PATCH 2/9] add parameter for packet options this allows to install r10k from gem. --- manifests/init.pp | 39 ++++++++++++++++++++++----------------- spec/classes/r10k_spec.rb | 14 ++++++++++++++ 2 files changed, 36 insertions(+), 17 deletions(-) diff --git a/manifests/init.pp b/manifests/init.pp index 6691098..aa59653 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -52,22 +52,29 @@ # packages to install # @param package_ensure # what to ensure for packages +# @param package_options +# options to set for the package option used to +# install $packages. +# eg. this lets you install r10k from gem by +# setting this to: +# { 'provider' => 'gem' } # class r10k ( - String $configdir = '/etc/puppet', - Optional[String[1]] $cachedir = undef, - Optional[Integer] $pool_size = undef, - Optional[String[1]] $proxy = undef, - Optional[Hash] $sources = undef, - Optional[Hash] $git = undef, - Optional[Hash] $forge = undef, - Optional[Hash] $deploy = undef, - String $user = 'r10k', - String $home = '/var/lib/r10k', - Boolean $ensure_user = true, - Array $allowed_keys = [], - Array $packages = ['r10k'], - String[1] $package_ensure = 'installed', + String $configdir = '/etc/puppet', + Optional[String[1]] $cachedir = undef, + Optional[Integer] $pool_size = undef, + Optional[String[1]] $proxy = undef, + Optional[Hash] $sources = undef, + Optional[Hash] $git = undef, + Optional[Hash] $forge = undef, + Optional[Hash] $deploy = undef, + String $user = 'r10k', + String $home = '/var/lib/r10k', + Boolean $ensure_user = true, + Array $allowed_keys = [], + Array $packages = ['r10k'], + String[1] $package_ensure = 'installed', + Hash[String[1],String[1]] $package_options = {}, ) { if $ensure_user { class { 'r10k::user': @@ -77,9 +84,7 @@ } } - package { $packages: - ensure => $package_ensure, - } + ensure_packages($packages, { 'ensure' => $package_ensure } + $package_options) file { "${configdir}/r10k.yaml": owner => 'root', diff --git a/spec/classes/r10k_spec.rb b/spec/classes/r10k_spec.rb index e19c2a0..19fe09c 100644 --- a/spec/classes/r10k_spec.rb +++ b/spec/classes/r10k_spec.rb @@ -77,6 +77,20 @@ it_behaves_like 'r10k user' end + context 'with package_options' do + let :params do + default_params.merge( + package_options: { 'provider' => 'gem' }, + ) + end + + it_behaves_like 'r10k shared examples' + it { + is_expected.to contain_package('r10k') + .with_provider('gem') + } + end + context 'with non default user' do let :params do default_params.merge( From 14db5f3c5700e755447977b40a4d3e25cbaaddbe Mon Sep 17 00:00:00 2001 From: Benedikt Trefzer Date: Fri, 5 Jan 2024 16:02:08 +0100 Subject: [PATCH 3/9] add .github options --- .github/FUNDING.yml | 2 ++ .github/workflows/pdk.yml | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 .github/FUNDING.yml create mode 100644 .github/workflows/pdk.yml diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..37a7699 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,2 @@ +github: [cirrax] +custom: ["https://cirrax.com"] diff --git a/.github/workflows/pdk.yml b/.github/workflows/pdk.yml new file mode 100644 index 0000000..4012fa3 --- /dev/null +++ b/.github/workflows/pdk.yml @@ -0,0 +1,37 @@ +name: PDK + +on: + - 'push' + - 'pull_request' + +jobs: + validate: + runs-on: ubuntu-latest + container: puppet/pdk:latest + outputs: + puppet_unit_test_matrix: ${{ steps.get-outputs.outputs.puppet_unit_test_matrix }} + github_action_test_matrix: ${{ steps.get-outputs.outputs.github_action_test_matrix }} + steps: + - name: Install build-essential + run: | + export DEBIAN_FRONTEND=noninteractive; + apt-get --yes update + apt-get --yes install build-essential + - name: Check out repository code + uses: actions/checkout@v3 + - name: run pdk validate + run: pdk validate + + unit-test: + runs-on: ubuntu-latest + container: puppet/pdk:latest + steps: + - name: Install build-essential + run: | + export DEBIAN_FRONTEND=noninteractive; + apt-get --yes update + apt-get --yes install build-essential + - name: Check out repository code + uses: actions/checkout@v3 + - name: run pdk test unit + run: pdk test unit From 490b91765b932e484ba8b7a522649f9b0a2a3900 Mon Sep 17 00:00:00 2001 From: Benedikt Trefzer Date: Fri, 5 Jan 2024 16:09:01 +0100 Subject: [PATCH 4/9] update metadata dependencies --- metadata.json | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/metadata.json b/metadata.json index d9fca5d..42a8ee2 100644 --- a/metadata.json +++ b/metadata.json @@ -10,17 +10,15 @@ "dependencies": [ { "name": "puppetlabs/stdlib", - "version_requirement": ">= 3.2.0 < 8.0.0" + "version_requirement": ">= 3.2.0 < 10.0.0" } ], "operatingsystem_support": [ { "operatingsystem": "Debian", "operatingsystemrelease": [ - "8", - "9", - "10", - "11" + "11", + "12" ] }, { @@ -30,7 +28,7 @@ "requirements": [ { "name": "puppet", - "version_requirement": ">=4.0.0 < 8.0.0" + "version_requirement": ">=4.0.0 < 9.0.0" } ], "tags": [ From 62735d5117416070f4e2466e2068b5548ceceab6 Mon Sep 17 00:00:00 2001 From: Benedikt Trefzer Date: Fri, 5 Jan 2024 16:09:59 +0100 Subject: [PATCH 5/9] use puppetforge for fixtures --- .fixtures.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.fixtures.yml b/.fixtures.yml index de87dbd..5bb41ec 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -1,7 +1,6 @@ --- fixtures: - repositories: - stdlib: - repo: "https://github.com/puppetlabs/puppetlabs-stdlib.git" + forge_modules: + stdlib: puppetlabs/stdlib symlinks: r10k: "#{source_dir}" From 5dbd2cb9d033c544f31b588e829807e744cafe91 Mon Sep 17 00:00:00 2001 From: Benedikt Trefzer Date: Fri, 5 Jan 2024 18:09:04 +0100 Subject: [PATCH 6/9] add parameter to specifify r10k binary to use in script --- manifests/init.pp | 35 ++++++++++++++++------------- templates/update_environment.sh.erb | 4 ++-- templates/update_module.sh.erb | 2 +- 3 files changed, 23 insertions(+), 18 deletions(-) diff --git a/manifests/init.pp b/manifests/init.pp index aa59653..b0feaa3 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -58,23 +58,28 @@ # eg. this lets you install r10k from gem by # setting this to: # { 'provider' => 'gem' } +# @param r10k_command +# r10k command, if it is not saved in path, +# you can specify the command with the path # class r10k ( - String $configdir = '/etc/puppet', - Optional[String[1]] $cachedir = undef, - Optional[Integer] $pool_size = undef, - Optional[String[1]] $proxy = undef, - Optional[Hash] $sources = undef, - Optional[Hash] $git = undef, - Optional[Hash] $forge = undef, - Optional[Hash] $deploy = undef, - String $user = 'r10k', - String $home = '/var/lib/r10k', - Boolean $ensure_user = true, - Array $allowed_keys = [], - Array $packages = ['r10k'], - String[1] $package_ensure = 'installed', - Hash[String[1],String[1]] $package_options = {}, + String $configdir = '/etc/puppet', + Boolean $ensure_configdir = false, + Optional[String[1]] $cachedir = undef, + Optional[Integer] $pool_size = undef, + Optional[String[1]] $proxy = undef, + Optional[Hash] $sources = undef, + Optional[Hash] $git = undef, + Optional[Hash] $forge = undef, + Optional[Hash] $deploy = undef, + String $user = 'r10k', + String $home = '/var/lib/r10k', + Boolean $ensure_user = true, + Array $allowed_keys = [], + Array $packages = ['r10k'], + String[1] $package_ensure = 'installed', + Hash[String[1],String[1]] $package_options = {}, + String[1] $r10k_command = 'r10k', ) { if $ensure_user { class { 'r10k::user': diff --git a/templates/update_environment.sh.erb b/templates/update_environment.sh.erb index 46ef140..5ea48ac 100644 --- a/templates/update_environment.sh.erb +++ b/templates/update_environment.sh.erb @@ -19,7 +19,7 @@ if [[ "$ENV" == 'MODULE' ]]; then echo "$ENV2 not allowed, only [A-Za-z0-9_]+ allowed as module" exit 1 fi - (cd <%= @configdir %>; r10k --config=r10k.yaml deploy --verbose=debug module $ENV2 2>&1 |grep -E '(ERROR|INFO|Updating)') + (cd <%= @configdir %>; <%= @r10k_command %> --config=r10k.yaml deploy --verbose=debug module $ENV2 2>&1 |grep -E '(ERROR|INFO|Updating)') else if [[ ! ( "$ENV2" == '' || "$ENV2" == '--puppetfile' ) ]]; then echo "only --puppetfile allowed as second argument" @@ -28,5 +28,5 @@ else if [[ $ENV == 'all' ]]; then ENV='' fi - (cd <%= @configdir %>; r10k --config=r10k.yaml deploy --verbose=debug environment $ENV $ENV2 2>&1 |grep -E '(ERROR|INFO|Updating)') + (cd <%= @configdir %>; <%= @r10k_command %> --config=r10k.yaml deploy --verbose=debug environment $ENV $ENV2 2>&1 |grep -E '(ERROR|INFO|Updating)') fi diff --git a/templates/update_module.sh.erb b/templates/update_module.sh.erb index a08f6c8..5b4233b 100644 --- a/templates/update_module.sh.erb +++ b/templates/update_module.sh.erb @@ -7,4 +7,4 @@ if [[ ! "$MODULE" =~ ^[A-Za-z0-9_]+$ ]]; then exit 1 fi -(cd <%= @configdir %>; r10k --config=r10k.yaml deploy --verbose=debug module $MODULE 2>&1 |grep -E '(ERROR|INFO|Updating)') +(cd <%= @configdir %>; <%= @r10k_command %> --config=r10k.yaml deploy --verbose=debug module $MODULE 2>&1 |grep -E '(ERROR|INFO|Updating)') From 6e3a153cc91a067e1918e591f28bec5db1c88d93 Mon Sep 17 00:00:00 2001 From: Benedikt Trefzer Date: Fri, 5 Jan 2024 18:18:49 +0100 Subject: [PATCH 7/9] add hiera.yaml --- hiera.yaml | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 hiera.yaml diff --git a/hiera.yaml b/hiera.yaml new file mode 100644 index 0000000..e608c51 --- /dev/null +++ b/hiera.yaml @@ -0,0 +1,13 @@ +--- +version: 5 + +defaults: + datadir: 'data' + data_hash: 'yaml_data' + +hierarchy: + - name: 'Operating System Family' + path: '%{facts.os.family}-family.yaml' + + - name: 'common' + path: 'common.yaml' From a12a824f514f9c230338c5898c4976356aad5fa6 Mon Sep 17 00:00:00 2001 From: Benedikt Trefzer Date: Fri, 5 Jan 2024 16:16:37 +0100 Subject: [PATCH 8/9] add support for RedHat/AlmaLinux since there are no packages available we install with gem provider --- README.md | 3 +++ data/RedHat-family.yaml | 13 +++++++++++++ manifests/init.pp | 8 ++++++++ metadata.json | 21 ++++++++++++++++++++- 4 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 data/RedHat-family.yaml diff --git a/README.md b/README.md index 3d55992..42a8143 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,9 @@ fetch git repositories. none +## Remarks +if you install r10k with the gem provider (default for RedHat family) +you need to ensure that you have ruby-devel (or ruby-dev) package installed. ## Contributing diff --git a/data/RedHat-family.yaml b/data/RedHat-family.yaml new file mode 100644 index 0000000..60693d9 --- /dev/null +++ b/data/RedHat-family.yaml @@ -0,0 +1,13 @@ +--- +# r10k setting for RedHat os family + +# there are no packages available, so we install from gem + +r10k::package_options: + provider: 'gem' + +r10k::configdir: '/etc/puppetlabs/r10k' +r10k::home: '/etc/puppetlabs/r10k' + +# since /usr/local/bin is not in path +r10k::r10k_command: '/usr/local/bin/r10k' diff --git a/manifests/init.pp b/manifests/init.pp index b0feaa3..2db7b9f 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -4,6 +4,8 @@ # @param configdir # where the configfile should be put # defaults to '/etc/puppet' +# @param ensure_configdir +# set this to true to ensure the config direcory exists # @param cachedir # The 'cachedir' setting controls where cached content, such as mirrored Git # repositories, are stored on the local machine. This location should be @@ -89,6 +91,12 @@ } } + if $ensure_configdir { + file { $configdir: + ensure => 'directory', + } + } + ensure_packages($packages, { 'ensure' => $package_ensure } + $package_options) file { "${configdir}/r10k.yaml": diff --git a/metadata.json b/metadata.json index 42a8ee2..bf806a3 100644 --- a/metadata.json +++ b/metadata.json @@ -22,7 +22,26 @@ ] }, { - "operatingsystem": "Ubuntu" + "operatingsystem": "Ubuntu", + "operatingsystemrelease": [ + "20.04", + "22.04" + ] + }, + { + "operatingsystem": "RedHat", + "operatingsystemrelease": [ + "7", + "8", + "9" + ] + }, + { + "operatingsystem": "AlmaLinux", + "operatingsystemrelease": [ + "8", + "9" + ] } ], "requirements": [ From a4e6cf5bf543937802972c058b47c4225a02baba Mon Sep 17 00:00:00 2001 From: Benedikt Trefzer Date: Mon, 8 Jan 2024 17:16:15 +0100 Subject: [PATCH 9/9] update REFERENCE.md --- REFERENCE.md | 220 +++++++++++++++++++++++++++++---------------------- 1 file changed, 126 insertions(+), 94 deletions(-) diff --git a/REFERENCE.md b/REFERENCE.md index a15ae0b..8b9116a 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -7,10 +7,10 @@ ### Classes * [`r10k`](#r10k): Main r10k class -* [`r10k::authorized_key`](#r10kauthorized_key): Define an authorized key on the server -* [`r10k::gitolite_hooks`](#r10kgitolite_hooks): this class installs hooks on a gitolite server to trigger r10k updates -* [`r10k::ssh_key`](#r10kssh_key): Generate an SSH authentication key Key generation for (passwordless) authentication to a remote system. -* [`r10k::user`](#r10kuser): this class creates an r10k user with ssh key etc. +* [`r10k::authorized_key`](#r10k--authorized_key): Define an authorized key on the server +* [`r10k::gitolite_hooks`](#r10k--gitolite_hooks): this class installs hooks on a gitolite server to trigger r10k updates +* [`r10k::ssh_key`](#r10k--ssh_key): Generate an SSH authentication key Key generation for (passwordless) authentication to a remote system. +* [`r10k::user`](#r10k--user): this class creates an r10k user with ssh key etc. ## Classes @@ -22,22 +22,25 @@ Main r10k class The following parameters are available in the `r10k` class: -* [`configdir`](#configdir) -* [`cachedir`](#cachedir) -* [`pool_size`](#pool_size) -* [`proxy`](#proxy) -* [`deploy`](#deploy) -* [`sources`](#sources) -* [`git`](#git) -* [`forge`](#forge) -* [`user`](#user) -* [`home`](#home) -* [`ensure_user`](#ensure_user) -* [`allowed_keys`](#allowed_keys) -* [`packages`](#packages) -* [`package_ensure`](#package_ensure) - -##### `configdir` +* [`configdir`](#-r10k--configdir) +* [`ensure_configdir`](#-r10k--ensure_configdir) +* [`cachedir`](#-r10k--cachedir) +* [`pool_size`](#-r10k--pool_size) +* [`proxy`](#-r10k--proxy) +* [`deploy`](#-r10k--deploy) +* [`sources`](#-r10k--sources) +* [`git`](#-r10k--git) +* [`forge`](#-r10k--forge) +* [`user`](#-r10k--user) +* [`home`](#-r10k--home) +* [`ensure_user`](#-r10k--ensure_user) +* [`allowed_keys`](#-r10k--allowed_keys) +* [`packages`](#-r10k--packages) +* [`package_ensure`](#-r10k--package_ensure) +* [`package_options`](#-r10k--package_options) +* [`r10k_command`](#-r10k--r10k_command) + +##### `configdir` Data type: `String` @@ -46,7 +49,15 @@ defaults to '/etc/puppet' Default value: `'/etc/puppet'` -##### `cachedir` +##### `ensure_configdir` + +Data type: `Boolean` + +set this to true to ensure the config direcory exists + +Default value: `false` + +##### `cachedir` Data type: `Optional[String[1]]` @@ -55,18 +66,18 @@ repositories, are stored on the local machine. This location should be persistent, as environments and modules may rely on these files in order to be updated. -Default value: ``undef`` +Default value: `undef` -##### `pool_size` +##### `pool_size` Data type: `Optional[Integer]` The pool_size setting is a number to determine how many threads should be spawn while updating modules. -Default value: ``undef`` +Default value: `undef` -##### `proxy` +##### `proxy` Data type: `Optional[String[1]]` @@ -75,9 +86,9 @@ operations performed by r10k. This includes requests to the Puppet Forge as well as any Git operations performed against an HTTP/HTTPS remote. @see https://github.com/puppetlabs/r10k/blob/main/doc/dynamic-environments/configuration.mkd#proxy -Default value: ``undef`` +Default value: `undef` -##### `deploy` +##### `deploy` Data type: `Optional[Hash]` @@ -87,9 +98,9 @@ Example (hiera, yaml): r10k::deploy: generate_types: true -Default value: ``undef`` +Default value: `undef` -##### `sources` +##### `sources` Data type: `Optional[Hash]` @@ -101,27 +112,27 @@ Example (hiera): remote: 'git@somewhere:main-puppet' basedir: '/etc/puppet/environments' -Default value: ``undef`` +Default value: `undef` -##### `git` +##### `git` Data type: `Optional[Hash]` Hash of git configurations, defaults to {} See r10k.yaml file for possible options (section git) -Default value: ``undef`` +Default value: `undef` -##### `forge` +##### `forge` Data type: `Optional[Hash]` Hash of forge configurations, defaults to {} See r10k.yaml file for possible options (section forge) -Default value: ``undef`` +Default value: `undef` -##### `user` +##### `user` Data type: `String` @@ -129,7 +140,7 @@ the r10k user, defaults to 'r10k' Default value: `'r10k'` -##### `home` +##### `home` Data type: `String` @@ -137,7 +148,7 @@ the home directory of $user Default value: `'/var/lib/r10k'` -##### `ensure_user` +##### `ensure_user` Data type: `Boolean` @@ -145,9 +156,9 @@ if we should ensure the r10k user (if true, includes r10k::user) defaults to true -Default value: ``true`` +Default value: `true` -##### `allowed_keys` +##### `allowed_keys` Data type: `Array` @@ -156,7 +167,7 @@ normaly this is the key used by git hooks. Default value: `[]` -##### `packages` +##### `packages` Data type: `Array` @@ -164,7 +175,7 @@ packages to install Default value: `['r10k']` -##### `package_ensure` +##### `package_ensure` Data type: `String[1]` @@ -172,7 +183,28 @@ what to ensure for packages Default value: `'installed'` -### `r10k::authorized_key` +##### `package_options` + +Data type: `Hash[String[1],String[1]]` + +options to set for the package option used to +install $packages. +eg. this lets you install r10k from gem by +setting this to: +{ 'provider' => 'gem' } + +Default value: `{}` + +##### `r10k_command` + +Data type: `String[1]` + +r10k command, if it is not saved in path, +you can specify the command with the path + +Default value: `'r10k'` + +### `r10k::authorized_key` Define an authorized key on the server @@ -180,29 +212,29 @@ Define an authorized key on the server The following parameters are available in the `r10k::authorized_key` class: -* [`username`](#username) -* [`home`](#home) -* [`keys`](#keys) -* [`destination`](#destination) -* [`owner`](#owner) -* [`group`](#group) -* [`mode`](#mode) -* [`command`](#command) -* [`options`](#options) +* [`username`](#-r10k--authorized_key--username) +* [`home`](#-r10k--authorized_key--home) +* [`keys`](#-r10k--authorized_key--keys) +* [`destination`](#-r10k--authorized_key--destination) +* [`owner`](#-r10k--authorized_key--owner) +* [`group`](#-r10k--authorized_key--group) +* [`mode`](#-r10k--authorized_key--mode) +* [`command`](#-r10k--authorized_key--command) +* [`options`](#-r10k--authorized_key--options) -##### `username` +##### `username` Data type: `String[1]` the username to put the file for -##### `home` +##### `home` Data type: `String[1]` the users homedirectory -##### `keys` +##### `keys` Data type: `Array` @@ -210,16 +242,16 @@ an array of keys to concat Default value: `[]` -##### `destination` +##### `destination` Data type: `Optional[String[1]]` use this if you want to set a different destination than '~/.ssh/authorized_keys' -Default value: ``undef`` +Default value: `undef` -##### `owner` +##### `owner` Data type: `String[1]` @@ -227,7 +259,7 @@ owner for the authorized_keys file Default value: `$username` -##### `group` +##### `group` Data type: `String[1]` @@ -235,7 +267,7 @@ group for the authorized_keys file Default value: `$username` -##### `mode` +##### `mode` Data type: `String[1]` @@ -243,7 +275,7 @@ mode for the authorized_keys file Default value: `'0644'` -##### `command` +##### `command` Data type: `String[1]` @@ -252,7 +284,7 @@ defaults to '/var/lib/r10k/update_environment.sh' Default value: `'/var/lib/r10k/update_environment.sh'` -##### `options` +##### `options` Data type: `Array` @@ -260,7 +292,7 @@ defaults to: [no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty] Default value: `['no-port-forwarding','no-X11-forwarding','no-agent-forwarding','no-pty']` -### `r10k::gitolite_hooks` +### `r10k::gitolite_hooks` this class installs hooks on a gitolite server to trigger r10k updates @@ -269,14 +301,14 @@ to trigger r10k updates The following parameters are available in the `r10k::gitolite_hooks` class: -* [`hook_path`](#hook_path) -* [`hook_name`](#hook_name) -* [`multihook_name`](#multihook_name) -* [`multihook_scripts`](#multihook_scripts) -* [`gitolite_user`](#gitolite_user) -* [`packages`](#packages) +* [`hook_path`](#-r10k--gitolite_hooks--hook_path) +* [`hook_name`](#-r10k--gitolite_hooks--hook_name) +* [`multihook_name`](#-r10k--gitolite_hooks--multihook_name) +* [`multihook_scripts`](#-r10k--gitolite_hooks--multihook_scripts) +* [`gitolite_user`](#-r10k--gitolite_hooks--gitolite_user) +* [`packages`](#-r10k--gitolite_hooks--packages) -##### `hook_path` +##### `hook_path` Data type: `String` @@ -285,7 +317,7 @@ defaults to: '/var/lib/gitolite/scripts' Default value: `'/var/lib/gitolite/scripts'` -##### `hook_name` +##### `hook_name` Data type: `String` @@ -293,7 +325,7 @@ filename of the update hook script Default value: `'update-r10k-branch'` -##### `multihook_name` +##### `multihook_name` Data type: `String` @@ -303,7 +335,7 @@ defaults to: '/var/lib/gitolite/scripts/multihook_r10k_email' Default value: `'multihook_r10k_email'` -##### `multihook_scripts` +##### `multihook_scripts` Data type: `Array` @@ -314,7 +346,7 @@ $hook_name is added by default. Default value: `[]` -##### `gitolite_user` +##### `gitolite_user` Data type: `String` @@ -323,7 +355,7 @@ defaults to 'gitolite' Default value: `'gitolite'` -##### `packages` +##### `packages` Data type: `Array` @@ -332,7 +364,7 @@ defaults to ['moreutils'] which contains pee needed for multihook Default value: `['moreutils']` -### `r10k::ssh_key` +### `r10k::ssh_key` Generate an SSH authentication key @@ -343,20 +375,20 @@ remote system. The following parameters are available in the `r10k::ssh_key` class: -* [`filename`](#filename) -* [`type`](#type) -* [`length`](#length) -* [`password`](#password) -* [`comment`](#comment) -* [`user`](#user) +* [`filename`](#-r10k--ssh_key--filename) +* [`type`](#-r10k--ssh_key--type) +* [`length`](#-r10k--ssh_key--length) +* [`password`](#-r10k--ssh_key--password) +* [`comment`](#-r10k--ssh_key--comment) +* [`user`](#-r10k--ssh_key--user) -##### `filename` +##### `filename` Data type: `String` Filename (full path) for the key. Required. -##### `type` +##### `type` Data type: `String` @@ -364,7 +396,7 @@ Type of key, either dsa, ecdsa or rsa. Defaults to rsa. Default value: `'rsa'` -##### `length` +##### `length` Data type: `Integer` @@ -373,7 +405,7 @@ regarding non RSA keys. Default value: `2048` -##### `password` +##### `password` Data type: `String` @@ -383,7 +415,7 @@ process parameters when creating the key. Default value: `''` -##### `comment` +##### `comment` Data type: `String` @@ -391,7 +423,7 @@ Comment describing the Key. Defaults to "Automatic authentication key for $user Default value: `'undef'` -##### `user` +##### `user` Data type: `String` @@ -400,7 +432,7 @@ containing the key. Defaults to "root" Default value: `'root'` -### `r10k::user` +### `r10k::user` this class creates an r10k user with ssh key etc. @@ -409,11 +441,11 @@ with ssh key etc. The following parameters are available in the `r10k::user` class: -* [`user`](#user) -* [`home`](#home) -* [`allowed_keys`](#allowed_keys) +* [`user`](#-r10k--user--user) +* [`home`](#-r10k--user--home) +* [`allowed_keys`](#-r10k--user--allowed_keys) -##### `user` +##### `user` Data type: `String` @@ -421,7 +453,7 @@ the r10k user, defaults to 'r10k' Default value: `'r10k'` -##### `home` +##### `home` Data type: `String` @@ -429,7 +461,7 @@ the home directory of $user Default value: `'/var/lib/r10k'` -##### `allowed_keys` +##### `allowed_keys` Data type: `Array`