Skip to main content

Wrapper for r10k

Project description

Overview

It’s the API to r10k utility. With it you can get your puppet code automatically deployed to puppet server after pushing to git. Assumed that you use r10k for deployment puppet environments from git branches and want to get done it automatically after pushing.

Server application works as a daemon, listens at requests and invokes local r10k utility. It’s complete wrapper: generates config, launches r10k, controls and performs post-run actions. Client application is launched as VCS hook and calls server application informing about branch which has been pushed.

Features

  • Allows mapping of git branches to puppet environments using regex. E.g. branch ‘master’ may be mapped to puppet environment ‘production’.

  • Accepts regex pattern by which name of branch is filtered. A branch will be deployed only if matches regex.

  • Runs only one instance of r10k simultaneously. Deduplicates and keeps all requests in a queue, so that any request won’t be missed.

  • Launches ‘generate types’ after r10k for environment isolation.

  • Sends command flushing cache for an environment to api of puppet server after r10k has finished.

  • Depends on only one third-party package - pyaml.

Getting started

Installation at puppet server.

Firstly, install and set r10k utility to your repository. Ensure that following command works.

r10k deploy environment <env_name> -v

env_name has to be name of one of existent branches in your repo.

If you don’t have errors, proceed with installation of r10k-webhook.

pip3 install r10k-webhook
systemctl daemon-reload

Enable and start service.

systemctl enable r10k-webhook
systemctl start r10k-webhook

Check logs and status.

journalctl -xeu r10k-webhook
curl localhost:8088/status

If daemon doesn’t start, go on with Configuration.

Installation at VCS.

Install the package to server with your repository of puppet code.

pip3 install r10k-webhook

Trigger your puppet server with <env_name>.

r10k_webhook -s <puppetserver.hostname> -b <env_name>

Take <puppetserver.hostname> and <env_name> as you used at Installation at puppet server. You should see following output:

Deployed the branch to 1 servers out of 1.

It means that your have deployed content of the branch to the directory of environment at puppet server host.

Use with gitolite.

Create list with servers in json file looks like

[
  "server1",
  "server2"
]

Add a hook to your control repo consists of

#!/usr/bin/env bash
r10k_webhook --servers_file <path_to_servers.json>

Configuration

Create ‘/etc/r10k_webhook/config.json’ and put there parameters.

  • host default: ‘0.0.0.0’ - Ip-address or hostname, on which http-server listening.

  • port default: 8088 - Port, on which http-server listening.

  • branch_to_env_map default: {} - Map of name of branch in VCS and associated name of puppet environment. It may be regexp. E.g. ‘^env_(.*)$’: ‘\g<1>’ removes prefix env_ from all branches having it.

  • allowed_branches default: ‘.*’ - Regexp by which name of a branch is filtered. A branch will be deployed if matches regexp.

  • flush_env_cache default: true - Determines whether send command flushing an environment’s cache via puppet api after r10k run.

  • generate_types default: true - Determines whether launch command ‘puppet generate types <env>’ after r10k run.

  • initial_deployment default: true - Deployment all environments on start.

  • override_environment_directories default: false - Removes existent directory of environment before deployment.

  • r10k_path: default: ‘r10k’ - Path to r10k binary

  • puppet_path: default: ‘/opt/puppetlabs/bin/puppet’ - Path to puppet binary

  • r10k_tmpcfg: default: ‘/tmp/r10k.yaml’ - Path to modified configuration yaml file of r10k being created and used by wrapper.

  • r10k_args: default: ‘-v’ - String with arguments are passed to r10k at every execution. Spaces are not allowed there.

  • r10k_config_path: default: ‘/etc/puppetlabs/r10k/r10k.yaml’ - Path to configuration yaml file of r10k.

  • puppet_api_uri default: ‘https://localhost:8140/puppet-admin-api/v1’ - URI is called to flush cache of an environment.

Service r10k-webhook has to be restarted in order to apply changes of config:

systemctl restart r10k-webhook

Example of configuration file.

{
  "flush_env_cache": false,
  "branch_to_env_map": {
    "master": "production",
    "^env_(.*)$": "\g<1>"
  },
  "allowed_branches": "^(env_[\w]+|master)$"
}

Example of configuration file of r10k.

:cachedir: /opt/puppetlabs/puppet/cache/r10k
:sources:
  puppet:
    basedir: /etc/puppetlabs/code/environments
    invalid_branches: error
    remote: git@git.example.net:puppet

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

r10k-webhook-0.1.1.tar.gz (10.1 kB view details)

Uploaded Source

File details

Details for the file r10k-webhook-0.1.1.tar.gz.

File metadata

  • Download URL: r10k-webhook-0.1.1.tar.gz
  • Upload date:
  • Size: 10.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3

File hashes

Hashes for r10k-webhook-0.1.1.tar.gz
Algorithm Hash digest
SHA256 860465c10169b97a2667ea4ea398cdb81dd37f0174bf2f0a4a17b9e19136e09b
MD5 375d7b2bf4b7a25e7053ffd3ef1ddb50
BLAKE2b-256 b893d5fb9afed5ce8818ea986037daea3c7fa8ca00304b92172ca0eb04756db6

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page