diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..52146d6cccfa5c49cad8b5ea76f739dfa1e24beb --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +modules/ diff --git a/CODEOWNERS b/CODEOWNERS new file mode 100644 index 0000000000000000000000000000000000000000..23299b7f9419fbb37759842ab81dad8851213478 --- /dev/null +++ b/CODEOWNERS @@ -0,0 +1 @@ +* @puppetlabs/cs-arch diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000000000000000000000000000000000000..8f71f43fee3f78649d238238cbde51e6d7055c82 --- /dev/null +++ b/LICENSE @@ -0,0 +1,202 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "{}" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright {yyyy} {name of copyright owner} + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + diff --git a/Puppetfile b/Puppetfile new file mode 100644 index 0000000000000000000000000000000000000000..1d6cc66690e5c2633f4b4ad4a68850e6f8a9b411 --- /dev/null +++ b/Puppetfile @@ -0,0 +1,17 @@ +forge 'https://forge.puppet.com' + +# Modules from the Puppet Forge +# Versions should be updated to be the latest at the time you start +#mod 'puppetlabs/inifile', '5.0.1' +#mod 'puppetlabs/stdlib', '7.0.1' +#mod 'puppetlabs/concat', '7.0.1' + +# Modules from Git +# Examples: https://github.com/puppetlabs/r10k/blob/master/doc/puppetfile.mkd#examples +#mod 'apache', +# git: 'https://github.com/puppetlabs/puppetlabs-apache', +# commit: '1b6f89afdde0df7f9433a163d5c4b5328eac5779' + +#mod 'apache', +# git: 'https://github.com/puppetlabs/puppetlabs-apache', +# branch: 'docs_experiment' diff --git a/README.md b/README.md index f639e468d2091f7a0c69e758f2c145fe6d9f044a..a540c9eccc612b242fdddcbe2d65399e86c6122d 100644 --- a/README.md +++ b/README.md @@ -1,92 +1,123 @@ -# control-repo +# A Puppet Control Repository +* [What You Get From This control\-repo](#what-you-get-from-this-control-repo) +* [Copy This Repo Into Your Own Git Server](#copy-this-repo-into-your-own-git-server) + * [GitLab](#gitlab) + * [Bitbucket/Stash](#bitbucketstash) + * [Github](#github) +* [Code Manager Setup](#code-manager-setup) -## Getting started +## What You Get From This control-repo -To make it easy for you to get started with GitLab, here's a list of recommended next steps. +This is a template [control repository](https://puppet.com/docs/pe/latest/control_repo.html) that has the minimum amount of scaffolding to make it easy to get started with [r10k](https://puppet.com/docs/pe/latest/r10k.html) or Puppet Enterprise's [Code Manager](https://puppet.com/docs/pe/latest/code_mgr.html). -Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)! +The important files and items in this template are as follows: -## Add your files +* Basic example of roles and profiles. +* An example Puppetfile with various module references. +* An example Hiera configuration file and data directory with pre-created common.yaml and nodes directory. + * These match the default hierarchy that ships with PE. +* An [environment.conf](https://puppet.com/docs/puppet/7/config_file_environment.html) that correctly implements: + * A site-modules directory for roles, profiles, and any custom modules for your organization. + * A config\_version script. +* An example [config\_version](https://puppet.com/docs/puppet/7/config_file_environment.html#environment-conf-allowed-settings) script that outputs the git commit ID of the code that was used during a Puppet run. -- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files -- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command: +Here's a visual representation of the structure of this repository: ``` -cd existing_repo -git remote add origin https://gitlab.stud.idi.ntnu.no/andrgart/control-repo.git -git branch -M main -git push -uf origin main +control-repo/ +├── data/ # Hiera data directory. +│ ├── nodes/ # Node-specific data goes here. +│ └── common.yaml # Common data goes here. +├── manifests/ +│ └── site.pp # The "main" manifest that contains a default node definition. +├── scripts/ +│ ├── code_manager_config_version.rb # A config_version script for Code Manager. +│ ├── config_version.rb # A config_version script for r10k. +│ └── config_version.sh # A wrapper that chooses the appropriate config_version script. +├── site-modules/ # This directory contains site-specific modules and is added to $modulepath. +│ ├── profile/ # The profile module. +│ └── role/ # The role module. +├── LICENSE +├── Puppetfile # A list of external Puppet modules to deploy with an environment. +├── README.md +├── environment.conf # Environment-specific settings. Configures the modulepath and config_version. +└── hiera.yaml # Hiera's configuration file. The Hiera hierarchy is defined here. ``` -## Integrate with your tools - -- [ ] [Set up project integrations](https://gitlab.stud.idi.ntnu.no/andrgart/control-repo/-/settings/integrations) - -## Collaborate with your team - -- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/) -- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html) -- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically) -- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/) -- [ ] [Automatically merge when pipeline succeeds](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html) - -## Test and Deploy - -Use the built-in continuous integration in GitLab. - -- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html) -- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing(SAST)](https://docs.gitlab.com/ee/user/application_security/sast/) -- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html) -- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/) -- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html) - -*** - -# Editing this README - -When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thank you to [makeareadme.com](https://www.makeareadme.com/) for this template. - -## Suggestions for a good README -Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information. - -## Name -Choose a self-explaining name for your project. - -## Description -Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors. - -## Badges -On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge. - -## Visuals -Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method. - -## Installation -Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection. - -## Usage -Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README. - -## Support -Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc. - -## Roadmap -If you have ideas for releases in the future, it is a good idea to list them in the README. - -## Contributing -State if you are open to contributions and what your requirements are for accepting them. - -For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self. - -You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser. - -## Authors and acknowledgment -Show your appreciation to those who have contributed to the project. - -## License -For open source projects, say how it is licensed. - -## Project status -If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers. +## Copy This Repo Into Your Own Git Server + +To get started with using the control-repo template in your own environment and git server, we've provided steps for the three most common servers we see: [GitLab](#gitlab), [BitBucket](#bitbucketstash), and [GitHub](#github). + +### GitLab + +1. Install GitLab. + * <https://about.gitlab.com/downloads/> +1. After GitLab is installed you may sign in with the `root` user. If you didn't specify a custom password during installation, a temporary password is located in `/etc/gitlab/initial_root_password`. +1. Make a user for yourself. +1. Make an SSH key to link with your user. You’ll want to do this on the machine you intend to edit code from (most likely not your Puppet master, but your local workstation or laptop). + * <https://docs.gitlab.com/ee/ssh/index.html> + * <https://help.github.com/articles/generating-ssh-keys/> +1. Create a group called `puppet` (this is case sensitive). + * <https://docs.gitlab.com/ee/user/group/index.html> +1. Add your user to the `puppet` group as well. +1. Create a project called `control-repo`, and set the Namespace to be the `puppet` group. +1. Clone this control repository to your laptop/workstation: + * `git clone <repository url>` + * `cd control-repo` +1. Remove this repository as the origin remote: + * `git remote remove origin` +1. Add your internal repository as the origin remote: + * `git remote add origin <url of your gitlab repository>` +1. Push the production branch of the repository from your machine up to your git server + * `git push origin production` + +### Bitbucket/Stash + +1. Install Bitbucket + * <https://www.atlassian.com/software/bitbucket/download> +1. Make a `Project` called `puppet` (with a short name of `PUP`) +1. Create a repository called `control-repo` +1. Create a user called `r10k` with a password of `puppet`. + * Make the r10k user an admin of the `PUP` project. +1. Either use the admin user to test pushing code, or create a user for yourself and add your SSH key to that user. + * If making a user for yourself, give your user account read/write or admin privilege to the `PUP` project. +1. Clone this control repository to your laptop/workstation + * `git clone <repository url>` + * `cd control-repo` +1. Remove this repository as the origin remote + * `git remote remove origin` +1. Add your internal repository as the origin remote + * `git remote add origin <url of your bitbucket repository>` +1. Push the production branch of the repository from your machine up to your git server + * `git push origin production` + +### GitHub + +Follow [GitHub's documentation](https://docs.github.com/en/github/creating-cloning-and-archiving-repositories/creating-a-repository-from-a-template) to create your control repository starting from this template. + +<img width="429" alt="template button" src="https://user-images.githubusercontent.com/1392917/117215366-f4eeb280-adb2-11eb-9108-1bd45c4d98f3.png"> + + +### GitHub Enterprise + +1. Prepare your local git client to authenticate with a **local GitHub Enterprise instance**. + * <https://help.github.com/articles/generating-ssh-keys/> + * <https://help.github.com/articles/adding-a-new-ssh-key-to-your-github-account/> +1. Create a repository called `control-repo` in your user account or organization. Ensure that "Initialize this repository with a README" is not selected. + * <https://help.github.com/articles/creating-a-new-repository/> +1. Make a note of your repository URL (HTTPS or SSH, depending on your security configuration). +1. Clone this control repository to your laptop/workstation: + * `git clone <repository url>` + * `cd control-repo` +1. Remove this repository as the origin remote: + * `git remote remove origin` +1. Add your internal repository as the origin remote: + * `git remote add origin <url of your github repository>` +1. Push the production branch of the repository from your machine up to your git server + * `git push origin production` + +## Code Manager Setup + +If you use Puppet Enterprise see the official [documentation](https://puppet.com/docs/pe/latest/code_mgr.html) for enabling Code Manager. diff --git a/data/common.yaml b/data/common.yaml new file mode 100644 index 0000000000000000000000000000000000000000..2baa62ba05dfa93a58f20bae37568fe239c3580a --- /dev/null +++ b/data/common.yaml @@ -0,0 +1,2 @@ +--- +message: "This node is using common data" diff --git a/data/nodes/example-node.yaml b/data/nodes/example-node.yaml new file mode 100644 index 0000000000000000000000000000000000000000..ed97d539c095cf1413af30cc23dea272095b97dd --- /dev/null +++ b/data/nodes/example-node.yaml @@ -0,0 +1 @@ +--- diff --git a/environment.conf b/environment.conf new file mode 100644 index 0000000000000000000000000000000000000000..494446620c087bfe7d11743d4e165348b48a55cc --- /dev/null +++ b/environment.conf @@ -0,0 +1,2 @@ +modulepath = site-modules:modules:$basemodulepath +config_version = 'scripts/config_version.sh $environmentpath $environment' diff --git a/hiera.yaml b/hiera.yaml new file mode 100644 index 0000000000000000000000000000000000000000..0f5c65769814da9323ce7734e7e82e69cbd4178b --- /dev/null +++ b/hiera.yaml @@ -0,0 +1,12 @@ +--- +version: 5 + +defaults: + datadir: "data" + +hierarchy: + - name: "Yaml backend" + data_hash: yaml_data + paths: + - "nodes/%{trusted.certname}.yaml" + - "common.yaml" diff --git a/manifests/site.pp b/manifests/site.pp new file mode 100644 index 0000000000000000000000000000000000000000..11663aa788e499b1c10511ac5afc4f9970e782cb --- /dev/null +++ b/manifests/site.pp @@ -0,0 +1,31 @@ +## site.pp ## + +# This file (./manifests/site.pp) is the main entry point +# used when an agent connects to a master and asks for an updated configuration. +# https://puppet.com/docs/puppet/latest/dirs_manifest.html +# +# Global objects like filebuckets and resource defaults should go in this file, +# as should the default node definition if you want to use it. + +## Active Configurations ## + +# Disable filebucket by default for all File resources: +# https://github.com/puppetlabs/docs-archive/blob/master/pe/2015.3/release_notes.markdown#filebucket-resource-no-longer-created-by-default +File { backup => false } + +## Node Definitions ## + +# The default node definition matches any node lacking a more specific node +# definition. If there are no other node definitions in this file, classes +# and resources declared in the default node definition will be included in +# every node's catalog. +# +# Note that node definitions in this file are merged with node data from the +# Puppet Enterprise console and External Node Classifiers (ENC's). +# +# For more on node definitions, see: https://puppet.com/docs/puppet/latest/lang_node_definitions.html +node default { + # This is where you can declare classes for all nodes. + # Example: + # class { 'my_class': } +} diff --git a/scripts/config_version-r10k.rb b/scripts/config_version-r10k.rb new file mode 100755 index 0000000000000000000000000000000000000000..beacabcc89567f71e114ff4e27595e5c860a82e6 --- /dev/null +++ b/scripts/config_version-r10k.rb @@ -0,0 +1,19 @@ +#!/opt/puppetlabs/puppet/bin/ruby +require 'json' +require 'socket' + +environmentpath = ARGV[0] +environment = ARGV[1] + +# Get the hostname of the Puppet master compiling the catalog. +# Sometimes the hostname is the fqdn, so we'll take the first segment. +compiling_master = Socket.gethostname.split('.').first + +# Get the path to the Code Manager deployment info file. +r10k_deploy_file_path = File.join(environmentpath, environment, '.r10k-deploy.json') + +# Get the first 12 characters of the commit ID out of the deployment file. +commit_id = JSON.parse(File.read(r10k_deploy_file_path))['signature'][0...11] + +# Show the compiling master, environment name, and commit ID. +puts "#{compiling_master}-#{environment}-#{commit_id}" diff --git a/scripts/config_version-rugged.rb b/scripts/config_version-rugged.rb new file mode 100755 index 0000000000000000000000000000000000000000..abb3390326bb1dd0535df24127498ab59537c2af --- /dev/null +++ b/scripts/config_version-rugged.rb @@ -0,0 +1,25 @@ +#!/opt/puppetlabs/puppet/bin/ruby +begin + require 'rugged' + require 'socket' +rescue LoadError + t = Time.new + puts t.to_i +else + environmentpath = ARGV[0] + environment = ARGV[1] + + # Get the hostname of the Puppet master compiling the catalog. + # Sometimes the hostname is the fqdn, so we'll take the first segment. + compiling_master = Socket.gethostname.split('.').first + + # Get the path to the environment being compiled. + repo = Rugged::Repository.discover(File.join(environmentpath, environment)) + head = repo.head + + # First 12 characters of the sha1 hash of the newest commit. + commit_id = head.target_id[0...11] + + # Show the compiling master, environment name, and commit ID. + puts "#{compiling_master}-#{environment}-#{commit_id}" +end diff --git a/scripts/config_version.sh b/scripts/config_version.sh new file mode 100755 index 0000000000000000000000000000000000000000..0dbf718f942a8cc0f4b6aa64f62b5a7eb4738508 --- /dev/null +++ b/scripts/config_version.sh @@ -0,0 +1,35 @@ +#!/bin/sh + +# Usage +if [ $# -ne 2 -o ! -d "$1" -o ! -d "$1/$2" ]; then + echo "usage: $0 <environmentpath> <environment>" >&2 + exit 1 +fi + +# For portability, identify a preferred ruby executable to use +ruby() { + [ -x /opt/puppetlabs/puppet/bin/ruby ] \ + && /opt/puppetlabs/puppet/bin/ruby "$@" \ + || /usr/bin/env ruby "$@" +} + +# Determine how best to calculate a config_version +if [ -e $1/$2/.r10k-deploy.json ]; then + # The environment was deployed using r10k. We will calculate the config + # version using the r10k data. + ruby $1/$2/scripts/config_version-r10k.rb $1 $2 + +elif [ -e /opt/puppetlabs/server/pe_version ]; then + # This is a Puppet Enterprise system and we can rely on the rugged ruby gem + # being available. + ruby $1/$2/scripts/config_version-rugged.rb $1 $2 + +elif type git >/dev/null && [ -d "$1/$2/.git" ]; then + # The git command is available. + git --git-dir $1/$2/.git rev-parse HEAD + +else + # Nothing else available; just use the date. + date +%s + +fi diff --git a/site-modules/adhoc/plans/myplan.pp b/site-modules/adhoc/plans/myplan.pp new file mode 100644 index 0000000000000000000000000000000000000000..e60e742ea5239243c931ba70dba721efc9e57228 --- /dev/null +++ b/site-modules/adhoc/plans/myplan.pp @@ -0,0 +1,9 @@ +# This is a description for my plan +plan adhoc::myplan( + # input parameters go here + TargetSpec $targets, +) { + + # plan steps go here + +} diff --git a/site-modules/adhoc/tasks/nix_example.json b/site-modules/adhoc/tasks/nix_example.json new file mode 100644 index 0000000000000000000000000000000000000000..2c4d5c7037b9e42d0dafe5ff96fcf85d99c0d425 --- /dev/null +++ b/site-modules/adhoc/tasks/nix_example.json @@ -0,0 +1,4 @@ +{ + "description": "This is the description for the nix_example task", + "input_method": "environment" +} diff --git a/site-modules/adhoc/tasks/nix_example.sh b/site-modules/adhoc/tasks/nix_example.sh new file mode 100644 index 0000000000000000000000000000000000000000..6b063779bdd17052db832f75d23bb1c0b5dc20fa --- /dev/null +++ b/site-modules/adhoc/tasks/nix_example.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +# task content goes here diff --git a/site-modules/adhoc/tasks/win_example.json b/site-modules/adhoc/tasks/win_example.json new file mode 100644 index 0000000000000000000000000000000000000000..42dccda334cfc18fe351d05d87d1eef405b17568 --- /dev/null +++ b/site-modules/adhoc/tasks/win_example.json @@ -0,0 +1,4 @@ +{ + "description": "This is the description for the win_example task", + "input_method": "powershell" +} diff --git a/site-modules/adhoc/tasks/win_example.ps1 b/site-modules/adhoc/tasks/win_example.ps1 new file mode 100644 index 0000000000000000000000000000000000000000..3a109ee460790db4ca5287a2028fc12ba86e5777 --- /dev/null +++ b/site-modules/adhoc/tasks/win_example.ps1 @@ -0,0 +1 @@ +# task content goes here diff --git a/site-modules/profile/manifests/base.pp b/site-modules/profile/manifests/base.pp new file mode 100644 index 0000000000000000000000000000000000000000..b9e130dda53f9de3bcbdbc42ab3575fa892273a6 --- /dev/null +++ b/site-modules/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/site-modules/profile/manifests/example.pp b/site-modules/profile/manifests/example.pp new file mode 100644 index 0000000000000000000000000000000000000000..6505aa9ff82b9ed0affc8b299c00d09999ad5a0e --- /dev/null +++ b/site-modules/profile/manifests/example.pp @@ -0,0 +1,4 @@ +# An example profile +class profile::example { + +} diff --git a/site-modules/role/manifests/database_server.pp b/site-modules/role/manifests/database_server.pp new file mode 100644 index 0000000000000000000000000000000000000000..59cbc0f7dbb4042ee1a35dae46d68c38c0a6af5a --- /dev/null +++ b/site-modules/role/manifests/database_server.pp @@ -0,0 +1,7 @@ +# This role would be made of all the profiles that need to be included to make a database server work +# All roles should include the base profile +class role::database_server { + + include profile::base + +} diff --git a/site-modules/role/manifests/example.pp b/site-modules/role/manifests/example.pp new file mode 100644 index 0000000000000000000000000000000000000000..35666bbc58e278cd9f59f0e230fe27c72968b49b --- /dev/null +++ b/site-modules/role/manifests/example.pp @@ -0,0 +1,4 @@ +# An example role +class role::example { + +} diff --git a/site-modules/role/manifests/webserver.pp b/site-modules/role/manifests/webserver.pp new file mode 100644 index 0000000000000000000000000000000000000000..ce943a0710514e3bf6699730f11288a7a11a3f50 --- /dev/null +++ b/site-modules/role/manifests/webserver.pp @@ -0,0 +1,7 @@ +# This role would be made of all the profiles that need to be included to make a webserver work +# All roles should include the base profile +class role::webserver { + + include profile::base + +}