Created
July 8, 2012 12:33
-
-
Save abhishekkr/3070758 to your computer and use it in GitHub Desktop.
Puppet Module ~ Code Sample Describing usage of manifests, templates, files, lib, specs, tests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http://justfewtuts.blogspot.com/2012/07/puppet-beginners-concept-guide-part-2.html | |
<tomcat-module>/manifests/install.pp | |
class <tomcat-module>::install { | |
package { 'tomcat6': ensure => 'installed', } | |
} | |
<tomcat-module>/manifests/configure.pp | |
class <tomcat-module>::configure { | |
<tomcat-module>::configure::war { | |
['web']: | |
require => Package['tomcat6'], | |
} | |
} | |
<tomcat-module>/manifests/configure/war.pp | |
class <tomcat-module>::configure::war { | |
file { | |
"/var/lib/tomcat6/webapps/${name}.war": | |
content => template('<tomcat-module>/war_app.conf.erb'), | |
owner => tomcat, | |
group => tomcat, | |
mode => '0644', | |
} | |
file { | |
"/etc/${name}.conf": | |
content => template('<tomcat-module>/war_app.conf.erb'), | |
owner => tomcat, | |
group => tomcat, | |
mode => '0644', | |
require => File["/var/lib/tomcat6/webapps/${name}.war"], | |
notify => Service['tomcat6'], | |
} | |
} | |
'<tomcat-module>/templates/war_app.conf.erb' | |
com.<%= name %>.adept.serviceURL=http://<%= fqdn %>:8080/<%= name %> | |
com.<%= name %>.adept.log.file=/var/log/tomcat6/<%= name %>.log | |
com.<%= name %>.adept.persist.sql.driverClass=com.mysql.jdbc.Driver | |
com.<%= name %>.adept.persist.sql.connection=jdbc:mysql://127.0.0.1:3306/adept | |
com.<%= name %>.adept.persist.sql.dialect=mysql | |
com.<%= name %>.adept.persist.sql.user=<%= mysql_user%> | |
com.<%= name %>.adept.persist.sql.password=<%= mysql_password%> | |
'<tomcat-module>/files/web.war' | |
~ the war-packaged file for web-application | |
'<tomcat-module>/lib/facter/database.rb' | |
require 'facter' | |
require 'yaml' | |
facts_file = '/etc/puppet/myfacts.yaml' | |
facts = {} | |
facts.merge YAML.load_file(facts_file) if File.exist? facts_file | |
Facter.add("mysql_user") do | |
setcode do | |
return 'mysql-password' if facts['mysql'].nil? || facts['mysql']['user'].nil? | |
facts['mysql']['user'] | |
end | |
end | |
Facter.add("mysql_password") do | |
setcode do | |
return 'mysql-password' if facts['mysql'].nil? || facts['mysql']['password'].nil? | |
facts['mysql']['password'] | |
end | |
end | |
'<tomcat-module>/spec/classes/<tomcat-module>/install_spec.pp' | |
require 'spec_helper' | |
describe 'tomcat::install' do | |
it do | |
should contain_package('tomcat6').with_ensure('latest') | |
end | |
end | |
'<tomcat-module>/tests/' | |
node just-tomcat6 { | |
include <tomcat-module>::install | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
not actually a Ruby script but marked as one to get the color scheme for Ruby DSL snippets