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

Fix Apt Repo Settings #68

Merged
merged 1 commit into from
Sep 5, 2015
Merged
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
65 changes: 58 additions & 7 deletions lib/kitchen/provisioner/puppet_apply.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ def non_suite_dirs
end
end

module Configurable
def platform_name
instance.platform.name
end
end

module Provisioner
#
# Puppet Apply provisioner.
Expand All @@ -46,6 +52,7 @@ class PuppetApply < Base
default_config :puppet_version, nil
default_config :facter_version, nil
default_config :hiera_version, nil
default_config :install_hiera, false
default_config :require_puppet_repo, true
default_config :require_chef_for_busser, true
default_config :resolve_with_librarian_puppet, true
Expand Down Expand Up @@ -125,7 +132,9 @@ class PuppetApply < Base
default_config :puppet_debug, false
default_config :puppet_verbose, false
default_config :puppet_noop, false
default_config :puppet_platform, ''
default_config :platform do |provisioner|
provisioner.platform_name
end
default_config :update_package_repos, true
default_config :remove_puppet_repo, false
default_config :custom_facts, {}
Expand Down Expand Up @@ -165,7 +174,7 @@ def install_command
else
case puppet_platform
when 'debian', 'ubuntu'
info("Installing puppet on #{puppet_platform}")
info("Installing puppet on #{config[:platform]}")
<<-INSTALL
if [ ! $(which puppet) ]; then
#{sudo('apt-get')} -y install wget
Expand All @@ -175,7 +184,7 @@ def install_command
#{sudo_env('apt-get')} -y install facter#{facter_debian_version}
#{sudo_env('apt-get')} -y install puppet-common#{puppet_debian_version}
#{sudo_env('apt-get')} -y install puppet#{puppet_debian_version}
#{sudo_env('apt-get')} -y install hiera-puppet#{puppet_hiera_debian_version}
#{install_hiera}
fi
#{install_eyaml}
#{install_deep_merge}
Expand Down Expand Up @@ -210,7 +219,7 @@ def install_command
#{sudo_env('apt-get')} -y install facter#{facter_debian_version}
#{sudo_env('apt-get')} -y install puppet-common#{puppet_debian_version}
#{sudo_env('apt-get')} -y install puppet#{puppet_debian_version}
#{sudo_env('apt-get')} -y install hiera-puppet#{puppet_hiera_debian_version}
#{install_hiera}
fi
fi
fi
Expand Down Expand Up @@ -321,6 +330,13 @@ def install_busser
INSTALL
end

def install_hiera
return unless config[:install_hiera]
<<-INSTALL
#{sudo_env('apt-get')} -y install hiera-puppet#{puppet_hiera_debian_version}
INSTALL
end

# /bin/wget -P /etc/pki/rpm-gpg/ http://yum.puppetlabs.com/RPM-GPG-KEY-puppetlabs
# changed to curl

Expand Down Expand Up @@ -680,7 +696,7 @@ def puppet_logdest_flag
end

def puppet_platform
config[:puppet_platform].to_s.downcase
config[:platform].gsub(/-.*/, '')
end

def facter_facts
Expand Down Expand Up @@ -744,12 +760,47 @@ def remove_repo
remove_puppet_repo ? "; #{sudo('rm')} -rf /tmp/kitchen #{hiera_data_remote_path} #{hiera_eyaml_key_remote_path} #{puppet_dir}/* " : nil
end

# rubocop:disable Metrics/CyclomaticComplexity
def puppet_apt_repo
config[:puppet_apt_repo]
platform_version = config[:platform].partition('-')[2]
case puppet_platform
when 'ubuntu'
case platform_version
when '14.10'
# Utopic Repo
'https://apt.puppetlabs.com/puppetlabs-release-utopic.deb'
when '14.04'
# Trusty Repo
'https://apt.puppetlabs.com/puppetlabs-release-trusty.deb'
when '12.04'
# Precise Repo
'https://apt.puppetlabs.com/puppetlabs-release-precise.deb'
else
# Configured Repo
config[:puppet_apt_repo]
end
when 'debian'
case platform_version.gsub(/\..*/, '')
when '8'
# Debian Jessie
'https://apt.puppetlabs.com/puppetlabs-release-jessie.deb'
when '7'
# Debian Wheezy
'https://apt.puppetlabs.com/puppetlabs-release-wheezy.deb'
when '6'
# Debian Squeeze
'https://apt.puppetlabs.com/puppetlabs-release-squeeze.deb'
else
# Configured Repo
config[:puppet_apt_repo]
end
else
error("Unsupported Platform - #{config[:platform]}")
end
end

def puppet_apt_repo_file
config[:puppet_apt_repo].split('/').last
puppet_apt_repo.split('/').last
end

def puppet_apt_coll_repo_file
Expand Down
32 changes: 16 additions & 16 deletions provisioner_options.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ key | default value | Notes
puppet_version | "latest"| desired version, affects apt installs.
facter_version | "latest"| desired version, affects apt installs.
hiera_version | "latest"| desired version, affects apt installs.
puppet_platform | naively tries to determine | OS platform of server
install_hiera | false | Installs `hiera-puppet` package. Not needed for puppet > 3.x.x
require_puppet_repo | true | Set if using a puppet install from yum or apt repo
puppet_apt_repo | "http://apt.puppetlabs.com/puppetlabs-release-precise.deb"| apt repo
puppet_yum_repo | "https://yum.puppetlabs.com/puppetlabs-release-el-6.noarch.rpm"| yum repo
Expand Down Expand Up @@ -83,9 +83,9 @@ The provisioner can be configured globally or per suite, global settings act as
verifier:
ruby_bindir: '/usr/bin'
```
where /usr/bin is the location of the ruby command.
where /usr/bin is the location of the ruby command.

in this example, vagrant will download a box for ubuntu 1204 with no configuration management installed, then install the
in this example, vagrant will download a box for ubuntu 1204 with no configuration management installed, then install the
latest puppet and puppet apply against a puppet repo from the /repository/puppet_repo directory using the defailt manifest site.pp

To override a setting at the suite-level, specify the setting name under the suite:
Expand Down Expand Up @@ -202,7 +202,7 @@ The provisioner can be configured globally or per suite, global settings act as
verifier:
ruby_bindir: '/usr/bin'
```
where /usr/bin is the location of the ruby command.
where /usr/bin is the location of the ruby command.

In this example, vagrant will download a box for ubuntu 1204 with no configuration management installed, then install the latest puppet and run puppet agent against a puppet master at puppetmaster-nocm-ubuntu-1204

Expand All @@ -222,24 +222,24 @@ To override a setting at the suite-level, specify the setting name under the sui
manifest: foobar.pp
```

## Custom ServerSpec or Beaker Invocation
## Custom ServerSpec or Beaker Invocation

Instead of using the busser use a custom serverspec invocation using [shell verifier](https://github.com/higanworks/kitchen-verifier-shell) to call it.
Instead of using the busser use a custom serverspec invocation using [shell verifier](https://github.com/higanworks/kitchen-verifier-shell) to call it.
With such setup there is no dependency on busser and any other chef library.

Also you can specify you tests in a different directory structure or even call [beaker](https://github.com/puppetlabs/beaker) instead of server spec and have tests in beaker structure
Also you can specify you tests in a different directory structure or even call [beaker](https://github.com/puppetlabs/beaker) instead of server spec and have tests in beaker structure

Using a structure like
```yaml
verifier:
name: shell
remote_exec: true
command: |
sudo -s <<SERVERSPEC
cd /opt/gdc/serverspec-core
export SERVERSPEC_ENV=$EC2DATA_ENVIRONMENT
export SERVERSPEC_BACKEND=exec
serverspec junit=true tag=~skip_in_kitchen check:role:$EC2DATA_TYPE
verifier:
name: shell
remote_exec: true
command: |
sudo -s <<SERVERSPEC
cd /opt/gdc/serverspec-core
export SERVERSPEC_ENV=$EC2DATA_ENVIRONMENT
export SERVERSPEC_BACKEND=exec
serverspec junit=true tag=~skip_in_kitchen check:role:$EC2DATA_TYPE
SERVERSPEC
```

Expand Down
4 changes: 2 additions & 2 deletions spec/kitchen/provisioner/puppet_apply_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
let(:logged_output) { StringIO.new }
let(:logger) { Logger.new(logged_output) }
let(:config) { { test_base_path: '/kitchen' } }
let(:platform) { Kitchen::Platform.new(name: 'fooos-99') }
let(:platform) { Kitchen::Platform.new(name: 'ubuntu-14.04') }
let(:suite) { Kitchen::Suite.new(name: 'suitey') }
let(:verifier) { Kitchen::Verifier::Dummy.new }
let(:transport) { Kitchen::Transport::Dummy.new }
Expand Down Expand Up @@ -194,7 +194,7 @@
end

it "should set puppet platform to ''" do
expect(provisioner[:puppet_platform]).to eq('')
expect(provisioner[:puppet_platform]).to eq(nil)
end

it 'should update package repos' do
Expand Down