Puppet 简明教程

Puppet - Installing and Configuring r10K

在 Puppet 中,我们有一个已知的代码管理工具叫 r10k,它有助于管理与我们在 Puppet 中配置的不同类型的环境相关的环境配置,例如开发、测试和生产。这有助于在源代码库中存储与环境相关的配置。使用源代码控制库分支,r10k 会在 Puppet 主控机上创建环境安装,并使用库中现有的模块更新环境。

In Puppet, we have a code management tool known as r10k that helps in managing environment configurations related to different kind of environments that we can configure in Puppet such as development, testing, and production. This helps in storing environment-related configuration in the source code repository. Using the source control repo branches, r10k creates environments on Puppet master machine installs and updates environment using modules present in the repo.

Gem 文件可以用来在任何机器上安装 r10k,但为了模块化并获得最新版本,我们将使用 rpm 和 rpm 包管理器。以下是同一个示例。

Gem file can be used to install r10k on any machine but for modularity and in order to get the latest version, we will use rpm and rpm package manager. Following is an example for the same.

$ urlgrabber -o /etc/yum.repos.d/timhughes-r10k-epel-6.repo
https://copr.fedoraproject.org/coprs/timhughes/yum -y install rubygem-r10k

在 /etc/puppet/puppet.conf 中配置环境

Configure environment in /etc/puppet/puppet.conf

[main]
environmentpath = $confdir/environments

Create a Configuration File for r10k Config

cat <<EOF >/etc/r10k.yaml
# The location to use for storing cached Git repos
:cachedir: '/var/cache/r10k'
# A list of git repositories to create
:sources:
# This will clone the git repository and instantiate an environment per
# branch in /etc/puppet/environments
:opstree:
#remote: 'https://github.com/fullstack-puppet/fullstackpuppet-environment.git'
remote: '/var/lib/git/fullstackpuppet-environment.git'
basedir: '/etc/puppet/environments'
EOF

Installing Puppet Manifest and Module

r10k deploy environment -pv

由于我们需要每 15 分钟就持续更新环境,我们将为此创建一个 cron 作业。

As we need to continue updating the environment in every 15 minutes, we will create a cron job for the same.

cat << EOF > /etc/cron.d/r10k.conf
SHELL = /bin/bash
PATH = /sbin:/bin:/usr/sbin:/usr/bin
H/15 * * * * root r10k deploy environment -p
EOF

Testing Installation

为了测试是否一切按照接受的方式工作,你需要为 Puppet 模块编译 Puppet 清单。运行以下命令并获取 YAML 输出作为结果。

In order to test if everything works as accepted, one needs to compile the Puppet manifest for Puppet module. Run the following command and get a YAML output as the result.

curl --cert /etc/puppet/ssl/certs/puppet.corp.guest.pem \
--key /etc/puppet/ssl/private_keys/puppet.corp.guest.pem \
--cacert /etc/puppet/ssl/ca/ca_crt.pem \
-H 'Accept: yaml' \
https://puppet.corp.guest:8140/production/catalog/puppet.corp.guest