Skip to content

Instantly share code, notes, and snippets.

View TJM's full-sized avatar

Tommy McNeely TJM

View GitHub Profile
@TJM
TJM / dash.wsgi
Last active October 23, 2018 14:00
WSGI file for a Dash / Plotly app with no hard coded paths. Picks up the "prefix" for DASH through the WSGI environment variable SCRIPT_NAME and uses the virtualenv "venv"
import os
import sys
my_directory=os.path.dirname(__file__)
if my_directory not in sys.path:
sys.path.insert(0,my_directory)
# Virtual Environment (./venv)
activate_this = os.path.join(my_directory, 'venv', 'bin', 'activate_this.py')
@TJM
TJM / Jenkinsfile
Last active October 25, 2018 20:23
First (workable) attempt at using Pipeline for Puppet control-repo code testing and deployment - Uses the Mesos plugin to spin up slaves as "cloud1" and the Puppet Enterprise plugin for deployment https://wiki.jenkins.io/display/JENKINS/Puppet+Enterprise+Pipeline+Plugin
#!/usr/bin/env groovy
// NOTE:
// * This is designed to work as a Multi-Branch PIPELINE buid.
// * Our Jenkins Slave is mesos and labeled "cloud1" (you may need to adjust)
// * This uses the Puppet Enterprise Jenkins plugin. It assumes that is setup
// * Also there needs to be a credential (API KEY) with the id of "puppet"
pipeline {
//agent { label 'cloud1' }
@TJM
TJM / nginxplus.pp
Created December 10, 2018 17:22
Puppet Profile for nginxplus
# == Class: profile::nginxplus
#
class profile::nginxplus (
Optional[String] $repo_cert = undef,
Optional[String] $repo_key = undef,
Boolean $manage_repo = true,
Boolean $enable_dashboard = true,
Boolean $dashboard_readonly = true,
Integer $dashboard_port = 8080,
) {
@TJM
TJM / artifactory-forge-for-puppet-enterprise.md
Last active December 14, 2018 16:04
Setup Puppet Enterprise Code Manager to use Artifactory as Puppet Forge

Setup Puppet Enterprise Code Manager to use Artifactory as Puppet Forge

Setup Artifactory

Actually installing Artifactory is outside the scope of this document. It is assumed that your have artifactory PRO or greater already running.

Here are the steps from their documentation on setting up the Puppet Repo: https://www.jfrog.com/confluence/display/RTF/Puppet+Repositories

In the additional files below, you will find a common.yaml and pe.conf fragment.

@TJM
TJM / A-ExtractPuppetEnvironmentsAndRolesForMorpheus.md
Last active December 14, 2018 16:23
Extract roles from puppet for Morpheus OptionList

Extract Puppet Environments and Roles for Morpheus

See inside for javascript to "translate" the output of Puppet API queries to name/value list for Morpheus.

Puppet Enterprise Setup

  • Generate a certificate on the Puppet Master (CA) for morpheus
    • puppet cert generate morhpeus-api
  • Grant Access to the environment_classes API
  • Add mod 'puppetlabs-puppet_authorization', '0.5.0' to Puppetfile (if its not already there)
@TJM
TJM / run_puppet.sh
Created April 26, 2019 19:18
Run puppet during provisioning - puppet exit code > 1 on changes caused provisioning system to think it had failed
#!/bin/bash
for (( i=0; i<5; i++ )); do
echo "Running Puppet Agent..."
/opt/puppetlabs/puppet/bin/puppet agent -t
rc=$?
if [ $rc = 0 ]; then
echo " *** SUCCESS!"
exit 0
elif [ $rc = 1 ]; then
>&2 echo " *** ERROR!"
@TJM
TJM / site.pp
Created April 27, 2019 22:40
control-repo/manifests/site.pp to select based on pp_role or role fact.
## site.pp ##
# This file (/etc/puppetlabs/puppet/manifests/site.pp) is the main entry point
# used when an agent connects to a master and asks for an updated configuration.
#
# Global objects like filebuckets and resource defaults should go in this file,
# as should the default node definition. (The default node can be omitted
# if you use the console and don't define any other nodes in site.pp. See
# http://docs.puppetlabs.com/guides/language_guide.html#nodes for more on
# node definitions.)
@TJM
TJM / app_hosts.sh
Created June 5, 2019 23:03
Morpheus parse application instance
echo '<%=instance.apps.first().instances.collect{it.name}%>'
node_hosts_363=(<%= instance.apps.first().instances.findAll{it.metadata.application_component == 'node'}.collect{ it.containers.collect{ it.hostname + '.' + it.domainName } }.flatten().join(' ') %>)
echo "Node 3.6.3: ${node_hosts_363}"
node_hosts=(<%= instance.apps.first().instances.findAll{it.metadata.application_component == 'node'}.collect{ it.hostname + '.DOMAIN.corp' }.flatten().join(' ') %>)
dmgr_hosts=(<%= instance.apps.first().instances.findAll{it.metadata.application_component == 'dmgr'}.collect{ it.hostname + '.DOMAIN.corp' }.flatten().join(' ') %>)
@TJM
TJM / .sync.yml
Created July 2, 2019 18:15
Puppet PDK .sync.yml for our control-repo
---
.gitignore:
paths:
- /modules
- .vagrant
- vagrant/*/environments/production/*
- vagrant/*/spec/fixtures/modules/*
- .DS_Store
- .DS_Store?
@TJM
TJM / average_compile_time.sh
Last active August 5, 2019 22:14
Average Puppet Catalog compile time
awk '/Compiled static catalog for/ { x=$(NF-1); sum+=x; total++ }; END { print "Average Compile Time: " sum / total }' /var/log/puppetlabs/puppetserver/puppetserver.log