Package: r10k-webhook
OverviewIt’s the API tor10k 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.FeaturesAllowsmapping of git branches to puppet environmentsusing regex. E.g. branch ‘master’ may be mapped to puppet environment ‘production’.Acceptsregex pattern by which name of branch is filtered. A branch will be deployed only if matches regex.Runs onlyone 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 forenvironment isolation.Sends commandflushing cachefor an environment to api of puppet server after r10k has finished.Depends on only one third-party package - pyaml.Getting startedInstallation at puppet server.Firstly, install and setr10k utilityto your repository. Ensure that following command works.r10kdeployenvironment<env_name>-venv_namehas to be name of one of existent branches in your repo.If you don’t have errors, proceed with installation of r10k-webhook.pip3installr10k-webhooksystemctldaemon-reloadEnable and start service.systemctlenabler10k-webhooksystemctlstartr10k-webhookCheck logs and status.journalctl-xeur10k-webhookcurllocalhost:8088/statusIf daemon doesn’t start, go on withConfiguration.Installation at VCS.Install the package to server with your repository of puppet code.pip3installr10k-webhookTrigger your puppet server with <env_name>.r10k_webhook-s<puppetserver.hostname>-b<env_name>Take <puppetserver.hostname> and <env_name> as you used atInstallation at puppet server.You should see following output:Deployedthebranchto1serversoutof1.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 bashr10k_webhook--servers_file<path_to_servers.json>ConfigurationCreate ‘/etc/r10k_webhook/config.json’ and put there parameters.hostdefault: ‘0.0.0.0’- Ip-address or hostname, on which http-server listening.portdefault: 8088- Port, on which http-server listening.branch_to_env_mapdefault: {}- Map of name of branch in VCS and associated name of puppet environment. It may be regexp. E.g. ‘^env_(.*)$’: ‘\g<1>’ removes prefixenv_from all branches having it.allowed_branchesdefault: ‘.*’- Regexp by which name of a branch is filtered. A branch will be deployed if matches regexp.flush_env_cachedefault: true- Determines whether send command flushing an environment’s cache via puppet api after r10k run.generate_typesdefault: true- Determines whether launch command ‘puppet generate types <env>’ after r10k run.initial_deploymentdefault: true- Deployment all environments on start.override_environment_directoriesdefault: false- Removes existent directory of environment before deployment.r10k_path:default: ‘r10k’- Path to r10k binarypuppet_path:default: ‘/opt/puppetlabs/bin/puppet’- Path to puppet binaryr10k_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_uridefault: ‘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-webhookExample 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/environmentsinvalid_branches:errorremote:git@git.example.net:puppet