diff --git a/.travis.yml b/.travis.yml index f28dc59..ff4899b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,6 +9,8 @@ sudo: false matrix: fast_finish: true include: + - rvm: 1.9.3 + env: PUPPET_GEM_VERSION="3.4.3" - rvm: 1.9.3 env: PUPPET_GEM_VERSION="~> 3.0" - rvm: 2.1.5 diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..711f915 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,16 @@ +# Change Log for Puppet Module locp-gitssh + +##2016-09-21 - Release 0.1.2 ([diff](https://github.com/locp/gitssh/compare/0.1.1...0.1.2)) + +* Fixed a fatal error when running a Puppet version < 3.6.0. +* Improved unit and acceptance testing. +* Improved the documentation. + +##2016-09-18 - Release 0.1.1 ([diff](https://github.com/locp/gitssh/compare/0.1.0...0.1.1)) + +* Ensure the service runs on Red Hat and Debian families. +* Improved the project metadata. + +##2016-09-11 - Release 0.1.0 + +An initial release. diff --git a/Gemfile b/Gemfile index f252a72..0959600 100644 --- a/Gemfile +++ b/Gemfile @@ -16,17 +16,21 @@ group :system_tests do gem 'beaker-rspec', require: false gem 'coveralls', require: false gem 'docker-api', require: false + gem 'google-api-client', '<= 0.9.4' + gem 'json_pure', '<= 2.0.1' gem 'metadata-json-lint', require: false gem 'pry', require: false gem 'puppet-blacksmith', require: false gem 'puppet-lint', require: false gem 'puppetlabs_spec_helper', require: false - gem 'rspec_junit_formatter', require: false + gem 'rspec_junit_formatter', '0.2.2' gem 'rspec-puppet', '<= 2.3.2' gem 'rspec-puppet-utils', require: false + gem 'rubocop', '<= 0.41.2' gem 'serverspec', require: false gem 'specinfra', '<= 2.59.0' gem 'spdx-licenses', '<= 1.0.0' + gem 'tins', '<= 1.6.0' end group :development do @@ -38,7 +42,4 @@ end if RUBY_VERSION >= '1.8.7' && RUBY_VERSION < '1.9' gem 'rspec', '~> 2.0' gem 'rake', '~> 10.0' -else - # rubocop requires ruby >= 1.9 - gem 'rubocop' end diff --git a/README.md b/README.md index 413f136..6c0d4b2 100644 --- a/README.md +++ b/README.md @@ -110,26 +110,70 @@ gitssh::repos: ## Reference -### Class gitssh +* [Defined type gitssh::client](#defined-type-gitsshclient) +* [Class gitssh](#class-gitssh) +* [Defined type gitssh::repo](#defined-type-gitsshrepo) -#### Parameters +### Parameters + +#### Defined type gitssh::client + +##### `ensure` +If the SSH key is to be present in the git account. Valid values are +*present* and *absent*. +Default value: **present** + +##### `type` +The type of SSH key. See +[here](https://docs.puppet.com/puppet/latest/reference/types/ssh_authorized_key.html#ssh_authorized_key-attribute-type) +for a list of valid values. +Default value: 'ssh-rsa' + +##### `key` +This value can be left as *undef* (the default) if `ensure` is set to +*absent*. Otherwise it should be the SSH key. +Default value: *undef* + +#### Class gitssh ##### `basedir` This is set as the home directory for the git user. Default value: '/var/git' ##### `clients` -An array of hashes that can be passed to the gitssh::client definition. +An array of hashes that can be passed to the `gitssh::client` definition. Default value: [] ##### `package_ensure` -Passed as the **ensure** parameter package for the **git** package. Valid +Passed as the **ensure** attribute to the package resource. Valid values are **present** or a specific version number. -Default value: present +Default value: **present** + +##### `package_name` +Passed as the **name** attribute for the package resource for the git +package. +Default value: 'git' + +##### `purge_ssh_keys` +Passed as an attribute for the user resource for git. This will remove all +SSH keys from the git user that are not controlled by Puppet. This +attribute has no effect on version of Puppet < 3.6.0 and will generate a +warning unless set to **false**. +Default value: **true** + +##### `repos` +An array of hashes that can be passed to the `gitssh::repo` definition. +Default value: [] + +#### Defined type gitssh::repo + +##### `ensure` +If the repository is to be *present* or *absent*. +Default value: **present** ## Limitations -Currently only developed and tested on CentOS and Debian 7. +Currently only developed and tested on CentOS 7, Ubuntu 14.04 and Debian 7. ## Development @@ -137,3 +181,9 @@ Contributions will be gratefully accepted. Please go to the project page, fork the project, make your changes locally and then raise a pull request. Details on how to do this are available at https://guides.github.com/activities/contributing-to-open-source. + +### Contributers + +| Release | Issue/PR | Contributer | +| :------------- | :-------------------------------------------------------------------------------------------------------------------------- | :------------------------------------| +| 0.1.2 | [The module does not work on Puppet 3.4.3The module does not work on Puppet 3.4.3](https://github.com/locp/gitssh/issues/3) | [@nl0pvm](https://github.com/nl0pvm) | diff --git a/circle.yml b/circle.yml index 0fe8499..a519337 100644 --- a/circle.yml +++ b/circle.yml @@ -16,6 +16,7 @@ machine: environment: PUPPET_GEM_VERSION: '~> 4.0' STRICT_VARIABLES: yes + BEAKER_destroy: no ruby: version: 2.1.6 services: @@ -27,3 +28,4 @@ test: - bundle exec rake lint - bundle exec rake validate - bundle exec rake spec SPEC_OPTS="--format RspecJunitFormatter -o $CIRCLE_TEST_REPORTS/rspec/puppet.xml" + - bundle exec rake beaker diff --git a/manifests/init.pp b/manifests/init.pp index 4550456..0e6e17c 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -17,13 +17,21 @@ before => User['git'] } + if versioncmp($::puppetversion,'3.6.0') >= 0 { + User { + purge_ssh_keys => $purge_ssh_keys, + } + } elsif $purge_ssh_keys { + warning('gitssh::purge_ssh_keys is ignored in Puppet < 3.6.0.') + warning('To disable this warning, set gitssh::purge_ssh_keys to false.') + } + user { 'git': - ensure => present, - home => $basedir, - shell => '/usr/bin/git-shell', - managehome => true, - purge_ssh_keys => $purge_ssh_keys, - require => Package[$package_name], + ensure => present, + home => $basedir, + shell => '/usr/bin/git-shell', + managehome => true, + require => Package[$package_name], } if size($clients) > 0 { diff --git a/metadata.json b/metadata.json index d140a28..4225af8 100644 --- a/metadata.json +++ b/metadata.json @@ -20,6 +20,12 @@ "7" ] }, + { + "operatingsystem": "Debian", + "operatingsystemrelease": [ + "7" + ] + }, { "operatingsystem": "Ubuntu", "operatingsystemrelease": [ diff --git a/spec/acceptance/gitssh_spec.rb b/spec/acceptance/gitssh_spec.rb index 788cbde..880b6b0 100644 --- a/spec/acceptance/gitssh_spec.rb +++ b/spec/acceptance/gitssh_spec.rb @@ -27,6 +27,9 @@ describe 'Git SSH installation.' do it 'should work with no errors' do apply_manifest(pre_req_install_pp, catch_failures: true) + end + + it 'check code is idempotent' do expect(apply_manifest(pre_req_install_pp, catch_failures: true).exit_code).to be_zero end diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index d294cd1..b1d8500 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -7,24 +7,25 @@ end end - context 'with defaults for all parameters' do - it do - should contain_class('gitssh').with('basedir' => '/var/git', - 'package_ensure' => 'present', - 'package_name' => 'git', - 'purge_ssh_keys' => 'true') - end - - it do - should contain_package('git').with('ensure' => 'present') - end + puppetversion = Gem.loaded_specs['puppet'].version - it do - should contain_user('git').with('home' => '/var/git', - 'purge_ssh_keys' => true) + context "With defaults for all parameters (puppet-#{puppetversion})" do + let :facts do + { + puppetversion: puppetversion.to_s + } end it do + should contain_class('gitssh') + .with( + basedir: '/var/git', + package_ensure: 'present', + package_name: 'git', + purge_ssh_keys: 'true' + ) + should contain_package('git').with('ensure' => 'present') + should contain_user('git').with('home' => '/var/git') should contain_exec('/bin/echo /usr/bin/git-shell >> /etc/shells') end end diff --git a/spec/defines/client_spec.rb b/spec/defines/client_spec.rb index 8e0ec7c..1b9feed 100644 --- a/spec/defines/client_spec.rb +++ b/spec/defines/client_spec.rb @@ -3,6 +3,14 @@ context 'Manage authorised SSH key' do let(:title) { 'nick@magpie.puppetlabs.lan' } + puppetversion = Gem.loaded_specs['puppet'].version + + let :facts do + { + puppetversion: puppetversion.to_s + } + end + let :params do { key: 'AAAAB...aQ==' @@ -10,6 +18,12 @@ end it do + should contain_gitssh__client('nick@magpie.puppetlabs.lan').with( + ensure: 'present', + type: 'ssh-rsa', + key: 'AAAAB...aQ==' + ) + should contain_ssh_authorized_key( 'gitssh::client::nick@magpie.puppetlabs.lan' ).with('user' => 'git', diff --git a/spec/defines/repo_spec.rb b/spec/defines/repo_spec.rb index da62eda..d61beb8 100644 --- a/spec/defines/repo_spec.rb +++ b/spec/defines/repo_spec.rb @@ -6,16 +6,23 @@ end end + puppetversion = Gem.loaded_specs['puppet'].version + context 'Add a repo (Red Hat)' do let(:title) { 'foobar' } let :facts do { - osfamily: 'RedHat' + osfamily: 'RedHat', + puppetversion: puppetversion.to_s } end it do + should contain_gitssh__repo('foobar').with( + ensure: 'present' + ) + should contain_exec('/usr/bin/mkdir /var/git/foobar.git') .with('user' => 'git') @@ -27,12 +34,13 @@ end end - context 'Add a repo (Red Hat)' do + context 'Add a repo (Debian)' do let(:title) { 'foobar' } let :facts do { - osfamily: 'Debian' + osfamily: 'Debian', + puppetversion: puppetversion.to_s } end