Created
January 31, 2015 11:49
-
-
Save liamjbennett/ad6e2a2689aa8c4e2460 to your computer and use it in GitHub Desktop.
roles and profiles spec_helper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'beaker-rspec/spec_helper' | |
require 'beaker-rspec/helpers/serverspec' | |
require 'winrm' | |
otmodules_root = File.expand_path(File.join(File.dirname(__FILE__), '..', 'otmodules')) | |
hosts.each do |host| | |
if host['platform'] =~ /windows/ | |
include Serverspec::Helper::Windows | |
include Serverspec::Helper::WinRM | |
end | |
version = ENV['PUPPET_VERSION'] || '3.7.1' | |
install_puppet(:version => version) | |
if host['roles'].include?('master') | |
master = host | |
# scp required files/folders onto master | |
files = [ 'environments','facts','hiera','roles', 'profiles', 'keys', 'app_modules', 'foreman_modules', | |
'auth.conf','autosign.conf','fileserver.conf', 'Gemfile','hiera.yaml','Puppetfile' | |
] | |
files.each do |file| | |
scp_to master, File.expand_path(File.join(File.dirname(__FILE__), '..', file)), "/etc/puppet/#{file}" | |
end | |
# scp modules folder (this excludes stuff like spec and test folders) | |
otmodules = Dir["#{otmodules_root}/*/"].map { |a| File.basename(a) } | |
otmodules.each do |module_name| | |
otmodule_dir = "#{otmodules_root}/#{module_name}" | |
copy_module_to(master, :source => otmodule_dir, :module_name => module_name) | |
end | |
master_name = "#{master}.test.local" | |
# install the puppetmaster | |
on master, "apt-get install -y rubygems git" | |
on master, "apt-get install -y puppet-common=#{version}-1puppetlabs1 puppetmaster-common=#{version}-1puppetlabs1 puppetmaster=#{version}-1puppetlabs1 " | |
on master, "echo '*' > /etc/puppet/autosign.conf" | |
config = { | |
'main' => { | |
'server' => master_name, | |
'certname' => master_name, | |
'logdir' => '/var/log/puppet', | |
'vardir' => '/var/lib/puppet', | |
'ssldir' => '/var/lib/puppet/ssl', | |
'rundir' => '/var/run/puppet' | |
}, | |
'agent' => { | |
'environment' => 'vagrant' | |
} | |
} | |
configure_puppet(master, config) | |
# install required gems | |
on master, "gem install bundler" | |
on master, "gem install hiera-eyaml" | |
on master, "cd /etc/puppet && bundle install --without development" | |
# install modules with librarian-puppet | |
on master, "cd /etc/puppet && bundle exec librarian-puppet install --verbose" | |
#host_entry(master, { 'ip' => '10.255.33.135', 'name' => master_name}) | |
on master, "echo '10.255.33.135 #{master_name}' >> /etc/hosts" | |
on master, "hostname #{master_name}" | |
on master, "/etc/init.d/puppetmaster restart" | |
else | |
agent = host | |
master = only_host_with_role(hosts, 'master') | |
agent_name = agent.to_s.downcase | |
master_fqdn = "#{master}.test.local" | |
agent_fqdn = "#{agent_name}.test.local" | |
if agent['platform'] =~ /windows/ | |
host_entry(agent, { 'ip' => '10.255.33.135', 'name' => master_fqdn}) | |
host_entry(agent, { 'ip' => '10.255.33.129', 'name' => 'win-2008R2-std'}) | |
config = { | |
'main' => { | |
'server' => master_fqdn, | |
'certname' => agent_name, | |
'logdir' => 'C:\\ProgramData\\PuppetLabs\\puppet\\var\\log', | |
'vardir' => 'C:\\ProgramData\\PuppetLabs\\puppet\\var\\lib', | |
'ssldir' => 'C:\\ProgramData\\PuppetLabs\\puppet\\var\\lib\\ssl', | |
'rundir' => 'C:\\ProgramData\\PuppetLabs\\puppet\\var\\run' | |
}, | |
'agent' => { | |
'environment' => 'vagrant' | |
} | |
} | |
else | |
config = { | |
'main' => { | |
'server' => master_fqdn, | |
'certname' => agent_fqdn, | |
'logdir' => '/var/log/puppet', | |
'vardir' => '/var/lib/puppet', | |
'ssldir' => '/var/lib/puppet/ssl', | |
'rundir' => '/var/run/puppet' | |
}, | |
'agent' => { | |
'environment' => 'vagrant' | |
} | |
} | |
on agent, "echo '10.255.33.135 #{master_fqdn}' >> /etc/hosts" | |
on agent, "echo '10.255.33.129 #{agent_fqdn}' >> /etc/hosts" | |
on agent, "hostname #{agent_fqdn}" | |
end | |
configure_puppet(agent, config) | |
end | |
end | |
RSpec.configure do |c| | |
c.before :suite do | |
hosts.each do |host| | |
c.host = host | |
if host['platform'] =~ /windows/ | |
endpoint = "http://127.0.0.1:5985/wsman" | |
c.winrm = ::WinRM::WinRMWebService.new(endpoint, :ssl, :user => 'vagrant', :pass => 'vagrant', :basic_auth_only => true) | |
c.winrm.set_timeout 300 | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment