- cfpuppetserver - Puppet Server + PuppetDB + PostgreSQL + r10k + librarian-puppet automatic configuration module
- Brief Introduction to Puppet
- Describes initial deployment from scratch
Some lyrics. It would seem that the whole cycle should be started with this article, but the target audience is more experienced users of the Open Source products of Puppet Labs, who are not satisfied with the separate little-integrated modules with Puppet Forge. As with any case of the “library vs. framework”, the cost is to follow the author’s worldview of the integrated solution.
Puppet is first and foremost a specific language for the declarative specification of the final state of the system. For comparison, the GNU Makefile is extremely suitable, where, in addition to directly describing dependencies, there is the possibility of starting to the fullest.
Abstraction Puppet is about the following ( disrupting templates - forget everything you knew about the terms in programming! ).
define
, which creates instances of other types or as an extension to Ruby with a flight of fancy.Puppet can be used for local deployment without a network and related infrastructure. This can be used to create container images. There is even a whole line of campaigners for abandoning the centralized server.
In the ideologically correct key, the Puppet infrastructure consists of an agent — a privileged service on the target system and a server that distributes valuable instructions in the form of declarative resource directories upon request from agents. Security is implemented at the level of a private public key infrastructure ( X.509 ). Simply put, the same mechanisms as in HTTPS, but with its own CA and mandatory verification of the client certificate.
In a simplified form, the deployment procedure looks like this:
puppet facts
. These facts are available as global variables.For tasting all the charms, there are additional buns in the form:
first
- the first priority value is givenunique
- collects all values ​​into a one-dimensional array and removes duplicateshash
- unites all found YAML Hash. Duplicate keys are selected by priority.deep
- essentially a recursive version of hashlookup()
function, since and in any hierarchy file using the special key lookup_options , which is actively used in the cfnetwork module.It is required to understand that Puppet Server becomes a vulnerability of the entire IT infrastructure, since determines the final configuration of all systems. In special cases, it makes sense to do the separation - a separate server for critical infrastructure elements with extremely limited access and manual updating, and the second for everything else.
Availability Puppet Server determines the ability to manage the entire infrastructure. It makes sense to place Puppet Server on a virtual machine in a more reliable and quickly recoverable third-party cloud than its own capabilities. Or, you should install multiple servers.
In any case, do not install other services on the system where Puppet Server with gadgets will be deployed. Virtualization and containerization to help you.
The manufacturer has a full description.
puppet lookup
.This process is quite primitive, but requires adherence to a certain sequence of steps. Since doing it manually is a thankless task, the author will teach the bad, namely, download incomprehensible scripts from the Internet and run as root on his system.
The three main components of the server are Puppet Server, PuppetDB and PostgreSQL itself. They can all be pushed into one node or split into two or three systems. Puppet Server and Puppet DB can be run multiple times, but PostgeSQL is a single point of failure. There are various approaches to replication and clustering of PostgeSQL. A convenient approach in the case of primary and secondary servers will be Master + Read-Only Slave, which is supported in PuppetDB itself as the main and read-only database node, but automating this configuration takes time and therefore has not yet Included in the cfpuppetserver
module.
Directly, the configuration can be simply stored at least on the file system along with Puppet Server, but this is how to write scripts on the combat web server. The best solution is the git repository. The r10k utility can pull out all the branches of the repository and deploy them to the Puppet Server as separate Environments. r10k
is bad enough with dependency pulling, so librarian-puppet is used on top. It is worth noting immediately that the main canonical environment of Puppet is "production". Therefore, in the configuration repository, you should use a branch called "production" and not "master".
For iron described by the manufacturer . The cfpuppetserver
module cfpuppetserver
only supports Debian Jessie + and Ubuntu Trusty +.
For the r10k itself, the placement of the repository does not really matter - the main thing is its availability. For example, for testing purposes, the repository can be placed on the same system with access via file://
. A good start would be an example of the codingfuture / puppet-exampleenv configuration .
git clone https://github.com/codingfuture/puppet-exampleenv my-puppet-conf && cd my-puppet-conf
repository: git clone https://github.com/codingfuture/puppet-exampleenv my-puppet-conf && cd my-puppet-conf
$EDITOR data/common.yaml
$MY_DOMAIN
- root domain name (for example, example.org)$HOST_NAME
- the name of the client node without a domainmkdir data/$MY_DOMAIN
cp data/example.com/puppet.yaml data/${MY_DOMAIN}/puppet.yaml
$EDITOR nano -w data/${MY_DOMAIN}/puppet.yaml
- setting up a node with Puppet Server according to the prompts in the commentscp data/example.com/host.yaml data/${MY_DOMAIN}/${HOST_NAME}.yaml
$EDITOR nano -w data/${MY_DOMAIN}/${HOST_NAME}.yaml
- setting up an arbitrary node using the prompts in the commentsThe cfpuppetserver
module allows cfpuppetserver
to install everything using the Puppet tool itself, but for the initial installation, the basic operations are duplicated by the Bash script.
On the target system:
wget https://raw.githubusercontent.com/codingfuture/puppet-cfpuppetserver/master/setup_puppetserver.sh
less setup_puppetserver.sh
bash setup_puppetserver.sh <repo_uri> puppet.${MY_DOMAIN}
.bash setup_puppetserver.sh ssh://git@git.example.com/puppet-conf
bash setup_puppetserver.sh file:///root/puppetconf/
ssh-keygen -t rsa -b 2048
/root/.ssh/id_rsa.pub
on a remote Git server .../usr/bin/ssh -T deploypuppet@puppet.${MY_DOMAIN} ./puppetdeploy.sh
/etc/puppetlabs/deploy.sh
/opt/puppetlabs/bin/puppet agent --test
echo "128.1.1.1 puppet.example.com" >> /etc/hosts
/opt/codingfuture/bin/cf_gen_puppet_client_init ${HOST_NAME}.${MY_DOMAIN}
./opt/puppetlabs/bin/puppet agent --test
. When you first start, a certificate signing request will be generated.puppet cert list
- we verify the signature of the certificate for greater paranoia.puppet cert sign ${HOST_NAME}.${MY_DOMAIN}
- in fact, we sign the certificate. bash <<EOT #!/bin/bash http_proxy= if test "\$(id -un)" != 'root'; then echo 'This script must run as root' exit 1 fi if test ! -z ""; then echo -n >/etc/cflocation fi if test ! -z ""; then echo -n >/etc/cflocationpool fi if test ! -z "\$http_proxy"; then export http_proxy export https_proxy="\$http_proxy" export HTTP_PROXY="\$http_proxy" export HTTPS_PROXY="\$http_proxy" fi echo host.example.com > /etc/hostname hostname host.example.com if ! which lsb-release | read; then apt-get install lsb-release fi codename=\$(lsb_release -cs) if test -z "\$codename"; then echo "Failed to detect correct codename" exit 1 fi wget https://apt.puppetlabs.com/puppetlabs-release-pc1-\${codename}.deb dpkg -i puppetlabs-release-pc1-\${codename}.deb mkdir -p /etc/puppetlabs/puppet cat > /etc/puppetlabs/puppet/puppet.conf <<EOF [main] certname = host.example.com server = puppet.example.com ca_server = puppet.example.com environment = production EOF apt-get update && apt-get install puppet-agent while ! /opt/puppetlabs/bin/puppet agent --test --wairforcert 120; do echo "Please go to puppetserver and exec the following command when we wait for key" echo "> puppet cert sign host.example.com" echo "Use CTRL+C to stop cycle, if fails due to different reasons" sleep 5 done EOT
~# ./setup_puppetserver.sh Usage: ./setup_puppetserver.sh <r10k_repo_url> [<certname=hostname> [<cflocation> [<cflocationpool> [<http_proxy>] ] ] ]
r10k_repo_url
- Git URI repositorycertname
- FQDN of the nodecflocation
- initialization of the fact cf_locationcflocationpool
- initialize the cf_location_pool facthttp_proxy
- proxy server for HTTP and HTTPS requests ~# /opt/codingfuture/bin/cf_gen_puppet_client_init Usage: cf_gen_puppet_client_init <certname> [<cflocation> [<cflocationpool> [<http_proxy>]]]
The value of the parameters is the same as in the previous script.
cfpuppetserver
classdeployuser = 'deploypuppet'
- username for automatic deployment of configuration updatesdeployuser_auth_keys = undef
- list of keys for $ deployuserrepo_url = undef
- repository URI (example: ssh: // user @ host / repo or file: /// some / path)puppetserver = true
- whether to install the Puppet Server component on this nodepuppetdb = true
- whether to install the PuppetDB component on this nodepuppetdb_port = 8081
- port for PuppetDBsetup_postgresql = true
- whether to install the PostgreSQL component on this node (only if the PuppetDB installation is enabled)service_face = 'any'
- the name of the cfnetwork::iface
for accepting incoming connectionspuppetserver_mem = auto
- RAM under Puppet Server in megabytes (minimum 192MB)puppetdb_mem = auto
- RAM under PuppetDB in megabytes (minimum 192MB)postgresql_mem = auto
- RAM under PostgreSQL in megabytes (at least 128MB)cfpuppetserver::puppetdb
postgresql_host = 'localhost'
- database addresspostgresql_listen = $postgresql_host
- the value goes directly to PostgreSQL listen_addresses
postgresql_port = 5432
- database portpostgresql_user = 'puppetdb'
- PuppetDB user in databasepostgresql_pass = 'puppetdb'
is the password of the PuppetDB user in the databasepostgresql_ssl = false
- enable connection encryption based on Puppet PKI certificatescfpuppetserver::puppetserver
autosign = false
- DO NOT use in a combat environment, except in the DMZ. There is only to automate testing.global_hiera_config = 'cfpuppetserver/hiera.yaml'
- the path to the default Hiera configuration file according to the canons of Puppet (the first component is the module name, the rest is the path under the files/
folder in the module)UPD 2016-03-12
Updated the name of the client initialization generation script (cf_gen_puppet_client_init).
Source: https://habr.com/ru/post/278163/
All Articles