📜 ⬆️ ⬇️

CodingFuture + Puppet. Part III: Install Puppet Server (cfpuppetserver)

In short:


  1. cfpuppetserver - Puppet Server + PuppetDB + PostgreSQL + r10k + librarian-puppet automatic configuration module
  2. Brief Introduction to Puppet
  3. Describes initial deployment from scratch


Thematic cycle:



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.


A little bit about how Puppet works


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! ).



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:


  1. Processing using TLS and X.509 (establishing a connection, updating the CRL, checking certificate limits, etc.)
  2. The agent receives fact generators from the server with caching and all the tasks (more precisely, everything from the lib / folders in modules is pulled). It’s easy to add your Ruby script to collect information of interest.
  3. The agent collects facts about the target system and sends to the server. All facts can be easily viewed manually through puppet facts . These facts are available as global variables.
  4. The server makes a directory of resources and sends it to the agent. Under this lies a whole layer of different concepts.
  5. The agent pulls everything you need from the server and brings the system to the specified form. The agent himself does not know how to deal with resources, he relies on the implementation of providers (the semantic translation will be the "embodiment", and not the supplier) of specific types of resources. Some providers are standard and come in Puppet packages, while the rest are pulled out of the modules.

For tasting all the charms, there are additional buns in the form:



Security and Availability Notes


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.


Multi-master (several separate Puppet Server)



What significant has changed from older versions


The manufacturer has a full description.



Installation


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".


System requirements


For iron described by the manufacturer . The cfpuppetserver module cfpuppetserver only supports Debian Jessie + and Ubuntu Trusty +.


Configuration in git


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 .


  1. 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
  2. Set the general admin access settings, using the hints in the comments:
    • $EDITOR data/common.yaml
  3. Create a node configuration:
    • $MY_DOMAIN - root domain name (for example, example.org)
    • $HOST_NAME - the name of the client node without a domain
    • mkdir 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 comments
    • cp 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 comments
  4. We push on own Git the server or we make available locally on a node with Puppet Server through rsync or scp. The local repository is convenient as an intermediate step until the Git server is deployed from the Puppet itself. In a sense, it resembles a compiler build in several steps.

We put from scratch on a clean system


The 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:


  1. Download the installation script: wget https://raw.githubusercontent.com/codingfuture/puppet-cfpuppetserver/master/setup_puppetserver.sh
  2. Check the script and frown: less setup_puppetserver.sh
  3. Run: bash setup_puppetserver.sh <repo_uri> puppet.${MY_DOMAIN} .
    • Example with remote repository: bash setup_puppetserver.sh ssh://git@git.example.com/puppet-conf
    • Example with local: bash setup_puppetserver.sh file:///root/puppetconf/
  4. We look how the system puffs up and does not install everything very quickly.
  5. If remote repository:
    • Create a ssh key at root: ssh-keygen -t rsa -b 2048
    • We register the public key /root/.ssh/id_rsa.pub on a remote Git server ...
    • ... and in the same place we configure Git hook with a call of the following command: /usr/bin/ssh -T deploypuppet@puppet.${MY_DOMAIN} ./puppetdeploy.sh
  6. Run the manual configuration deployment: /etc/puppetlabs/deploy.sh
  7. Trying how it works on the server itself: /opt/puppetlabs/bin/puppet agent --test
  8. Check network settings, network filter and SSH access

Add managed nodes


  1. The full name of the Puppet Server should be accessible via DNS on the managed host or should be “sewn up” in / etc / hosts.
    • Example: echo "128.1.1.1 puppet.example.com" >> /etc/hosts
  2. On the node with Puppet Server, run the following script /opt/codingfuture/bin/cf_gen_puppet_client_init ${HOST_NAME}.${MY_DOMAIN} .
  3. The result is copied entirely and pasted into the command line on the target system.
  4. We are waiting for the execution to finish and run /opt/puppetlabs/bin/puppet agent --test . When you first start, a certificate signing request will be generated.
  5. Go to the Puppet Server node to sign the certificate.
    • 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.
  6. Go back to the managed node and run: / opt / puppetlabs / bin / puppet agent - test` again. This will force the deployment procedure.
  7. We are waiting until the end of the deployment via Puppet Agent.
  8. Everything, you have a minimal Puppet infrastructure ready!

Sample output / opt / codingfuture / bin / cf_gen_puppet_client_init
 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 

Module Description


Full list of Bash parameters of the initial installation script


 ~# ./setup_puppetserver.sh Usage: ./setup_puppetserver.sh <r10k_repo_url> [<certname=hostname> [<cflocation> [<cflocationpool> [<http_proxy>] ] ] ] 


Full list of Bash parameters for the Puppet Client Initialization Script


 ~# /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 class



class cfpuppetserver::puppetdb



class cfpuppetserver::puppetserver



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