Skip to content

Instantly share code, notes, and snippets.

@nadavoid
Created December 19, 2011 18:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nadavoid/1498207 to your computer and use it in GitHub Desktop.
Save nadavoid/1498207 to your computer and use it in GitHub Desktop.
Puppet Conditional in Template
---
parameters:
server_tags: "role:all=true,role:dev=true"
# filename ends with .rb, not .pp.
# see http://docs.puppetlabs.com/guides/custom_facts.html
# see http://www.scribd.com/doc/56291200/63/Puppet-Using-Facter-and-Templates
# see Pro Puppet, chapter 10 "Extending Facter and Puppet"
Facter.add("some_custom_fact") do
setcode do
'Some custom data piece. Possibly an IP address.'
end
end
# To call the `has_role` function, you must prefix it with `function_`,
# and send it to the `scope` object.
# So, `has_role('foo')` becomes `scope.function_has_role('foo')`.
# `has_role` is a function added by the truth module.
<% if scope.function_has_role('dev') %>
# facts, including those set by ENCs, are available.
# some_custom_fact is a custom fact created by a custom module.
allow <%= some_custom_fact %>;
<% end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment