Fun With Raw Constructors


The Basics

Each Raw Constructor class follows a similar pattern and accepts a pair of Hashes as parameters.

  • The first Hash is for specifying the list of resources you want to create.
  • The second Hash provides a series of default values to each resource in the first Hash.

Read that again. The first Hash is a list; the second augments the list.

The Hashes can be composed in any order. Here we specify the defaults hash first...

Example:

---
# The defaults Hash
managedmac::execs::defaults:
  path: /bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
# The resource list Hash
managedmac::execs::commands:
  file_a:
    command: 'touch /tmp/file_a'
  file_b:
    command: 'touch /tmp/file_b'
  file_c:
    command: 'touch /tmp/file_c'

The YAML above defines 3 unique Puppet Exec resources, composed of two Hashes:

  • managedmac::execs::defaults
  • managedmac::execs::commands

The first Hash has one key, path, whose value is a String.

The second Hash has three keys, each in the form of:

resource_name:
  command: 'some_command'

The thing to understand here is that each of the Hashes in the managedmac::execs::commands inherit the path key from the managedmac::execs::defaults Hash.

So, in the end, the defaults Hash is simply a way of refactoring. Consider this equivalent example:

---
# The resource list Hash
managedmac::execs::commands:
  file_a:
    path: /bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
    command: 'touch /tmp/file_a'
  file_b:
    path: /bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
    command: 'touch /tmp/file_b'
  file_c:
    path: /bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
    command: 'touch /tmp/file_c'

This is a contrived example, but any parameters you can pass to a Puppet Exec resource, can be specified in the Hiera data. Here is a more detailed example:

---
# Dump the process table to a file
managedmac::execs::commands:
  dump_proc_table:
    path: /bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
    creates: '/tmp/proc_table.txt'
    command: 'ps aux > /tmp/proc_table.txt'
    returns: 0
    logoutput: on_failure

About

This module was designed as part of the Managed Mac project at Simon Fraser University.

Released under the Apache License.


Requirements

  • OS X 10.9 or greater
  • Puppet 3.x
  • puppetlabs-stdlib module
  • CFPropertyList gem
  • sqlite3 gem

Bug Reports

Please file bug reports using the Github Issue Tracker


Acknowledgments

The authors would like to thank the following folks for their invaluable contributions:

  • Gary Larizza
  • Christian Kruse
  • The generous operators and regulars on #puppet-dev
  • SFU ITS Mac Dev Team
    • Geoff Brown
    • Jeff Bryer
    • Grant Dimock
    • Brian Langdeau
    • James Peltier
    • Riley Shott
    • Brian Warsing