- DevOps:Puppet,Docker,and Kubernetes
- Thomas Uphill John Arundel Neependra Khare Hideto Saito Hui Chuan Chloe Lee Ke Jou Carol Hsu
- 531字
- 2021-07-09 18:32:51
Bootstrapping Puppet with bash
Previous versions of this book used Rakefiles to bootstrap Puppet. The problem with using Rake to configure a node is that you are running the commands from your laptop; you assume you already have ssh
access to the machine. Most bootstrap processes work by issuing an easy to remember command from a node once it has been provisioned. In this section, we'll show how to use bash to bootstrap Puppet with a web server and a bootstrap script.
Getting ready
Install httpd on a centrally accessible server and create a password protected area to store the bootstrap script. In my example, I'll use the Git server I set up previously, git.example.com
. Start by creating a directory in the root of your web server:
# cd /var/www/html # mkdir bootstrap
Now perform the following steps:
- Add the following location definition to your apache configuration:
<Location /bootstrap> AuthType basic AuthName "Bootstrap" AuthBasicProvider file AuthUserFile /var/www/puppet.passwd Require valid-user </Location>
- Reload your web server to ensure the location configuration is operating. Verify with curl that you cannot download from the bootstrap directory without authentication:
[root@bootstrap-test tmp]# curl http://git.example.com/bootstrap/ <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head> <title>401 Authorization Required</title> </head><body> <h1>Authorization Required</h1>
- Create the password file you referenced in the apache configuration (
/var/www/puppet.passwd
):root@git# cd /var/www root@git# htpasswd –cb puppet.passwd bootstrap cookbook Adding password for user bootstrap
- Verify that the username and password permit access to the bootstrap directory as follows:
[root@node1 tmp]# curl --user bootstrap:cookbook http://git.example.com/bootstrap/ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> <html> <head> <title>Index of /bootstrap</title>
How to do it...
Now that you have a safe location to store the bootstrap script, create a bootstrap script for each OS you support in the bootstrap directory. In this example, I'll show you how to do this for a Red Hat Enterprise Linux 6-based distribution.
Tip
Although the bootstrap location requires a password, there is no encryption since we haven't configured SSL on our server. Without encryption, the location is not very safe.
Create a script named el6.sh
in the bootstrap directory with the following contents:
#!/bin/bash # bootstrap for EL6 distributions SERVER=git.example.com LOCATION=/bootstrap BOOTSTRAP=bootstrap.pp USER=bootstrap PASS=cookbook # install puppet curl http://yum.puppetlabs.com/RPM-GPG-KEY-puppetlabs >/etc/pki/rpm-gpg/RPM-GPG-KEY-puppetlabs rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-puppetlabs yum -y install http://yum.puppetlabs.com/puppetlabs-release-el-6.noarch.rpm yum -y install puppet # download bootstrap curl --user $USER:$PASS http://$SERVER/$LOCATION/$BOOTSTRAP >/tmp/$BOOTSTRAP # apply bootstrap cd /tmp puppet apply /tmp/$BOOTSTRAP # apply puppet puppet apply --modulepath /etc/puppet/cookbook/modules /etc/puppet/cookbook/manifests/site.pp
How it works...
The apache configuration only permits access to the bootstrap directory with a username and password combination. We supply these with the --user
argument to curl, thereby getting access to the file. We use a pipe (|
) to redirect the output of curl into bash. This causes bash to execute the script. We write our bash script like we would any other bash script. The bash script downloads our bootstrap.pp
manifest and applies it. Finally, we apply the Puppet manifest from the Git repository and the machine is configured as a member of our decentralized infrastructure.
There's more...
To support another operating system, we only need to create a new bash script. All Linux distributions will support bash scripting, Mac OS X does as well. Since we placed much of our logic into the bootstrap.pp
manifest, the bootstrap script is quite minimal and easy to port to new operating systems.
- R Data Mining
- Learning Social Media Analytics with R
- 流處理器研究與設(shè)計(jì)
- 讓每張照片都成為佳作的Photoshop后期技法
- Supervised Machine Learning with Python
- 中國(guó)戰(zhàn)略性新興產(chǎn)業(yè)研究與發(fā)展·智能制造
- INSTANT Autodesk Revit 2013 Customization with .NET How-to
- 網(wǎng)絡(luò)化分布式系統(tǒng)預(yù)測(cè)控制
- 運(yùn)動(dòng)控制系統(tǒng)應(yīng)用與實(shí)踐
- Citrix? XenDesktop? 7 Cookbook
- C++程序設(shè)計(jì)基礎(chǔ)(上)
- Web璀璨:Silverlight應(yīng)用技術(shù)完全指南
- 實(shí)戰(zhàn)Windows Azure
- 軟件質(zhì)量管理實(shí)踐
- 超好玩的Python少兒編程