- Puppet 2.7 Cookbook
- John Arundel
- 823字
- 2021-04-02 18:19:56
Using version control
"Unix was not designed to stop you from doing stupid things, because that would also stop you from doing clever things." —Doug Gwyn
Ever deleted something and wished you hadn't? The most important tip in this book is to put your Puppet manifests in a version control system such as Git or Subversion. Editing the manifests directly on the Puppetmaster is a bad idea, because your changes could get applied before you're ready. Puppet automatically detects any changes to manifest files, so you might find half-finished manifests being applied to your clients. This could have nasty results!
Instead, use version control (I recommend Git) and make the /etc/puppet
directory on the Puppetmaster a checkout from your repository. This gives you several advantages:
- You don't run the risk of Puppet applying incomplete changes
- You can undo changes and revert to any previous version of your manifest
- You can experiment with new features using a branch, without affecting the master version used in production
- If several people need to make changes to the manifests, they can make them independently, in their own working copies, and then merge their changes later
- You can use the log feature to see what was changed, and when (and by whom).
Getting ready
You'll need a Puppetmaster and a set of existing manifests in /etc/puppet
. If you don't have these already, refer to the Puppet documentation to find out how to install Puppet and create your first manifests.
To put your manifests under version control, you need to import the /etc/puppet
directory from the Puppetmaster into your version control system, and make it a working copy. In this example, we'll use a GitHub account to store the Puppet configuration.
You'll need a GitHub account (it's free to sign up) and a repository. Follow the instructions at www.github.com to create one.
Tip
You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.
How to do it...
- To turn the
/etc/puppet
directory on the Puppetmaster into a Git repository, run the following commands:root@cookbook:/etc/puppet# git init Initialized empty Git repository in /etc/puppet/.git/ root@cookbook:/etc/puppet# git add manifests/ modules/ root@cookbook:/etc/puppet# git commit -m "initial commit" [master (root-commit) c7a24cf] initial commit 59 files changed, 1790 insertions(+), 0 deletions(-) create mode 100644 manifests/site.pp create mode 100644 manifests/utils.pp ...
- Connect this to your GitHub repo and
push
as follows:# git push -u origin master Counting objects: 91, done. Compressing objects: 100% (69/69), done. Writing objects: 100% (91/91), 21.07 KiB, done. Total 91 (delta 4), reused 0 (delta 0) To git@github.com:bitfield/puppet-demo.git * [new branch] master -> master
Branch master setup to track remote branch masters from the origin.
How it works...
You've created a "master" repository (usually known as a repo for short) at GitHub which contains your Puppet manifests. You can check out multiple copies of this in different places and work on them before committing your changes. For example, if you had a team of system admins, each of them could work on their own local copy of the repo.
The copy in /etc/puppet
on the Puppetmaster is now just another working copy, slaved to the GitHub repo. When you decide that you want to tell Puppet about your changes, you can update this copy and it will pull the latest changes from GitHub.
There's more...
Now that you've set up version control, you can use the following workflow for editing your Puppet manifests:
- Make your changes in the working copy using your favorite text editor.
- Commit the changes and push them to the GitHub repo, as shown in the preceding text.
- Update the Puppetmaster's working copy, using
git pull.
- Here is an example where we add a new file to the manifest, commit it, and then update the Puppetmaster's working copy. I've made some edits to the working copy on my laptop:
john@laptop:~$ cd puppet-work john@laptop:~/puppet-work$ mkdir manifests john@laptop:~/puppet-work$ touch manifests/nodes.pp john@laptop:~/puppet-work$ git add manifests/nodes.pp john@laptop:~/puppet-work$ git commit -m "adding nodes.pp" [master 5c7b94c] adding nodes.pp 0 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 manifests/nodes.pp john@laptop:~/puppet-work$ git push Counting objects: 7, done. Compressing objects: 100% (4/4), done. Writing objects: 100% (4/4), 409 bytes, done. Total 4 (delta 1), reused 0 (delta 0) To git@github.com:bitfield/puppet-demo.git c7a24cf..b74d452 master -> master
- Now I'll update the working copy on the Puppetmaster:
root@cookbook:/etc/puppet# git pull remote: Counting objects: 5, done. remote: Compressing objects: 100% (2/2), done. remote: Total 4 (delta 0), reused 0 (delta 0) Unpacking objects: 100% (4/4), done. From git@github.com:bitfield/puppet-demo.git 26d668c..5c7b94c master -> origin/master Updating 26d668c..5c7b94c Fast-forward 0 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 manifests/nodes.pp
- You can automate this process by using a tool such as Rake.
- Here is an example where we add a new file to the manifest, commit it, and then update the Puppetmaster's working copy. I've made some edits to the working copy on my laptop:
See also
- Deploying changes with Rake in this chapter
- Creating a decentralized Puppet architecture in this chapter
- Using commit hooks in this chapter
- 持續(xù)演進(jìn)的Cloud Native:云原生架構(gòu)下微服務(wù)最佳實(shí)踐
- JasperReports for Java Developers
- Hi!扁平化Photoshop扁平化用戶界面設(shè)計(jì)教程
- Photoshop CS6完全自學(xué)案例教程(微課版)
- 中文版Illustrator CC基礎(chǔ)培訓(xùn)教程(移動(dòng)學(xué)習(xí)版)
- ABAQUS有限元分析從入門到精通(第3版)
- Photoshop網(wǎng)店圖片處理實(shí)訓(xùn)教程
- Photoshop CC UI設(shè)計(jì)標(biāo)準(zhǔn)培訓(xùn)教程
- Autodesk Ecotect Analysis綠色建筑分析應(yīng)用
- Learning the Yahoo! User Interface library
- Photoshop CS6平面設(shè)計(jì)實(shí)戰(zhàn)從入門到精通(經(jīng)典暢銷版)
- Configuring IPCop Firewalls: Closing Borders with Open Source
- 邊做邊學(xué):CorelDRAW X6圖形設(shè)計(jì)案例教程(第2版)(微課版)
- 零基礎(chǔ)學(xué)Photoshop CS6(全視頻教學(xué)版)
- Deep Inside osCommerce: The Cookbook