Enforcing State with Puppetlets

How to use small, idempotent, self-contained executable puppet scripts to enforce state, rather than a full solution.

Update: I tweaked the pup script to use exec rather than just running puppet apply, replacing the current process rather than forking another. It’s better to use "$@" than $* so quoted arguments are preserved (cheers to lamby for pointing these out)

You can make nearly any file executable by using a shebang or hash-bang at the top of the file - e.g. #!/usr/bin/env ruby. This tells the shell in which the script is being executed to run the contents of the file with the shebang command - in this example, /usr/bin/ruby some_file.rb.

So the shell (in my case zsh) is interpreting that we want to run puppet ./test.pp, and puppet needs to take an additional argument to tell it to run agentless. Here’s the snag: the shebang parsing only cares about the first command as an argument (and after that only short-form flags).

You can get around that with a custom wrapper that runs puppet apply - let’s call it pup - in your path.