Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code cleanup and refactoring #23

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .fixtures.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
fixtures:
symlinks:
profile: "#{source_dir}"
repositories:
stdlib: "git://github.com/puppetlabs/puppetlabs-stdlib"
apache: "git://github.com/puppetlabs/puppetlabs-apache"
concat: "git://github.com/puppetlabs/puppetlabs-concat"
firewall: "git://github.com/puppetlabs/puppetlabs-firewall"
ntp: "git://github.com/puppetlabs/puppetlabs-ntp"
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -213,3 +213,5 @@ pip-log.txt

#Mr Developer
.mr.developer.cfg

spec/fixtures/
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
John Puskar 08/09/17
- Refactored group_members to group_members for readability and to fix core functionality.
8 changes: 8 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true
source "https://rubygems.org"

# gem "rails"
gem 'rake'
gem 'rspec-puppet'
gem 'puppet'
gem 'puppetlabs_spec_helper'
62 changes: 62 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
GEM
remote: https://rubygems.org/
specs:
diff-lcs (1.3)
facter (2.4.6)
fast_gettext (1.1.0)
gettext (3.2.2)
locale (>= 2.0.5)
text (>= 1.3.0)
gettext-setup (0.13)
fast_gettext (~> 1.1.0)
gettext (>= 3.0.2)
locale
hiera (3.3.0)
json_pure (1.8.6)
locale (2.1.2)
metaclass (0.0.4)
mocha (1.2.1)
metaclass (~> 0.0.1)
puppet (4.9.2)
facter (> 2.0, < 4)
gettext-setup (>= 0.10, < 1)
hiera (>= 2.0, < 4)
json_pure (~> 1.8)
locale (~> 2.1)
puppet-lint (2.1.1)
puppet-syntax (2.3.0)
rake
puppetlabs_spec_helper (2.0.1)
mocha (~> 1.0)
puppet-lint (~> 2.0)
puppet-syntax (~> 2.0)
rspec-puppet (~> 2.0)
rake (12.0.0)
rspec (3.5.0)
rspec-core (~> 3.5.0)
rspec-expectations (~> 3.5.0)
rspec-mocks (~> 3.5.0)
rspec-core (3.5.4)
rspec-support (~> 3.5.0)
rspec-expectations (3.5.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.5.0)
rspec-mocks (3.5.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.5.0)
rspec-puppet (2.5.0)
rspec
rspec-support (3.5.0)
text (1.3.1)

PLATFORMS
ruby

DEPENDENCIES
puppet
puppetlabs_spec_helper
rake
rspec-puppet

BUNDLED WITH
1.14.3
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ V 0.3.1 :
- Fix add user. (dsquery.exe doesn't seem to work anymore) - Works with fullname value
- Add Pull Request #8 (fix readme for Group)
V 0.3.2 :
- Fix add group and groupmember dsquery.exe doesn't seem to work anymore).
- Fix add group and group member dsquery.exe doesn't seem to work anymore).

##Module Description

Expand Down Expand Up @@ -209,7 +209,7 @@ For adding a Group :

For adding members to a Group :
```
windows_ad::groupmembers{'Member groupplop':
windows_ad::group_members{'Member groupplop':
ensure => present,
groupname => 'groupplop',
members => '"jre","test2"',
Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ require 'puppet-lint/tasks/puppet-lint'
PuppetLint.configuration.send('disable_80chars')
PuppetLint.configuration.ignore_paths = ["spec/**/*.pp", "pkg/**/*.pp"]

desc "Run puppet in noop mode and check for syntax errors."
desc "Validate manifests, templates, and ruby files"
task :validate do
Dir['manifests/**/*.pp'].each do |manifest|
sh "puppet parser validate --noop #{manifest}"
Expand Down
1 change: 0 additions & 1 deletion checksums.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"lib/puppet/parser/functions/validate_password.rb": "dc6f2d87967e86882e49a09b9e3e0ca7",
"manifests/conf_forest.pp": "2d8de6a9deddaa47711b7684e6c7c43f",
"manifests/group.pp": "cf0081d1bba488c62f0eba54fffd52f1",
"manifests/groupmembers.pp": "c50ec54005b12aa3120577e963a61082",
"manifests/init.pp": "cbd753ea0b6ceedb14ec94c6fce8abf5",
"manifests/install.pp": "02d4dff5c898bf26bf37d25b7bdae2fb",
"manifests/organisationalunit.pp": "c1925a20f4cb0da1cf8cb4247a635d4d",
Expand Down
87 changes: 48 additions & 39 deletions manifests/conf_forest.pp
Original file line number Diff line number Diff line change
Expand Up @@ -33,60 +33,69 @@
# === Authors
#
# Jerome RIVIERE (www.jerome-riviere.re)
# Karol Kozakowski <[email protected]>
#
# === Copyright
#
# Copyright 2014 Jerome RIVIERE.
# Copyright 2017 Karol Kozakowski <[email protected]>
#
class windows_ad::conf_forest (
#install parameters
$ensure = $ensure,
$domainname = $domainname,
$netbiosdomainname = $netbiosdomainname,
$domainlevel = $domainlevel,
$forestlevel = $forestlevel,
$globalcatalog = $globalcatalog,
$databasepath = $databasepath,
$logpath = $logpath,
$sysvolpath = $sysvolpath,
$dsrmpassword = $dsrmpassword,
$installdns = $installdns,
$kernel_ver = $kernel_ver,
$timeout = 0,
$configureflag = $configureflag,

#removal parameters
$localadminpassword = $localadminpassword, #admin password required for removal
$force = $force,
$forceremoval = $forceremoval,
$uninstalldnsrole = $uninstalldnsrole,
$demoteoperationmasterrole = $demoteoperationmasterrole,
$ensure,
$domainname,
$netbiosdomainname,
$domainlevel,
$forestlevel,
$globalcatalog,
$databasepath,
$logpath,
$sysvolpath,
$dsrmpassword,
$installdns,
$kernel_ver,
$configureflag,
$localadminpassword,
$force,
$forceremoval,
$uninstalldnsrole,
$demoteoperationmasterrole,
$timeout,
){
validate_bool($configureflag)
if ($configureflag == true){
if $force { $forcebool = 'true' } else { $forcebool = 'false' }
if $forceremoval { $forceboolremoval = 'true' } else { $forceboolremoval = 'false' }
if $demoteoperationmasterrole { $demoteoperationmasterrolebool = 'true' } else { $demoteoperationmasterrolebool = 'false' }

# If the operating is server 2012 then run the appropriate powershell commands if not revert back to the cmd commands
# If the operating is server 2012 or 2016 then run the appropriate powershell commands if not revert back to the cmd commands
if ($ensure == 'present') {
if ($kernel_ver =~ /^6\.2|^6\.3/) {
if ($kernel_ver =~ /^6\.2|^6\.3|^10\.0/) {
if ($installdns == 'yes'){
# Deploy Server 2012 Active Directory
exec { 'Config ADDS':
command => "Import-Module ADDSDeployment; Install-ADDSForest -Force -DomainName ${domainname} -DomainMode ${domainlevel} -DomainNetbiosName ${netbiosdomainname} -ForestMode ${forestlevel} -DatabasePath ${databasepath} -LogPath ${logpath} -SysvolPath ${sysvolpath} -SafeModeAdministratorPassword (convertto-securestring '${dsrmpassword}' -asplaintext -force) -InstallDns",
provider => powershell,
onlyif => "if((gwmi WIN32_ComputerSystem).Domain -eq \'${domainname}\'){exit 1}",
timeout => $timeout,
# Deploy Server 2016 Active Directory
class { 'windows_ad::deployments::adds_deployment_powershell':
type => 'ntp',
domainname => $domainname,
domainlevel => $domainlevel,
netbiosdomainname => $netbiosdomainname,
forestlevel => $forestlevel,
databasepath => $databasepath,
logpath => $logpath,
sysvolpath => $sysvolpath,
dsrmpassword => $dsrmpassword,
timeout => $timeout
}
}
else{
# Deploy Server 2012 Active Directory Without DNS
exec { 'Config ADDS':
command => "Import-Module ADDSDeployment; Install-ADDSForest -Force -DomainName ${domainname} -DomainMode ${domainlevel} -DomainNetbiosName ${netbiosdomainname} -ForestMode ${forestlevel} -DatabasePath ${databasepath} -LogPath ${logpath} -SysvolPath ${sysvolpath} -SafeModeAdministratorPassword (convertto-securestring '${dsrmpassword}' -asplaintext -force)",
provider => powershell,
onlyif => "if((gwmi WIN32_ComputerSystem).Domain -eq \'${domainname}\'){exit 1}",
timeout => $timeout,
} else{
class { 'windows_ad::deployments::adds_deployment_powershell':
type => '',
domainname => $domainname,
domainlevel => $domainlevel,
netbiosdomainname => $netbiosdomainname,
forestlevel => $forestlevel,
databasepath => $databasepath,
logpath => $logpath,
sysvolpath => $sysvolpath,
dsrmpassword => $dsrmpassword,
timeout => $timeout
}
}
}else {
Expand All @@ -99,7 +108,7 @@
}
}
}else{ #uninstall AD
if ($kernel_ver =~ /^6\.2|^6\.3/) {
if ($kernel_ver =~ /^6\.2|^6\.3|^10\.0/) {
if($localadminpassword != ''){
exec { 'Uninstall ADDS':
command => "Import-Module ADDSDeployment;Uninstall-ADDSDomainController -LocalAdministratorPassword (ConvertTo-SecureString \'${localadminpassword}\' -asplaintext -force) -Force:$${forcebool} -ForceRemoval:$${forceboolremoval} -DemoteOperationMasterRole:$${demoteoperationmasterrolebool} -SkipPreChecks",
Expand Down
26 changes: 26 additions & 0 deletions manifests/deployments/adds_deployment_powershell.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
class windows_ad::deployments::adds_deployment_powershell (
$type,
$domainname,
$domainlevel,
$netbiosdomainname,
$forestlevel,
$databasepath,
$logpath,
$sysvolpath,
$dsrmpassword,
$timeout,
) {

if ($type == 'ntp') {
$command = "Import-Module ADDSDeployment; Install-ADDSForest -Force -DomainName ${domainname} -DomainMode ${domainlevel} -DomainNetbiosName ${netbiosdomainname} -ForestMode ${forestlevel} -DatabasePath ${databasepath} -LogPath ${logpath} -SysvolPath ${sysvolpath} -SafeModeAdministratorPassword (convertto-securestring '${dsrmpassword}' -asplaintext -force) -InstallDns"
} else {
$command = "Import-Module ADDSDeployment; Install-ADDSForest -Force -DomainName ${domainname} -DomainMode ${domainlevel} -DomainNetbiosName ${netbiosdomainname} -ForestMode ${forestlevel} -DatabasePath ${databasepath} -LogPath ${logpath} -SysvolPath ${sysvolpath} -SafeModeAdministratorPassword (convertto-securestring '${dsrmpassword}' -asplaintext -force)"
}

exec { 'Config ADDS':
command => $command,
provider => powershell,
onlyif => "if((gwmi WIN32_ComputerSystem).Domain -eq \'${domainname}\'){exit 1}",
timeout => $timeout,
}
}
Loading