diff --git a/.github/workflows/CI.yaml b/.github/workflows/CI.yaml new file mode 100644 index 0000000..3abd486 --- /dev/null +++ b/.github/workflows/CI.yaml @@ -0,0 +1,35 @@ +# CI.yaml --- Check Puppet module + +name: CI + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + + workflow_dispatch: + +jobs: + check: + strategy: + fail-fast: false + matrix: + puppet_version: [6, 7] + + name: Puppet ${{ matrix.puppet_version }} + runs-on: ubuntu-latest + + steps: + - name: Clone repository + uses: actions/checkout@v2 + + - name: Run pdk validate + uses: puppets-epic-show-theatre/action-pdk-validate@31b5407676af16b690b2b8c54c0767af72fcc34f + with: + puppet-version: ${{ matrix.puppet_version }} + + - name: Run pdk test unit + uses: puppets-epic-show-theatre/action-pdk-test-unit@193987acba9977d1825fefbcbaf8d02d6af78106 + with: + puppet-version: ${{ matrix.puppet_version }} diff --git a/.gitignore b/.gitignore index 2767022..988dcbb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,27 +1,28 @@ .git/ .*.sw[op] .metadata .yardoc .yardwarns *.iml /.bundle/ /.idea/ /.vagrant/ /coverage/ /bin/ /doc/ /Gemfile.local /Gemfile.lock /junit/ /log/ /pkg/ /spec/fixtures/manifests/ /spec/fixtures/modules/ /tmp/ /vendor/ /convert_report.txt /update_report.txt .DS_Store .project .envrc /inventory.yaml +/spec/fixtures/litmus_inventory.yaml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 8e5d2c9..fd0d11a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,37 +1,53 @@ --- stages: - syntax - unit default: cache: paths: - vendor/bundle before_script: &before_script - bundle -v - rm Gemfile.lock || true - "# Update system gems if requested. This is useful to temporarily workaround troubles in the test runner" - "# Set `rubygems_version` in the .sync.yml to set a value" - "# Ignore exit code of SIGPIPE'd yes to not fail with shell's pipefail set" - '[ -z "$RUBYGEMS_VERSION" ] || (yes || true) | gem update --system $RUBYGEMS_VERSION' - gem --version - bundle -v - bundle install --without system_tests --path vendor/bundle --jobs $(nproc) syntax lint metadata_lint check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop-Ruby 2.5.7-Puppet ~> 6: stage: syntax image: ruby:2.5.7 script: - bundle exec rake syntax lint metadata_lint check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop variables: PUPPET_GEM_VERSION: '~> 6' parallel_spec-Ruby 2.5.7-Puppet ~> 6: stage: unit image: ruby:2.5.7 script: - bundle exec rake parallel_spec variables: PUPPET_GEM_VERSION: '~> 6' +syntax lint metadata_lint check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop-Ruby 2.7.2-Puppet ~> 7: + stage: syntax + image: ruby:2.7.2 + script: + - bundle exec rake syntax lint metadata_lint check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop + variables: + PUPPET_GEM_VERSION: '~> 7' + +parallel_spec-Ruby 2.7.2-Puppet ~> 7: + stage: unit + image: ruby:2.7.2 + script: + - bundle exec rake parallel_spec + variables: + PUPPET_GEM_VERSION: '~> 7' + diff --git a/.pdkignore b/.pdkignore index 254808c..3d6703e 100644 --- a/.pdkignore +++ b/.pdkignore @@ -1,44 +1,48 @@ .git/ .*.sw[op] .metadata .yardoc .yardwarns *.iml /.bundle/ /.idea/ /.vagrant/ /coverage/ /bin/ /doc/ /Gemfile.local /Gemfile.lock /junit/ /log/ /pkg/ /spec/fixtures/manifests/ /spec/fixtures/modules/ /tmp/ /vendor/ /convert_report.txt /update_report.txt .DS_Store .project .envrc /inventory.yaml +/spec/fixtures/litmus_inventory.yaml /appveyor.yml +/.editorconfig /.fixtures.yml /Gemfile /.gitattributes /.gitignore /.gitlab-ci.yml /.pdkignore /.puppet-lint.rc /Rakefile /rakelib/ /.rspec /.rubocop.yml /.travis.yml /.yardopts /spec/ /.vscode/ /.sync.yml +/.devcontainer/ +/.github/ diff --git a/.sync.yml b/.sync.yml index 9bbb71a..2cbb964 100644 --- a/.sync.yml +++ b/.sync.yml @@ -1,6 +1,6 @@ --- spec/spec_helper.rb: mock_with: ':rspec' -.travis.yml: - branches: - - master +.pdkignore: + paths: + - /.github/ diff --git a/.travis.yml b/.travis.yml index b5b889b..9381ad1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,46 +1,45 @@ --- os: linux dist: xenial language: ruby cache: bundler before_install: - bundle -v - rm -f Gemfile.lock - "# Update system gems if requested. This is useful to temporarily workaround troubles in the test runner" - "# See https://github.com/puppetlabs/pdk-templates/commit/705154d5c437796b821691b707156e1b056d244f for an example of how this was used" - "# Ignore exit code of SIGPIPE'd yes to not fail with shell's pipefail set" - '[ -z "$RUBYGEMS_VERSION" ] || (yes || true) | gem update --system $RUBYGEMS_VERSION' - gem --version - bundle -v script: - 'bundle exec rake $CHECK' bundler_args: --without system_tests rvm: - 2.5.7 stages: - static - spec - acceptance - if: tag =~ ^v\d name: deploy jobs: fast_finish: true include: - env: CHECK="check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop syntax lint metadata_lint" stage: static - env: PUPPET_GEM_VERSION="~> 6.0" CHECK=parallel_spec rvm: 2.5.7 stage: spec - env: DEPLOY_TO_FORGE=yes stage: deploy branches: only: - main - /^v\d/ - - master notifications: email: false diff --git a/Gemfile b/Gemfile index a5611e8..a167b88 100644 --- a/Gemfile +++ b/Gemfile @@ -1,72 +1,62 @@ source ENV['GEM_SOURCE'] || 'https://rubygems.org' def location_for(place_or_version, fake_version = nil) git_url_regex = %r{\A(?(https?|git)[:@][^#]*)(#(?.*))?} file_url_regex = %r{\Afile:\/\/(?.*)} if place_or_version && (git_url = place_or_version.match(git_url_regex)) [fake_version, { git: git_url[:url], branch: git_url[:branch], require: false }].compact elsif place_or_version && (file_url = place_or_version.match(file_url_regex)) ['>= 0', { path: File.expand_path(file_url[:path]), require: false }] else [place_or_version, { require: false }] 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] 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] end puppet_version = ENV['PUPPET_GEM_VERSION'] facter_version = ENV['FACTER_GEM_VERSION'] hiera_version = ENV['HIERA_GEM_VERSION'] gems = {} gems['puppet'] = location_for(puppet_version) # If facter or hiera versions have been specified via the environment # variables gems['facter'] = location_for(facter_version) if facter_version gems['hiera'] = location_for(hiera_version) if hiera_version -if Gem.win_platform? && puppet_version =~ %r{^(file:///|git://)} - # If we're using a Puppet gem on Windows which handles its own win32-xxx gem - # dependencies (>= 3.5.0), set the maximum versions (see PUP-6445). - gems['win32-dir'] = ['<= 0.4.9', require: false] - gems['win32-eventlog'] = ['<= 0.6.5', require: false] - gems['win32-process'] = ['<= 0.7.5', require: false] - gems['win32-security'] = ['<= 0.2.5', require: false] - gems['win32-service'] = ['0.8.8', require: false] -end - gems.each do |gem_name, gem_params| gem gem_name, *gem_params end # Evaluate Gemfile.local and ~/.gemfile if they exist extra_gemfiles = [ "#{__FILE__}.local", File.join(Dir.home, '.gemfile'), ] extra_gemfiles.each do |gemfile| if File.file?(gemfile) && File.readable?(gemfile) eval(File.read(gemfile), binding) end end # vim: syntax=ruby diff --git a/README.md b/README.md index 4826116..f2014a1 100644 --- a/README.md +++ b/README.md @@ -1,138 +1,138 @@ # debconf -[![Build Status](https://travis-ci.com/smoeding/puppet-debconf.svg?branch=master)](https://travis-ci.com/smoeding/puppet-debconf) +[![Build Status](https://github.com/smoeding/puppet-debconf/actions/workflows/CI.yaml/badge.svg)](https://github.com/smoeding/puppet-debconf/actions/workflows/CI.yaml) [![Puppet Forge](https://img.shields.io/puppetforge/v/stm/debconf.svg)](https://forge.puppetlabs.com/stm/debconf) [![License](https://img.shields.io/github/license/smoeding/puppet-debconf.svg)](https://raw.githubusercontent.com/smoeding/puppet-debconf/master/LICENSE) #### Table of Contents 1. [Overview](#overview) 2. [Module Description - What does the module do?](#module-description) 3. [Setup - The basics of getting started with debconf](#setup) * [What debconf affects](#what-debconf-affects) * [Setup requirements](#setup-requirements) 4. [Usage - Configuration options and additional functionality](#usage) 5. [Reference - An under-the-hood peek at what the module is doing and how](#reference) 5. [Limitations - OS compatibility, etc.](#limitations) 6. [Development - Guide for contributing to the module](#development) ## Overview Manage entries in the Debian debconf database. ## Module Description Debian based systems use the debconf database to record configuration choices the user made during the installation of a package. The system uses the stored answers and therefore does not need to query the user again when the package is upgraded or reinstalled at a later time. The debconf type allows preseeding the database with given answers to allow an unattended package installation or modification of package defaults. The type can optionally also manage the seen flag for an item. The standard `package` type uses the responsefile parameter to provide a file with preseeded answers during installation. The `debconf` type is a more general solution as it allows to update settings without the need to install the package at the same time. ## Setup ### What debconf affects The debconf type modifies entries in the Debian debconf database. ### Setup Requirements This module uses programs provided by the Debian/Ubuntu `debconf` package. Debian assigns the `required` priority to this package so it should already be installed everywhere. ## Usage Use `debconf-show` or `debconf-get-selections` to find out about valid debconf entries for an installed package. ### Example: Use dash as replacement for the bourne shell This entry will ensure a symlink from `/bin/sh` to `/bin/dash` if `dpkg-reconfigure dash` is run the next time. It will also mark the question as seen to prevent the installer from asking this question during the installation. ```puppet debconf { 'dash/sh': type => 'boolean', value => 'true', seen => true, } ``` **Note**: Although this code is perfectly legal Puppet code, the string `'true'` (not the boolean `true`) will trigger the puppet-lint warning `quoted_booleans`. But we really want to use the string `'true'` and not the boolean truth value here. So in this case we can easily suppress the warning with a [control comment](http://puppet-lint.com/controlcomments/): ```puppet debconf { 'dash/sh': type => 'boolean', value => 'true', # lint:ignore:quoted_booleans seen => true, } ``` ### Example: Automatically set a root password for MySQL during installation These two resources preseed the installation of the `mysql-server-5.5` package with the password for the MySQL root user to use. The password has to be set twice because the installation dialog asks two times for the password to detect typos. This password is used if the package is installed after these resources have been created. ```puppet debconf { 'mysql-root-passwd': package => 'mysql-server-5.5', item => 'mysql-server/root_password', type => 'password', value => 'secret', seen => true, } debconf { 'mysql-root-passwd-again': package => 'mysql-server-5.5', item => 'mysql-server/root_password_again', type => 'password', value => 'secret', seen => true, } ``` ## Reference - [**Types**](#types) - [Type: debconf](#type-debconf) ### Types #### Type: `debconf` Ensures presence or absence of a debconf database entry on Debian based systems. **Parameters for the `debconf` type:** ##### `ensure` Ensures whether the resource is present. Valid options: `present`, `absent`. Default value: `present` ##### `item` The configuration item to manage. This is normally a string with at least one slash character. Valid options: String. Default: the title of the debconf resource. ##### `package` The name of the package that owns the item. Valid options: String. Default: the prefix of the item parameter up to the first slash character. ##### `type` The data type of the item. Valid options: `'string'`, `'boolean'`, `'select'`, `'multiselect'`, `'note'`, `'text'`, `'password'`, `'title'`. This parameter is mandatory if `ensure` is `present`. Default: Undefined. ##### `value` The value to set. Valid options: String. Default: Undefined. ##### `seen` Optionally set the `seen` flag for `item`. The `seen` flag is used by the packaging system to decide if the associated configuration question should be asked during an installation. This parameter can be left undefined if the `seen` flag should not be managed. The packaging system normally sets this flag to `true` if an item is modified. The parameter can be a boolean value and the flag is set to the specified value. Valid options: `true`, `false` or undefined. Default value: Undefined. ## Limitations This module is only useful on Debian based systems where the debconf database is used. A control comment may be needed to suppress puppet-lint warnings when you set boolean values. See the [Usage](#usage) section for an example. The value of the `type` parameter is only used when an item is created. It is not updated if the value of the item is changed later. ## Development Feel free to send pull requests for new features. diff --git a/metadata.json b/metadata.json index 6312e58..4ae22b3 100644 --- a/metadata.json +++ b/metadata.json @@ -1,44 +1,44 @@ { "name": "stm-debconf", "version": "3.3.1", "author": "stm", "summary": "Manage debconf database items on Debian based systems.", "license": "BSD-2-Clause", "source": "https://github.com/smoeding/puppet-debconf", "project_page": "https://github.com/smoeding/puppet-debconf", "issues_url": "https://github.com/smoeding/puppet-debconf/issues", "dependencies": [ ], "operatingsystem_support": [ { "operatingsystem": "Debian", "operatingsystemrelease": [ "8", "9", "10" ] }, { "operatingsystem": "Ubuntu", "operatingsystemrelease": [ "14.04", "16.04", "18.04", "20.04" ] } ], "requirements": [ { "name": "puppet", "version_requirement": ">= 5.0.0 < 8.0.0" } ], "tags": [ "debconf" ], - "pdk-version": "2.0.0", - "template-url": "pdk-default#2.0.0", - "template-ref": "tags/2.0.0-0-ge838f1d" + "pdk-version": "2.1.1", + "template-url": "pdk-default#2.1.1", + "template-ref": "tags/2.1.1-0-g03daa92" } diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index b367fde..9b1fa6f 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,61 +1,73 @@ # frozen_string_literal: true RSpec.configure do |c| c.mock_with :rspec end require 'puppetlabs_spec_helper/module_spec_helper' require 'rspec-puppet-facts' require 'spec_helper_local' if File.file?(File.join(File.dirname(__FILE__), 'spec_helper_local.rb')) include RspecPuppetFacts default_facts = { puppetversion: Puppet.version, facterversion: Facter.version, } default_fact_files = [ File.expand_path(File.join(File.dirname(__FILE__), 'default_facts.yml')), File.expand_path(File.join(File.dirname(__FILE__), 'default_module_facts.yml')), ] default_fact_files.each do |f| next unless File.exist?(f) && File.readable?(f) && File.size?(f) begin default_facts.merge!(YAML.safe_load(File.read(f), [], [], true)) rescue => 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 end RSpec.configure do |c| c.default_facts = default_facts c.before :each do # set to strictest setting for testing # by default Puppet runs at warning level Puppet.settings[:strict] = :warning Puppet.settings[:strict_variables] = true end c.filter_run_excluding(bolt: true) unless ENV['GEM_BOLT'] c.after(:suite) do end + + # Filter backtrace noise + backtrace_exclusion_patterns = [ + %r{spec_helper}, + %r{gems}, + ] + + if c.respond_to?(:backtrace_exclusion_patterns) + c.backtrace_exclusion_patterns = backtrace_exclusion_patterns + elsif c.respond_to?(:backtrace_clean_patterns) + c.backtrace_clean_patterns = backtrace_exclusion_patterns + end end # Ensures that a module is defined # @param module_name Name of the module def ensure_module_defined(module_name) module_name.split('::').reduce(Object) do |last_module, next_module| last_module.const_set(next_module, Module.new) unless last_module.const_defined?(next_module, false) last_module.const_get(next_module, false) end end # 'spec_overrides' from sync.yml will appear below this line