arfor 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dfea1dee45ad4415c9b404c2dff9d83d33db51c4
4
- data.tar.gz: 89eaefcf1dd86f136ec5902762a6d07584816035
3
+ metadata.gz: 63d74f24dee9d20bc39dc8ec2a4edd9914cd7db0
4
+ data.tar.gz: 80e38bb214b9e6a43e618a70d78f2c5f00587cb2
5
5
  SHA512:
6
- metadata.gz: 2e245e9a3def2da5e6f5586e556e9f62b06d2805ea2395345ec5544b1e5460666ecaf9451a3e83c1e0a9168945bc2e2643db920cc16dfdb4dd64e009ef09019c
7
- data.tar.gz: fcc7473c5ff973f83531c81e23295b1f09b5f9315f4b4a63d52f3d2cf2af747acdcfb1eebfb98b60863b0eb61a59d3db23270fe76542ceb1d934b4d627a2e555
6
+ metadata.gz: 587452cf390dfb2b898a0a46ff57663afb075b1f68800b9e0bdbcecbdb1a744b3db9a363102ca3dd2e6280b198e2e2082542d251cc2ad16e2990b94c6dabf617
7
+ data.tar.gz: d172f044d5b7acab6bf9a46fa8c19bb847f93d2b397ec89e2e733f258910f65707ff07da93a9465c758ecb8d3e84d57cdeb0c52812b9924e8dd0be5688f54a66
data/exe/arfor CHANGED
@@ -20,6 +20,7 @@ require 'arfor/agent_installers'
20
20
  require 'arfor/gems'
21
21
  require 'arfor/platform_installer'
22
22
  require 'pe_info/tarball'
23
+ require 'arfor/control_repo'
23
24
 
24
25
  # display help if nothing specified
25
26
  ARGV.push('-h') if ARGV.empty?
@@ -107,5 +108,13 @@ Escort::App.create do |app|
107
108
  Arfor::PlatformInstaller::download(pe_version, dist, rel, arch)
108
109
  end
109
110
  end
111
+
112
+ app.command :control_repo do |command|
113
+ command.summary "Control Repository"
114
+ command.description "Create a Puppet Control Repository, setup for testing with onceover"
115
+ command.action do |options, arguments|
116
+ Arfor::ControlRepo::create()
117
+ end
118
+ end
110
119
  end
111
120
  end
@@ -0,0 +1,72 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Copyright 2016 Geoff Williams for Puppet Inc.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ module Arfor
17
+ module ControlRepo
18
+ WORKING_DIR = 'puppet-control'
19
+ UPSTREAM_EXAMPLE = 'https://github.com/puppetlabs/control-repo'
20
+ CLEANUP_FILES = [
21
+ 'README.md',
22
+ 'LICENSE',
23
+ 'site/role/manifests/database_server.pp',
24
+ 'site/role/manifests/web_server.pp',
25
+ 'site/role/manifests/database_server.pp',
26
+ 'site/role/manifests/example.pp',
27
+ 'site/profile/manifests/example.pp',
28
+ ]
29
+
30
+ VENDORED_FILES = '../../res/control_repo/.'
31
+ CLEAN_RUBY = "unset RUBYLIB GEM_HOME GEM_PATH RUBYOPT BUNDLE_GEMFILE; "
32
+
33
+ # create a new contorl repository in a directory ./puppet-control
34
+ def self.create()
35
+ if File.exists?(WORKING_DIR)
36
+ abort("Puppet control repository already exists at #{WORKING_DIR}")
37
+ else
38
+ # Step 1 - git clone of upstream puppet control repository
39
+ system("git clone #{UPSTREAM_EXAMPLE} #{WORKING_DIR}")
40
+
41
+ # Step 2 - crud cleanup
42
+ CLEANUP_FILES.each { |f|
43
+ # swallow errors relating to files that are no longer in upstream
44
+ begin
45
+ File.delete(f)
46
+ rescue
47
+ end
48
+ }
49
+ # ...And remove upstream git repo - not needed
50
+ FileUtils.rm_rf(File.join(WORKING_DIR, '.git'))
51
+
52
+ # Step 3 - Copy in files
53
+ dir = File.join(File.dirname(File.expand_path(__FILE__)), VENDORED_FILES)
54
+ FileUtils.cp_r(dir, WORKING_DIR)
55
+
56
+ # Step 4 - Install onceover
57
+ Dir.chdir(WORKING_DIR) {
58
+ system("#{CLEAN_RUBY} bundle install")
59
+ system("#{CLEAN_RUBY} bundle exec onceover init")
60
+
61
+ # Step 5 - setup git
62
+ system("git init")
63
+ system("git checkout -b production")
64
+
65
+ # Step 6 - initial git commit
66
+ system("git add -A")
67
+ system("git commit -m 'initial' ")
68
+ }
69
+ end
70
+ end
71
+ end
72
+ end
data/lib/arfor/version.rb CHANGED
@@ -15,5 +15,5 @@
15
15
  # limitations under the License.
16
16
 
17
17
  module Arfor
18
- VERSION = "0.2.2"
18
+ VERSION = "0.3.0"
19
19
  end
@@ -0,0 +1,12 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rake'
4
+ gem 'bundler'
5
+ gem 'onceover'
6
+ gem 'rugged'
7
+ gem 'pry'
8
+ gem 'r10k'
9
+
10
+ gem 'puppet-strings',
11
+ :git => 'https://github.com/declarativesystems/puppet-strings',
12
+ :ref => 'no_dates'
@@ -0,0 +1,8 @@
1
+ # run acceptance_alpha with --keep_test_system to keep all test VMs
2
+ onceover:
3
+ find . -name '*.yaml' -not -path './.onceover/*' -exec ruby -ryaml -e "YAML.load_file '"{}"' " \;
4
+ bundle exec r10k puppetfile check
5
+ cat Puppetfile > Puppetfile.onceover
6
+ cat Puppetfile.mock >> Puppetfile.onceover
7
+ bundle exec onceover run spec --puppetfile Puppetfile.onceover
8
+ #bundle exec onceover run acceptance_alpha --puppetfile Puppetfile.onceover --trace --debug
@@ -0,0 +1,4 @@
1
+ # Mock modules needed for testing
2
+ mod 'geoffwilliams-pe_staging', '0.1.0'
3
+ mod 'geoffwilliams-pe_repo', '0.2.0'
4
+ mod 'geoffwilliams-puppet_enterprise', '0.5.3'
@@ -0,0 +1,127 @@
1
+ # Puppet Control Repository
2
+
3
+ ## Overview
4
+
5
+ This Git repository contains a [Puppet Control repository](https://docs.puppet.com/pe/latest/cmgmt_control_repo.html) and holds references to all:
6
+ * Environments
7
+ * Puppet modules
8
+ * Roles and Profiles
9
+ * Hiera data
10
+ * Hiera configuration (hierarchy)
11
+
12
+ Used at this site.
13
+
14
+ ## Environments
15
+ Each [Git branch](https://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging) in this control repository represents an environment in Puppet Enterprise. An environment is the combination of a group of machines and a particular directory of Puppet code and usually also Hiera data, inside the `/etc/puppetlabs/code/environments/` directory. On code deployment, Environments will be created automatically with names corresponding to git branches. With the default puppet git branch being `production`, not `master` as is customary for Git projects.
16
+
17
+ Due to this being a fresh Puppet Enterprise deployment, all work was carried out directly in the `production` branch. For real-world development, it's recommended to carry out development work in [feature branches](https://www.atlassian.com/git/tutorials/comparing-workflows#feature-branch-workflow) to build [pull requests](https://www.atlassian.com/git/tutorials/making-a-pull-request) for testing against a limited number of test nodes in a non-production environment.
18
+
19
+ ## Modules
20
+
21
+ ### Puppetfile
22
+ The [Puppetfile](https://docs.puppet.com/pe/latest/cmgmt_puppetfile.html#about-puppetfiles) describes all of the modules in use for a given environment.
23
+
24
+ Since environments in Puppet Enterprise are represented by branches, a different branch (environment) is able to have a different `Puppetfile` and thus may have a completely different set of modules to its neighbors.
25
+
26
+ Each [`mod` directive](https://github.com/puppetlabs/r10k/blob/master/doc/puppetfile.mkd#module-types) of the `Puppetfile` represents a different module to be installed. For repeatable deployments, its vital that the exact version of every module used is specified, otherwise inadvertent upgrades (or non upgrades...) may occur.
27
+
28
+ Released versions of modules only get created automatically on the [Puppet Forge](https://forge.puppet.com/). For modules that are only ever accessed though git, its vital that [Git tags](https://git-scm.com/book/en/v2/Git-Basics-Tagging) are created to represent each released module version and are referenced in the `Puppetfile` using the `:tag` attribute to prevent unintended code deployment.
29
+
30
+ ### Roles and Profiles
31
+ Roles and Profiles are simply regular puppet modules that are used to abstract complexity away, to the point that each node normally has a single associated `role` class that loads all associated functionality using a single name.
32
+
33
+ Roles and Profiles for this Puppet Control Repository are stored as separate modules within the `/site` directory.
34
+
35
+ #### Roles
36
+ * A node is associated with a single role (eg `role::application_server`) and describes the business role of a node
37
+ * Roles only include profiles
38
+
39
+ #### Profiles
40
+ * A profile assembles functionality provided by modules and sometimes basic Puppet resources into a (hopefully) reusable body of code to perform a discreet task such as setup a web server or set the timezone.
41
+ * Explicit Hiera lookups should only take place at the profile level for reasons of simplicity and portability
42
+ * Ready-made profiles can be provided from other modules, such as [r_profile](https://forge.puppet.com/geoffwilliams/r_profile)
43
+
44
+
45
+ ## Hiera
46
+
47
+ ### Configuring the hierarchy
48
+ * The complete hiera hierarchy is described in the **production** branch of the control repository in the [`hierarchy.txt`](hieradata/hierarchy.txt) file.
49
+ * The file will be read verbatim and imported into [`hiera.yaml`](https://docs.puppet.com/hiera/3.2/configuring.html) as an array to populate the `:hierarchy:` key
50
+ * If the hierarchy needs to be altered, adjust `hierarchy.txt `as required and make sure changes are saved to the git repository. Changes will become active the next the puppet agent runs on the master after redeploying the code.
51
+
52
+ ### Hints and tips
53
+ Hiera can become a system thats deceptively simple to setup but almost impossibly complex to administer if users fall into some of the common 'traps' that initially look like great ways to manage complexity:
54
+ * Try to avoid using [`hiera_array()`](https://docs.puppet.com/puppet/latest/function.html#hieraarray), [`hiera_hash()`](https://docs.puppet.com/puppet/latest/function.html#hierahash) and friends. They perform aggregate lookups across the entire hierarchy which while initially convenient can lead to conditions where the ripple effect of making a change in a 'base' hiera file is not realised until unintended change has happened
55
+ * Keep hierarchies as _simple_ as possible. The duplication of producing hierarchies that mirror tables by interpolating multiple variables per hierarchy level gives data files that are both _much_ simpler to comprehend and that can be directly related back to tabular specification documents. This is a worthwhile tradeoff vs insisting on de-duplicated data and also gives flexibility to adjust _rows_ of data in isolation in the future if required.
56
+ * Make sure your hieradata is valid before committing back to Git. See testing section for details of how
57
+ * Copy and paste hiera key names from the relevant profiles and guards to avoid typos
58
+ * Ensure that the record separator `---` is only present _once_ at the very beginning of the file **including in comments!**. Any additional separators will cause hiera data to mysteriously _vanish_ when you come to look it up. Validating your `.yaml` files won't detect this either since this is technically valid syntax
59
+ * Learn about [yaml syntax](https://learn.getgrav.org/advanced/yaml)
60
+ * Learn about [hiera debugging techniques](https://puppet.com/blog/debugging-hiera-redux) available to you
61
+ * If you need to store passwords or sensitive data, consider encrypting using [hiera-eyaml](https://github.com/voxpupuli/hiera-eyaml)
62
+ * Alternatively, consider some of the newer systems that have appeared recently, such as [HashiCorp Vault](https://www.vaultproject.io/)
63
+
64
+ ## Deploying code to Puppet Masters
65
+ Deployment of code to the Puppet Masters is coordinated from the Master of Masters node which when updated will distribute all changes to any compile masters in use.
66
+
67
+ To manually trigger deployment, SSH into the Puppet Master of Masters and become root, then run the command:
68
+
69
+ ```shell
70
+ puppet code deploy --all --wait
71
+ ```
72
+
73
+ ### Warning
74
+ Never be tempted to deploy code to the Puppet Master by copying files directly the `/etc/puppetlabs/code` or `/etc/puppetlabs/code-staging` directories. Despite being placed under `/etc` these folders are not intended to be user-modifiable _if using code manager and file sysnc_ are in use. Indeed writing to these folder is usually enough to take down Puppet Enterprise completely. If this does occur, the solution is usually to remove all code in these directories and then use the `puppet code deploy` command to redeploy a fresh copy of all code.
75
+
76
+ ## Reference
77
+ * [role](site/role/doc/index.html)
78
+ * [profile](site/profile/doc/index.html)
79
+
80
+ The documentation is no substitute for reading and understanding the module source code, and all users should ensure they are familiar and comfortable with the operations these module perform before using them.
81
+
82
+ ## Limitations
83
+
84
+ * Not supported by Puppet, Inc.
85
+ * Requires in-depth testing prior to deployment
86
+
87
+ ## Development
88
+
89
+ No further external development planned. It is expected that:
90
+ * Additional environments will be branched from `production` in order to allow new developments without risking unintended changes reaching production infrastructure
91
+ * Development will take place in feature branches change will be controlled by configuring Bitbucket server to require pull requests, disallowing work to take place on the main branch
92
+ * This notice and the rest of the documentation will be actively updated to aid those working on the project in the future
93
+
94
+ ## Testing
95
+ This module supports testing using [Onceover](https://github.com/dylanratcliffe/onceover).
96
+
97
+ To run [rspec-puppet](http://rspec-puppet.com/) tests and generate documentation:
98
+
99
+ ```shell
100
+ bundle install
101
+ make
102
+ ```
103
+
104
+ If modules are not updated correctly, you may need to first clear out the onceover cache:
105
+
106
+ ```shell
107
+ rm -rf .onceover
108
+ ```
109
+
110
+ Before running the `make` command again.
111
+
112
+ ### Testing new role classes
113
+ To ensure a new role class is tested with onceover, it must be added to the classes array in `spec/onceover.yaml`
114
+
115
+ ### Further information
116
+ See the main onceover github repository for nore details of how onceover works
117
+
118
+ ### Internet access
119
+ Note that onceover (and bundle) expect free and easy internet access. If you are behind a proxy server you will likely have problems, although exporting the relevant proxies using combinations of:
120
+ * `http_proxy`
121
+ * `https_proxy`
122
+ * `no_proxy`
123
+ May allow these tools to work.
124
+
125
+ If you are 'protected' by a corporate firewall, you may find that your best course of action is to temporarily join a less restrictive network in order to run the tests.
126
+
127
+ Alternatively, you may need to adjust the onceover command inside the `Makefile` to have it use your main `Puppetfile` for access to the corporate bitbucket server instead of using publicly hosted modules.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arfor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Geoff Williams
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-04-22 00:00:00.000000000 Z
11
+ date: 2017-05-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -143,10 +143,15 @@ files:
143
143
  - exe/arfor
144
144
  - lib/arfor.rb
145
145
  - lib/arfor/agent_installers.rb
146
+ - lib/arfor/control_repo.rb
146
147
  - lib/arfor/download.rb
147
148
  - lib/arfor/gems.rb
148
149
  - lib/arfor/platform_installer.rb
149
150
  - lib/arfor/version.rb
151
+ - res/control_repo/Gemfile
152
+ - res/control_repo/Makefile
153
+ - res/control_repo/Puppetfile.mock
154
+ - res/control_repo/README.md
150
155
  homepage: https://github.com/GeoffWilliams/arfor/
151
156
  licenses:
152
157
  - Apache-2.0