Skip to content

Commit

Permalink
Merge pull request #6 from Ekerhag/master
Browse files Browse the repository at this point in the history
Add support for --domain-controller option
  • Loading branch information
acjohnson committed Mar 7, 2019
2 parents bfdb761 + 74586cc commit cd672cd
Show file tree
Hide file tree
Showing 19 changed files with 186 additions and 61 deletions.
10 changes: 6 additions & 4 deletions .fixtures.yml
Original file line number Diff line number Diff line change
@@ -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"


5 changes: 5 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*.rb eol=lf
*.erb eol=lf
*.pp eol=lf
*.sh eol=lf
*.epp eol=lf
3 changes: 2 additions & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
13 changes: 13 additions & 0 deletions .pdkignore
Original file line number Diff line number Diff line change
Expand Up @@ -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/
1 change: 1 addition & 0 deletions .puppet-lint.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--relative
8 changes: 2 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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|
Expand Down
11 changes: 3 additions & 8 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
---
version: 1.1.x.{build}
branches:
only:
- master
skip_commits:
message: /^\(?doc\)?.*/
clone_depth: 10
Expand All @@ -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
Expand Down
File renamed without changes.
17 changes: 9 additions & 8 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
28 changes: 20 additions & 8 deletions manifests/join.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
Expand Down
13 changes: 9 additions & 4 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down
6 changes: 3 additions & 3 deletions metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
54 changes: 54 additions & 0 deletions spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand All @@ -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
1 change: 0 additions & 1 deletion spec/default_facts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
4 changes: 1 addition & 3 deletions spec/spec.opts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
--format
s
--format documentation
--colour
--loadby
mtime
--backtrace
Loading

0 comments on commit cd672cd

Please sign in to comment.