diff --git a/.fixtures.yml b/.fixtures.yml index 28edf6f..9f1c076 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -1,5 +1,7 @@ fixtures: - repositories: - stdlib: "https://github.com/puppetlabs/puppetlabs-stdlib.git" - symlinks: - adcli: "#{source_dir}" + forge_modules: + stdlib: + repo: "puppetlabs/stdlib" + ref: "4.13.0" + + diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..9032a01 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,5 @@ +*.rb eol=lf +*.erb eol=lf +*.pp eol=lf +*.sh eol=lf +*.epp eol=lf diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index e369e3c..ea59806 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -10,7 +10,7 @@ cache: before_script: - bundle -v - rm Gemfile.lock || true - - gem update --system + - gem update --system $RUBYGEMS_VERSION - gem --version - bundle -v - bundle install --without system_tests --path vendor/bundle --jobs $(nproc) @@ -22,6 +22,7 @@ parallel_spec-Ruby 2.1.9-Puppet ~> 4.0: - bundle exec rake parallel_spec variables: PUPPET_GEM_VERSION: '~> 4.0' + RUBYGEMS_VERSION: '2.7.8' syntax lint metadata_lint check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop-Ruby 2.4.4-Puppet ~> 5.5: stage: syntax diff --git a/.pdkignore b/.pdkignore index 650022e..b713b3b 100644 --- a/.pdkignore +++ b/.pdkignore @@ -22,3 +22,16 @@ /convert_report.txt /update_report.txt .DS_Store +/appveyor.yml +/.fixtures.yml +/Gemfile +/.gitattributes +/.gitignore +/.gitlab-ci.yml +/.pdkignore +/Rakefile +/.rspec +/.rubocop.yml +/.travis.yml +/.yardopts +/spec/ diff --git a/.puppet-lint.rc b/.puppet-lint.rc new file mode 100644 index 0000000..cc96ece --- /dev/null +++ b/.puppet-lint.rc @@ -0,0 +1 @@ +--relative diff --git a/.travis.yml b/.travis.yml index c948f3f..521510d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,19 +1,18 @@ --- -sudo: false dist: trusty language: ruby cache: bundler before_install: - bundle -v - rm -f Gemfile.lock - - gem update --system + - gem update --system $RUBYGEMS_VERSION - gem --version - bundle -v script: - 'bundle exec rake $CHECK' bundler_args: --without system_tests rvm: - - 2.5.0 + - 2.5.1 env: global: - BEAKER_PUPPET_COLLECTION=puppet6 PUPPET_GEM_VERSION="~> 6.0" @@ -27,9 +26,6 @@ matrix: - env: PUPPET_GEM_VERSION="~> 5.0" CHECK=parallel_spec rvm: 2.4.4 - - - env: PUPPET_GEM_VERSION="~> 4.0" CHECK=parallel_spec - rvm: 2.1.9 branches: only: - master diff --git a/Gemfile b/Gemfile index 626d661..cf2c387 100644 --- a/Gemfile +++ b/Gemfile @@ -21,7 +21,8 @@ group :development do gem "fast_gettext", require: false if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.1.0') gem "json_pure", '<= 2.0.1', require: false if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('2.0.0') gem "json", '= 1.8.1', require: false if Gem::Version.new(RUBY_VERSION.dup) == Gem::Version.new('2.1.9') - gem "json", '<= 2.0.4', require: false if Gem::Version.new(RUBY_VERSION.dup) == Gem::Version.new('2.4.4') + 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 "puppet-module-posix-default-r#{minor_version}", require: false, platforms: [:ruby] gem "puppet-module-posix-dev-r#{minor_version}", require: false, platforms: [:ruby] gem "puppet-module-win-default-r#{minor_version}", require: false, platforms: [:mswin, :mingw, :x64_mingw] diff --git a/README.md b/README.md index 3ecfc6b..c0161e6 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,34 @@ class {'::adcli': ``` +With optional parameters: +```puppet +class {'::adcli': + ad_domain => 'ad.example.com', + ad_join_username => 'username', + ad_join_password => 'secret', + ad_join_ou => 'ou=container,dc=example,dc=com', + ad_join_domain_controller => 'dc01.example.com', + ad_join_os => 'CentOS', + ad_join_os_version => '7', + ad_join_os_service_pack => '6' +} + +``` + +Using hiera: +```yaml +adcli::ad_domain: 'ad.example.com' +adcli::ad_join_username: 'username' +adcli::ad_join_password: 'secret' +adcli::ad_join_ou: 'ou=container,dc=example,dc=com' +adcli::ad_join_domain_controller: 'dc01.example.com' +adcli::ad_join_os: 'CentOS' +adcli::ad_join_os_version: '7' +adcli::ad_join_os_service_pack: '6' +``` + + ## Reference `ad_domain` @@ -55,6 +83,11 @@ Defines the Active Directory organizational unit to use during domain join opera Type: string Default: undef +`$ad_join_domain_controller` +(optional) Specify which domain controller to use during the join operation. +Type: string +Default: undef + `$ad_join_os` (optional) Populates the Active Directory value for Operating System Name. Type: string diff --git a/Rakefile b/Rakefile index 204fb18..fbd5bb5 100644 --- a/Rakefile +++ b/Rakefile @@ -2,6 +2,7 @@ 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" @@ -28,6 +29,7 @@ def changelog_future_release end PuppetLint.configuration.send('disable_relative') +PuppetLint.configuration.send('disable_variable_scope') if Bundler.rubygems.find_name('github_changelog_generator').any? GitHubChangelogGenerator::RakeTask.new :changelog do |config| diff --git a/appveyor.yml b/appveyor.yml index bb60864..e10ba3b 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,5 +1,8 @@ --- version: 1.1.x.{build} +branches: + only: + - master skip_commits: message: /^\(?doc\)?.*/ clone_depth: 10 @@ -14,14 +17,6 @@ environment: - RUBY_VERSION: 24-x64 CHECK: syntax lint metadata_lint check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop - - - PUPPET_GEM_VERSION: ~> 4.0 - RUBY_VERSION: 21 - CHECK: parallel_spec - - - PUPPET_GEM_VERSION: ~> 4.0 - RUBY_VERSION: 21-x64 - CHECK: parallel_spec - PUPPET_GEM_VERSION: ~> 5.0 RUBY_VERSION: 24 diff --git a/tests/test.pp b/examples/test.pp similarity index 100% rename from tests/test.pp rename to examples/test.pp diff --git a/manifests/init.pp b/manifests/init.pp index fa145d1..8fd8f59 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -42,19 +42,20 @@ # Copyright 2016 Aaron Johnson # class adcli ( - $ad_domain = $adcli::params::ad_domain, - $ad_join_username = $adcli::params::ad_join_username, - $ad_join_password = $adcli::params::ad_join_password, - $ad_join_ou = $adcli::params::ad_join_ou, - $ad_join_os = $adcli::params::ad_join_os, - $ad_join_os_version = $adcli::params::ad_join_os_version, - $ad_join_os_service_pack = $adcli::params::ad_join_os_service_pack, + $ad_domain = $adcli::params::ad_domain, + $ad_join_username = $adcli::params::ad_join_username, + $ad_join_password = $adcli::params::ad_join_password, + $ad_join_ou = $adcli::params::ad_join_ou, + $ad_join_domain_controller = $adcli::params::ad_join_domain_controller, + $ad_join_os = $adcli::params::ad_join_os, + $ad_join_os_version = $adcli::params::ad_join_os_version, + $ad_join_os_service_pack = $adcli::params::ad_join_os_service_pack, ) inherits adcli::params { - validate_legacy(String, 'validate_string', $ad_domain) validate_legacy(String, 'validate_string', $ad_join_username) validate_legacy(String, 'validate_string', $ad_join_password) validate_legacy(String, 'validate_string', $ad_join_ou) + validate_legacy(String, 'validate_string', $ad_join_domain_controller) validate_legacy(String, 'validate_string', $ad_join_os) validate_legacy(String, 'validate_string', $ad_join_os_version) validate_legacy(String, 'validate_string', $ad_join_os_service_pack) diff --git a/manifests/join.pp b/manifests/join.pp index bcb58db..a42b23e 100644 --- a/manifests/join.pp +++ b/manifests/join.pp @@ -5,13 +5,14 @@ # See README.md for more details # class adcli::join ( - $ad_domain = $adcli::ad_domain, - $ad_join_username = $adcli::ad_join_username, - $ad_join_password = $adcli::ad_join_password, - $ad_join_ou = $adcli::ad_join_ou, - $ad_join_os = $adcli::ad_join_os, - $ad_join_os_version = $adcli::ad_join_os_version, - $ad_join_os_service_pack = $adcli::ad_join_os_service_pack + $ad_domain = $adcli::ad_domain, + $ad_join_username = $adcli::ad_join_username, + $ad_join_password = $adcli::ad_join_password, + $ad_join_ou = $adcli::ad_join_ou, + $ad_join_domain_controller = $adcli::ad_join_domain_controller, + $ad_join_os = $adcli::ad_join_os, + $ad_join_os_version = $adcli::ad_join_os_version, + $ad_join_os_service_pack = $adcli::ad_join_os_service_pack ) { if $ad_domain == undef { @@ -27,17 +28,28 @@ notify {'For Active Directory join to work you must specify the ad_join_ou parameter.':} } else { + if $ad_join_domain_controller != undef { + $ad_join_domain_controller_command = " --domain-controller='${ad_join_domain_controller}'" + } else { + $ad_join_domain_controller_command = '' + } if $ad_join_os != undef { $ad_join_os_command = " --os-name=\'${ad_join_os}\'" + } else { + $ad_join_os_command = '' } if $ad_join_os_version != undef { $ad_join_os_version_command = " --os-version=\'${ad_join_os_version}\'" + } else { + $ad_join_os_version_command = '' } if $ad_join_os_service_pack != undef { $ad_join_os_service_pack_command = " --os-service-pack=\'${ad_join_os_service_pack}\'" + } else { + $ad_join_os_service_pack_command = '' } exec {'adcli_join': - command => "/bin/echo -n \'${ad_join_password}\' | /usr/sbin/adcli join --login-user=\'${ad_join_username}\' \ + command => "/bin/echo -n \'${ad_join_password}\' | /usr/sbin/adcli join ${ad_join_domain_controller_command} --login-user=\'${ad_join_username}\' \ --domain=\'${ad_domain}\' --domain-ou=\'${ad_join_ou}\' --stdin-password --verbose ${ad_join_os_command} \ ${ad_join_os_version_command} ${ad_join_os_service_pack_command}", logoutput => true, diff --git a/manifests/params.pp b/manifests/params.pp index 0909754..1ce085b 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -10,10 +10,15 @@ # Parameters :: adcli # ---------------------------------------------------------------------------- - $ad_domain = undef - $ad_join_username = undef - $ad_join_password = undef - $ad_join_ou = undef + $ad_domain = undef + $ad_join_username = undef + $ad_join_password = undef + $ad_join_ou = undef + $ad_join_domain_controller = undef + $ad_join_os = undef + $ad_join_os_version = undef + $ad_join_os_service_pack = undef + if $::osfamily == 'RedHat' and $::operatingsystemmajrelease < '6' { fail("Unsupported platform: puppet-adcli does not currently support RedHat ${::operatingsystemmajrelease}") diff --git a/metadata.json b/metadata.json index 6393a14..5840154 100644 --- a/metadata.json +++ b/metadata.json @@ -45,7 +45,7 @@ "freeipa", "ipa" ], - "pdk-version": "1.7.1", + "pdk-version": "1.9.0", "template-url": "file:///opt/puppetlabs/pdk/share/cache/pdk-templates.git", - "template-ref": "1.7.1-0-g810b982" -} + "template-ref": "1.9.0-0-g7281db5" +} \ No newline at end of file diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index b1540f2..be7528f 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -15,6 +15,7 @@ ad_domain: 'ad.example.com', ad_join_username: 'userid', ad_join_password: 'secret', + ad_join_domain_controller: 'dc01.example.com', ad_join_ou: 'cn=computers,dn=ad,dn=example,dn=com', ad_join_os: 'RedHat', ad_join_os_version: '6', @@ -44,6 +45,7 @@ ad_domain: 'ad.example.com', ad_join_username: 'userid', ad_join_password: 'secret', + ad_join_domain_controller: 'dc01.example.com', ad_join_ou: 'cn=computers,dn=ad,dn=example,dn=com', ad_join_os: 'RedHat', ad_join_os_version: '7', @@ -58,4 +60,56 @@ it { is_expected.to contain_exec('adcli_join') } end end + + describe 'on RedHat 7.6' do + let(:facts) do + { + osfamily: 'RedHat', + operatingsystemrelease: '7.6', + operatingsystemmajrelease: '7', + rubyversion: '1.9.3', + } + end + let(:params) do + { + ad_domain: 'ad.example.com', + ad_join_username: 'userid', + ad_join_password: 'secret', + ad_join_ou: 'cn=computers,dn=ad,dn=example,dn=com', + } + end + + context 'with only required parameters' do + it { is_expected.to contain_class('adcli::install') } + it { is_expected.to contain_class('adcli::join') } + it { is_expected.to contain_package('adcli').with_ensure('present') } + it { is_expected.to contain_exec('adcli_join') } + end + end + + describe 'on RedHat 6.7' do + let(:facts) do + { + osfamily: 'RedHat', + operatingsystemrelease: '6.7', + operatingsystemmajrelease: '6', + rubyversion: '1.9.3', + } + end + let(:params) do + { + ad_domain: 'ad.example.com', + ad_join_username: 'userid', + ad_join_password: 'secret', + ad_join_ou: 'cn=computers,dn=ad,dn=example,dn=com', + } + end + + context 'with only required parameters' do + it { is_expected.to contain_class('adcli::install') } + it { is_expected.to contain_class('adcli::join') } + it { is_expected.to contain_package('adcli').with_ensure('present') } + it { is_expected.to contain_exec('adcli_join') } + end + end end diff --git a/spec/default_facts.yml b/spec/default_facts.yml index e10d991..ea1e480 100644 --- a/spec/default_facts.yml +++ b/spec/default_facts.yml @@ -2,7 +2,6 @@ # # Facts specified here will override the values provided by rspec-puppet-facts. --- -concat_basedir: "" ipaddress: "172.16.254.254" is_pe: false macaddress: "AA:AA:AA:AA:AA:AA" diff --git a/spec/spec.opts b/spec/spec.opts index 91cd642..106ebd3 100644 --- a/spec/spec.opts +++ b/spec/spec.opts @@ -1,6 +1,4 @@ ---format -s +--format documentation --colour ---loadby mtime --backtrace diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 5e721b7..2a764ab 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,11 +1,7 @@ require 'puppetlabs_spec_helper/module_spec_helper' require 'rspec-puppet-facts' -begin - require 'spec_helper_local' if File.file?(File.join(File.dirname(__FILE__), 'spec_helper_local.rb')) -rescue LoadError => loaderror - warn "Could not require spec_helper_local: #{loaderror.message}" -end +require 'spec_helper_local' if File.file?(File.join(File.dirname(__FILE__), 'spec_helper_local.rb')) include RspecPuppetFacts @@ -14,16 +10,24 @@ facterversion: Facter.version, } -default_facts_path = File.expand_path(File.join(File.dirname(__FILE__), 'default_facts.yml')) -default_module_facts_path = File.expand_path(File.join(File.dirname(__FILE__), 'default_module_facts.yml')) +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')), +] -if File.exist?(default_facts_path) && File.readable?(default_facts_path) - default_facts.merge!(YAML.safe_load(File.read(default_facts_path))) -end +default_fact_files.each do |f| + next unless File.exist?(f) && File.readable?(f) && File.size?(f) -if File.exist?(default_module_facts_path) && File.readable?(default_module_facts_path) - default_facts.merge!(YAML.safe_load(File.read(default_module_facts_path))) + begin + default_facts.merge!(YAML.safe_load(File.read(f))) + rescue => e + RSpec.configuration.reporter.message "WARNING: Unable to load #{f}: #{e}" + end end +RSpec.configure do |c| + c.mock_with :rspec +end +require 'puppetlabs_spec_helper/module_spec_helper' RSpec.configure do |c| c.default_facts = default_facts @@ -32,12 +36,15 @@ # by default Puppet runs at warning level Puppet.settings[:strict] = :warning end + c.filter_run_excluding(bolt: true) unless ENV['GEM_BOLT'] + c.after(:suite) do + end end 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) - last_module.const_get(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