From bff34cde83d3cda1846780d590aed0bd0353da47 Mon Sep 17 00:00:00 2001 From: Gene Liverman Date: Sat, 6 May 2017 18:29:40 -0700 Subject: [PATCH] Adding things for using Puppet --- bin/puppet/Gemfile | 11 +++------ bin/puppet/Gemfile.lock | 2 ++ bin/puppet/environment.conf | 2 ++ bin/puppet/hieradata/common.yaml | 1 + bin/puppet/hieradata/nodes/example-node.yaml | 1 + bin/puppet/manifests/site.pp | 14 +++++++++++ bin/puppet/r10k.yaml | 2 ++ .../scripts/code_manager_config_version.rb | 10 ++++++++ bin/puppet/scripts/config_version.rb | 24 +++++++++++++++++++ bin/puppet/scripts/config_version.sh | 12 ++++++++++ bin/puppet/site/profile/manifests/base.pp | 4 ++++ bin/puppet/site/role/manifests/server.pp | 7 ++++++ bin/puppet/site/role/manifests/workstation.pp | 4 ++++ 13 files changed, 86 insertions(+), 8 deletions(-) create mode 100644 bin/puppet/environment.conf create mode 100644 bin/puppet/hieradata/common.yaml create mode 100644 bin/puppet/hieradata/nodes/example-node.yaml create mode 100644 bin/puppet/manifests/site.pp create mode 100644 bin/puppet/r10k.yaml create mode 100755 bin/puppet/scripts/code_manager_config_version.rb create mode 100755 bin/puppet/scripts/config_version.rb create mode 100755 bin/puppet/scripts/config_version.sh create mode 100644 bin/puppet/site/profile/manifests/base.pp create mode 100644 bin/puppet/site/role/manifests/server.pp create mode 100644 bin/puppet/site/role/manifests/workstation.pp diff --git a/bin/puppet/Gemfile b/bin/puppet/Gemfile index 4d2ba2a..30fd8f3 100644 --- a/bin/puppet/Gemfile +++ b/bin/puppet/Gemfile @@ -8,19 +8,15 @@ else end group :development, :unit_tests do - if RUBY_VERSION < '2.0' - gem 'json', '1.8.3' - gem 'json_pure', '1.8.3' - else - gem 'json', '>= 2.0.2' - gem 'json_pure', '>= 2.0.2' - end + gem 'json', '>= 2.0.2' + gem 'json_pure', '>= 2.0.2' gem 'metadata-json-lint', '~> 1.0' gem 'puppet', puppetversion gem 'puppetlabs_spec_helper', '~> 1.1' gem 'r10k', '~> 2.3' gem 'rspec-puppet', '~> 2.5' + gem 'rugged', '~> 0.24' gem 'yamllint', '~> 0.0.9' # puppet-lint and plugins @@ -36,4 +32,3 @@ group :development, :unit_tests do gem 'puppet-lint-unquoted_string-check', '~> 0.3' gem 'puppet-lint-variable_contains_upcase', '~> 1.1' end - diff --git a/bin/puppet/Gemfile.lock b/bin/puppet/Gemfile.lock index 784b71d..6cece14 100644 --- a/bin/puppet/Gemfile.lock +++ b/bin/puppet/Gemfile.lock @@ -97,6 +97,7 @@ GEM rspec-puppet (2.5.0) rspec rspec-support (3.6.0) + rugged (0.25.1.1) semantic_puppet (0.1.4) gettext-setup (>= 0.3) spdx-licenses (1.1.0) @@ -127,6 +128,7 @@ DEPENDENCIES puppetlabs_spec_helper (~> 1.1) r10k (~> 2.3) rspec-puppet (~> 2.5) + rugged (~> 0.24) yamllint (~> 0.0.9) BUNDLED WITH diff --git a/bin/puppet/environment.conf b/bin/puppet/environment.conf new file mode 100644 index 0000000..d73df3b --- /dev/null +++ b/bin/puppet/environment.conf @@ -0,0 +1,2 @@ +modulepath = modules:site:$basemodulepath +config_version = 'scripts/config_version.sh $environmentpath $environment' diff --git a/bin/puppet/hieradata/common.yaml b/bin/puppet/hieradata/common.yaml new file mode 100644 index 0000000..ed97d53 --- /dev/null +++ b/bin/puppet/hieradata/common.yaml @@ -0,0 +1 @@ +--- diff --git a/bin/puppet/hieradata/nodes/example-node.yaml b/bin/puppet/hieradata/nodes/example-node.yaml new file mode 100644 index 0000000..ed97d53 --- /dev/null +++ b/bin/puppet/hieradata/nodes/example-node.yaml @@ -0,0 +1 @@ +--- diff --git a/bin/puppet/manifests/site.pp b/bin/puppet/manifests/site.pp new file mode 100644 index 0000000..ea699c8 --- /dev/null +++ b/bin/puppet/manifests/site.pp @@ -0,0 +1,14 @@ +## site.pp ## + +# DEFAULT NODE + +# The default node definition matches any node lacking a more specific node +# definition. If there are no other nodes in this file, classes declared here +# will be included in every node's catalog, *in addition* to any classes +# specified in the via an ENC for that node. + +node default { + # This is where you can declare classes for all nodes. + # Example: + # class { 'my_class': } +} diff --git a/bin/puppet/r10k.yaml b/bin/puppet/r10k.yaml new file mode 100644 index 0000000..a578000 --- /dev/null +++ b/bin/puppet/r10k.yaml @@ -0,0 +1,2 @@ +--- +cachedir: 'vendor/r10k' diff --git a/bin/puppet/scripts/code_manager_config_version.rb b/bin/puppet/scripts/code_manager_config_version.rb new file mode 100755 index 0000000..28afda7 --- /dev/null +++ b/bin/puppet/scripts/code_manager_config_version.rb @@ -0,0 +1,10 @@ +#!/usr/bin/env ruby +require 'json' + +environmentpath = ARGV[0] +environment = ARGV[1] + +r10k_deploy_file_path = File.join(environmentpath, environment, '.r10k-deploy.json') + +# output the sha1 from the control-repo +puts JSON.parse(File.read(r10k_deploy_file_path))['signature'] diff --git a/bin/puppet/scripts/config_version.rb b/bin/puppet/scripts/config_version.rb new file mode 100755 index 0000000..b34524a --- /dev/null +++ b/bin/puppet/scripts/config_version.rb @@ -0,0 +1,24 @@ +#!/usr/bin/env ruby +begin + require 'rugged' +rescue LoadError => e + t = Time.new + puts t.to_i +else + + environmentpath = ARGV[0] + environment = ARGV[1] + + repo = Rugged::Repository.discover(File.join(environmentpath, environment)) + head = repo.head + + # sha1 hash of the newest commit + head_sha = head.target_id + + # the commit message associated the newest commit + commit = repo.lookup(head_sha) + + # add something to find the remote url + + puts head_sha +end diff --git a/bin/puppet/scripts/config_version.sh b/bin/puppet/scripts/config_version.sh new file mode 100755 index 0000000..bc77213 --- /dev/null +++ b/bin/puppet/scripts/config_version.sh @@ -0,0 +1,12 @@ +#!/bin/bash +if [ -e $1/$2/.r10k-deploy.json ] +then + /opt/puppetlabs/puppet/bin/ruby $1/$2/scripts/code_manager_config_version.rb $1 $2 +elif [ -e /opt/puppetlabs/server/pe_version ] +then + /opt/puppetlabs/puppet/bin/ruby $1/$2/scripts/config_version.rb $1 $2 +else + /usr/bin/git --version > /dev/null 2>&1 && + /usr/bin/git --git-dir $1/$2/.git rev-parse HEAD || + date +%s +fi diff --git a/bin/puppet/site/profile/manifests/base.pp b/bin/puppet/site/profile/manifests/base.pp new file mode 100644 index 0000000..e1e831d --- /dev/null +++ b/bin/puppet/site/profile/manifests/base.pp @@ -0,0 +1,4 @@ +# the base profile should include component modules that will be on all nodes +class profile::base { + +} diff --git a/bin/puppet/site/role/manifests/server.pp b/bin/puppet/site/role/manifests/server.pp new file mode 100644 index 0000000..1731737 --- /dev/null +++ b/bin/puppet/site/role/manifests/server.pp @@ -0,0 +1,7 @@ +# Includes all the profiles needed for a server. +# One big difference between this and the workstation role is that you generally +# are not standing in front of the system and / or there is no graphical +# interface. +class role::workstation { + include ::profile::base +} diff --git a/bin/puppet/site/role/manifests/workstation.pp b/bin/puppet/site/role/manifests/workstation.pp new file mode 100644 index 0000000..27ee006 --- /dev/null +++ b/bin/puppet/site/role/manifests/workstation.pp @@ -0,0 +1,4 @@ +# Includes all the profiles needed for a workstation +class role::workstation { + include ::profile::base +}