TODO: Add error checking and possibly tests.
put this script in your puppet module under:
$your_module/lib/puppet/parser/exists.rb
You can use this to determine if a file exsists on the puppet master. This is extreamly useful if you need to access templates or files from a hierarchy.
i.e. $your_module/templates/domains/domain1.com/database.yml
vs.
$your_module/templates/domains/domain2.com/database.yml
Here is an example of how you would call it in a manifest file.
if exists("/etc/puppet/environments/${environment}/modules/$your_module/templates/${domain}/${environment}/database.yml"){
file { "database.yml":
path => "/data/${application}/shared/config/database.yml",
owner => 'deploy',
group => 'deploy',
content => template("$your_module/${domain}/${environment}/database.yml"),
}
}
Here, you can see that the file method will only be called if the template exists. Otherwise it will ignore the template.
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request :D