Skip to content

Instantly share code, notes, and snippets.

View abrader's full-sized avatar

Andrew Brader abrader

  • Portland, OR 97209
View GitHub Profile
require 'beaker-rspec'
require 'beaker-pe'
require 'beaker/puppet_install_helper'
def wait_for_master(max_retries)
1.upto(max_retries) do |retries|
on(master, "curl -skIL https://#{master.hostname}:8140", acceptable_exit_codes: [0, 1, 7]) do |result|
return if result.stdout =~ /400 Bad Request/
counter = 2 ** retries
@abrader
abrader / ec2.yaml
Last active July 27, 2017 20:51
Beaker: ec2.yaml
AMI:
"debian-wheezy":
:image:
:ebs_pv: "ami-c481ecf4"
:region: "us-west-2"
"amzn-201409":
:image:
:ebs_pv: "ami-55a7ea65"
:instance_pv: "ami-5ba7ea6b"
:region: "us-west-2"
@abrader
abrader / default.yml
Last active August 15, 2017 21:49
spec/acceptance/nodesets/default.yml
# Requires that ~/.fog have aws_access_key_id and aws_secret_access_key
HOSTS:
"puppet":
roles:
- master
- default
- database
- dashboard
- agent
vmname: "centos-7-x86-64-west"
@abrader
abrader / parameters.md
Created June 21, 2017 17:59
Parameters

Parameters

Parameters are defined essentially exactly the same as properties; the only difference between them is that parameters never result in methods being called on providers.

To define a new parameter, call the newparam method. This method takes the name of the parameter (as a symbol) as its argument, as well as a block of code. You can and should provide documentation for each parameter by calling the desc method inside its block. Leading whitespace is trimmed from multiline strings as described above.

    newparam(:name) do
      desc "The name of the database."
    end
@abrader
abrader / properties.md
Last active June 21, 2017 17:54
Properties

Properties

Here’s where we define how the resource really works. In most cases, it’s the properties that interact with your resource’s providers. If you define a property named owner, then when you are retrieving the state of your resource, then the owner property will call the owner method on the provider. In turn, when you are setting the state (because the resource is out of sync), then the owner property will call the owner= method to set the state on disk.

There’s one common exception to this: The ensure property is special because it’s used to create and destroy resources. You can set this property up on your resource type just by calling the ensurable method in your type definition:

    Puppet::Type.newtype(:database) do
      ensurable
      ...
 end
@abrader
abrader / single_namevar.md
Last active June 21, 2017 17:50
Single namevar

Single Namevar

Every type must have at least one mandatory parameter: the namevar. This parameter will uniquely identify each resource of the type on the target system — for example, the path of a file on disk, the name of a user account, or the name of a package. If the user doesn’t specify a value for the namevar when declaring a resource, its value will default to the title of the resource. There are three ways to designate a namevar. Every type must have exactly one parameter that meets exactly one of these criteria:

Option 1: Create a parameter whose name is :name. Since most types just use :name as the namevar, it gets special treatment and will automatically become the namevar.

    newparam(:name) do
      desc "The name of the database."
    end
@abrader
abrader / puppet_pipeline_branches.md
Last active June 16, 2017 00:13
Puppet: Pipeline - Issue Branches

Puppet: Issue branches managed by pipeline

  • Ticket
    • Post creation branch creation
      • Webhook: Trigger GitLabCI Pipeline from JIRA
      • GitLabCI -> GitLab REST call: Create branch
        • HEADER: PRIVATE-TOKEN: <MAGIC>
        • URL: https://puppet-gitlab-test-elb-1536216415.us-west-2.elb.amazonaws.com/api/v4/projects/1/repository/branches?branch=<NEW_BRANCH>&ref=<REFERENCE_BRANCH
  • Refactor code
    • Intra-process
  • Code refactored - Issue remediation complete
@abrader
abrader / tp_defining.md
Last active May 24, 2017 16:33
Type & Providers: Defining

Declaration

Providers are always associated with a single resource type, so they are created by calling the provide method on that resource type. The provide method takes three arguments plus a block:

  • The first argument must be the name of the provider, as a :symbol.
  • The optional :parent argument should be the name of a parent class.
  • The optional :source argument should be a symbol.
  • The block takes no arguments, and implements the behavior of the provider.

Parent Classes