diff --git a/PuppetResources/ClassRoomExamples/apache_ex/Gemfile b/PuppetResources/ClassRoomExamples/apache_ex/Gemfile new file mode 100644 index 0000000..4f662dc --- /dev/null +++ b/PuppetResources/ClassRoomExamples/apache_ex/Gemfile @@ -0,0 +1,18 @@ +source ENV['GEM_SOURCE'] || 'https://rubygems.org' + +puppetversion = ENV.key?('PUPPET_VERSION') ? ENV['PUPPET_VERSION'] : ['>= 3.3'] +gem 'metadata-json-lint' +gem 'puppet', puppetversion +gem 'puppetlabs_spec_helper', '>= 1.0.0' +gem 'puppet-lint', '>= 1.0.0' +gem 'facter', '>= 1.7.0' +gem 'rspec-puppet' + +# rspec must be v2 for ruby 1.8.7 +if RUBY_VERSION >= '1.8.7' && RUBY_VERSION < '1.9' + gem 'rspec', '~> 2.0' + gem 'rake', '~> 10.0' +else + # rubocop requires ruby >= 1.9 + gem 'rubocop' +end diff --git a/PuppetResources/ClassRoomExamples/apache_ex/README.md b/PuppetResources/ClassRoomExamples/apache_ex/README.md new file mode 100644 index 0000000..07c10e4 --- /dev/null +++ b/PuppetResources/ClassRoomExamples/apache_ex/README.md @@ -0,0 +1,83 @@ +# apache_ex + +#### Table of Contents + +1. [Description](#description) +1. [Setup - The basics of getting started with apache_ex](#setup) + * [What apache_ex affects](#what-apache_ex-affects) + * [Setup requirements](#setup-requirements) + * [Beginning with apache_ex](#beginning-with-apache_ex) +1. [Usage - Configuration options and additional functionality](#usage) +1. [Reference - An under-the-hood peek at what the module is doing and how](#reference) +1. [Limitations - OS compatibility, etc.](#limitations) +1. [Development - Guide for contributing to the module](#development) + +## Description + +Start with a one- or two-sentence summary of what the module does and/or what +problem it solves. This is your 30-second elevator pitch for your module. +Consider including OS/Puppet version it works with. + +You can give more descriptive information in a second paragraph. This paragraph +should answer the questions: "What does this module *do*?" and "Why would I use +it?" If your module has a range of functionality (installation, configuration, +management, etc.), this is the time to mention it. + +## Setup + +### What apache_ex affects **OPTIONAL** + +If it's obvious what your module touches, you can skip this section. For +example, folks can probably figure out that your mysql_instance module affects +their MySQL instances. + +If there's more that they should know about, though, this is the place to mention: + +* A list of files, packages, services, or operations that the module will alter, + impact, or execute. +* Dependencies that your module automatically installs. +* Warnings or other important notices. + +### Setup Requirements **OPTIONAL** + +If your module requires anything extra before setting up (pluginsync enabled, +etc.), mention it here. + +If your most recent release breaks compatibility or requires particular steps +for upgrading, you might want to include an additional "Upgrading" section +here. + +### Beginning with apache_ex + +The very basic steps needed for a user to get the module up and running. This +can include setup steps, if necessary, or it can be an example of the most +basic use of the module. + +## Usage + +This section is where you describe how to customize, configure, and do the +fancy stuff with your module here. It's especially helpful if you include usage +examples and code samples for doing things with your module. + +## Reference + +Here, include a complete list of your module's classes, types, providers, +facts, along with the parameters for each. Users refer to this section (thus +the name "Reference") to find specific details; most users don't read it per +se. + +## Limitations + +This is where you list OS compatibility, version compatibility, etc. If there +are Known Issues, you might want to include them under their own heading here. + +## Development + +Since your module is awesome, other users will want to play with it. Let them +know what the ground rules for contributing are. + +## Release Notes/Contributors/Etc. **Optional** + +If you aren't using changelog, put your release notes here (though you should +consider using changelog). You can also add any additional sections you feel +are necessary or important to include here. Please use the `## ` header. diff --git a/PuppetResources/ClassRoomExamples/apache_ex/Rakefile b/PuppetResources/ClassRoomExamples/apache_ex/Rakefile new file mode 100644 index 0000000..02609e3 --- /dev/null +++ b/PuppetResources/ClassRoomExamples/apache_ex/Rakefile @@ -0,0 +1,32 @@ +require 'puppetlabs_spec_helper/rake_tasks' +require 'puppet-lint/tasks/puppet-lint' +require 'metadata-json-lint/rake_task' + +if RUBY_VERSION >= '1.9' + require 'rubocop/rake_task' + RuboCop::RakeTask.new +end + +PuppetLint.configuration.send('disable_80chars') +PuppetLint.configuration.relative = true +PuppetLint.configuration.ignore_paths = ['spec/**/*.pp', 'pkg/**/*.pp'] + +desc 'Validate manifests, templates, and ruby files' +task :validate do + Dir['manifests/**/*.pp'].each do |manifest| + sh "puppet parser validate --noop #{manifest}" + end + Dir['spec/**/*.rb', 'lib/**/*.rb'].each do |ruby_file| + sh "ruby -c #{ruby_file}" unless ruby_file =~ %r{spec/fixtures} + end + Dir['templates/**/*.erb'].each do |template| + sh "erb -P -x -T '-' #{template} | ruby -c" + end +end + +desc 'Run metadata_lint, lint, validate, and spec tests.' +task :test do + [:metadata_lint, :lint, :validate, :spec].each do |test| + Rake::Task[test].invoke + end +end diff --git a/PuppetResources/ClassRoomExamples/apache_ex/examples/init.pp b/PuppetResources/ClassRoomExamples/apache_ex/examples/init.pp new file mode 100644 index 0000000..115ded0 --- /dev/null +++ b/PuppetResources/ClassRoomExamples/apache_ex/examples/init.pp @@ -0,0 +1,12 @@ +# The baseline for module testing used by Puppet Labs is that each manifest +# should have a corresponding test manifest that declares that class or defined +# type. +# +# Tests are then run by using puppet apply --noop (to check for compilation +# errors and view a log of events) or by fully applying the test in a virtual +# environment (to compare the resulting system state to the desired state). +# +# Learn more about module testing here: +# https://docs.puppet.com/guides/tests_smoke.html +# +include ::apache_ex diff --git a/PuppetResources/ClassRoomExamples/apache_ex/manifests/init.pp b/PuppetResources/ClassRoomExamples/apache_ex/manifests/init.pp new file mode 100644 index 0000000..b6a5d03 --- /dev/null +++ b/PuppetResources/ClassRoomExamples/apache_ex/manifests/init.pp @@ -0,0 +1,53 @@ +# Class: apache_ex +# =========================== +# +# Full description of class apache_ex here. +# +# Parameters +# ---------- +# +# Document parameters here. +# +# * `sample parameter` +# Explanation of what this parameter affects and what it defaults to. +# e.g. "Specify one or more upstream ntp servers as an array." +# +# Variables +# ---------- +# +# Here you should define a list of variables that this module would require. +# +# * `sample variable` +# Explanation of how this variable affects the function of this class and if +# it has a default. e.g. "The parameter enc_ntp_servers must be set by the +# External Node Classifier as a comma separated list of hostnames." (Note, +# global variables should be avoided in favor of class parameters as +# of Puppet 2.6.) +# +# Examples +# -------- +# +# @example +# class { 'apache_ex': +# servers => [ 'pool.ntp.org', 'ntp.local.company.com' ], +# } +# +# Authors +# ------- +# +# Author Name +# +# Copyright +# --------- +# +# Copyright 2017 Your name here, unless otherwise noted. +# +class apache_ex { + + # install configured package + include apache_ex::install + + #enable and start the service + include apache_ex::service + +} diff --git a/PuppetResources/ClassRoomExamples/apache_ex/manifests/install.pp b/PuppetResources/ClassRoomExamples/apache_ex/manifests/install.pp new file mode 100644 index 0000000..979da65 --- /dev/null +++ b/PuppetResources/ClassRoomExamples/apache_ex/manifests/install.pp @@ -0,0 +1,10 @@ +class apache_ex::install ($package_name = 'httpd') { + package { $package_name: + ensure => installed, + } + + $apache_install_message=hiera('apache_ex::install_message') + + notify { $apache_install_message: } + +} \ No newline at end of file diff --git a/PuppetResources/ClassRoomExamples/apache_ex/manifests/service.pp b/PuppetResources/ClassRoomExamples/apache_ex/manifests/service.pp new file mode 100644 index 0000000..4b2b332 --- /dev/null +++ b/PuppetResources/ClassRoomExamples/apache_ex/manifests/service.pp @@ -0,0 +1,14 @@ +class apache_ex::service($service_name='httpd'){ + + service { $service_name: + ensure => running, + enable => true, + hasrestart => true, + hasstatus => true, + # pattern => $service_name, + } + + $service_message = hiera('apache_ex::service_message') + notify { $service_message: } + +} \ No newline at end of file diff --git a/PuppetResources/ClassRoomExamples/apache_ex/metadata.json b/PuppetResources/ClassRoomExamples/apache_ex/metadata.json new file mode 100644 index 0000000..524f2fc --- /dev/null +++ b/PuppetResources/ClassRoomExamples/apache_ex/metadata.json @@ -0,0 +1,15 @@ +{ + "name": "asquarezone/apache_ex", + "version": "0.1.0", + "author": "asquarezone", + "summary": "apache class room example", + "license": "Apache-2.0", + "source": "https://github.com/asquarezone/PuppetZone.git", + "project_page": "https://github.com/asquarezone/PuppetZone", + "issues_url": "https://github.com/asquarezone/PuppetZone/issues", + "dependencies": [ + {"name":"puppetlabs-stdlib","version_requirement":">= 1.0.0"} + ], + "data_provider": null +} + diff --git a/PuppetResources/ClassRoomExamples/apache_ex/spec/classes/init_spec.rb b/PuppetResources/ClassRoomExamples/apache_ex/spec/classes/init_spec.rb new file mode 100644 index 0000000..bdd2035 --- /dev/null +++ b/PuppetResources/ClassRoomExamples/apache_ex/spec/classes/init_spec.rb @@ -0,0 +1,6 @@ +require 'spec_helper' +describe 'apache_ex' do + context 'with default values for all parameters' do + it { should contain_class('apache_ex') } + end +end diff --git a/PuppetResources/ClassRoomExamples/apache_ex/spec/spec_helper.rb b/PuppetResources/ClassRoomExamples/apache_ex/spec/spec_helper.rb new file mode 100644 index 0000000..2c6f566 --- /dev/null +++ b/PuppetResources/ClassRoomExamples/apache_ex/spec/spec_helper.rb @@ -0,0 +1 @@ +require 'puppetlabs_spec_helper/module_spec_helper' diff --git a/PuppetResources/ClassRoomExamples/appserver_tomcat/Gemfile b/PuppetResources/ClassRoomExamples/appserver_tomcat/Gemfile new file mode 100644 index 0000000..4f662dc --- /dev/null +++ b/PuppetResources/ClassRoomExamples/appserver_tomcat/Gemfile @@ -0,0 +1,18 @@ +source ENV['GEM_SOURCE'] || 'https://rubygems.org' + +puppetversion = ENV.key?('PUPPET_VERSION') ? ENV['PUPPET_VERSION'] : ['>= 3.3'] +gem 'metadata-json-lint' +gem 'puppet', puppetversion +gem 'puppetlabs_spec_helper', '>= 1.0.0' +gem 'puppet-lint', '>= 1.0.0' +gem 'facter', '>= 1.7.0' +gem 'rspec-puppet' + +# rspec must be v2 for ruby 1.8.7 +if RUBY_VERSION >= '1.8.7' && RUBY_VERSION < '1.9' + gem 'rspec', '~> 2.0' + gem 'rake', '~> 10.0' +else + # rubocop requires ruby >= 1.9 + gem 'rubocop' +end diff --git a/PuppetResources/ClassRoomExamples/appserver_tomcat/README.md b/PuppetResources/ClassRoomExamples/appserver_tomcat/README.md new file mode 100644 index 0000000..e4593d2 --- /dev/null +++ b/PuppetResources/ClassRoomExamples/appserver_tomcat/README.md @@ -0,0 +1,83 @@ +# appserver_tomcat + +#### Table of Contents + +1. [Description](#description) +1. [Setup - The basics of getting started with appserver_tomcat](#setup) + * [What appserver_tomcat affects](#what-appserver_tomcat-affects) + * [Setup requirements](#setup-requirements) + * [Beginning with appserver_tomcat](#beginning-with-appserver_tomcat) +1. [Usage - Configuration options and additional functionality](#usage) +1. [Reference - An under-the-hood peek at what the module is doing and how](#reference) +1. [Limitations - OS compatibility, etc.](#limitations) +1. [Development - Guide for contributing to the module](#development) + +## Description + +Start with a one- or two-sentence summary of what the module does and/or what +problem it solves. This is your 30-second elevator pitch for your module. +Consider including OS/Puppet version it works with. + +You can give more descriptive information in a second paragraph. This paragraph +should answer the questions: "What does this module *do*?" and "Why would I use +it?" If your module has a range of functionality (installation, configuration, +management, etc.), this is the time to mention it. + +## Setup + +### What appserver_tomcat affects **OPTIONAL** + +If it's obvious what your module touches, you can skip this section. For +example, folks can probably figure out that your mysql_instance module affects +their MySQL instances. + +If there's more that they should know about, though, this is the place to mention: + +* A list of files, packages, services, or operations that the module will alter, + impact, or execute. +* Dependencies that your module automatically installs. +* Warnings or other important notices. + +### Setup Requirements **OPTIONAL** + +If your module requires anything extra before setting up (pluginsync enabled, +etc.), mention it here. + +If your most recent release breaks compatibility or requires particular steps +for upgrading, you might want to include an additional "Upgrading" section +here. + +### Beginning with appserver_tomcat + +The very basic steps needed for a user to get the module up and running. This +can include setup steps, if necessary, or it can be an example of the most +basic use of the module. + +## Usage + +This section is where you describe how to customize, configure, and do the +fancy stuff with your module here. It's especially helpful if you include usage +examples and code samples for doing things with your module. + +## Reference + +Here, include a complete list of your module's classes, types, providers, +facts, along with the parameters for each. Users refer to this section (thus +the name "Reference") to find specific details; most users don't read it per +se. + +## Limitations + +This is where you list OS compatibility, version compatibility, etc. If there +are Known Issues, you might want to include them under their own heading here. + +## Development + +Since your module is awesome, other users will want to play with it. Let them +know what the ground rules for contributing are. + +## Release Notes/Contributors/Etc. **Optional** + +If you aren't using changelog, put your release notes here (though you should +consider using changelog). You can also add any additional sections you feel +are necessary or important to include here. Please use the `## ` header. diff --git a/PuppetResources/ClassRoomExamples/appserver_tomcat/Rakefile b/PuppetResources/ClassRoomExamples/appserver_tomcat/Rakefile new file mode 100644 index 0000000..02609e3 --- /dev/null +++ b/PuppetResources/ClassRoomExamples/appserver_tomcat/Rakefile @@ -0,0 +1,32 @@ +require 'puppetlabs_spec_helper/rake_tasks' +require 'puppet-lint/tasks/puppet-lint' +require 'metadata-json-lint/rake_task' + +if RUBY_VERSION >= '1.9' + require 'rubocop/rake_task' + RuboCop::RakeTask.new +end + +PuppetLint.configuration.send('disable_80chars') +PuppetLint.configuration.relative = true +PuppetLint.configuration.ignore_paths = ['spec/**/*.pp', 'pkg/**/*.pp'] + +desc 'Validate manifests, templates, and ruby files' +task :validate do + Dir['manifests/**/*.pp'].each do |manifest| + sh "puppet parser validate --noop #{manifest}" + end + Dir['spec/**/*.rb', 'lib/**/*.rb'].each do |ruby_file| + sh "ruby -c #{ruby_file}" unless ruby_file =~ %r{spec/fixtures} + end + Dir['templates/**/*.erb'].each do |template| + sh "erb -P -x -T '-' #{template} | ruby -c" + end +end + +desc 'Run metadata_lint, lint, validate, and spec tests.' +task :test do + [:metadata_lint, :lint, :validate, :spec].each do |test| + Rake::Task[test].invoke + end +end diff --git a/PuppetResources/ClassRoomExamples/appserver_tomcat/examples/init.pp b/PuppetResources/ClassRoomExamples/appserver_tomcat/examples/init.pp new file mode 100644 index 0000000..016262e --- /dev/null +++ b/PuppetResources/ClassRoomExamples/appserver_tomcat/examples/init.pp @@ -0,0 +1,12 @@ +# The baseline for module testing used by Puppet Labs is that each manifest +# should have a corresponding test manifest that declares that class or defined +# type. +# +# Tests are then run by using puppet apply --noop (to check for compilation +# errors and view a log of events) or by fully applying the test in a virtual +# environment (to compare the resulting system state to the desired state). +# +# Learn more about module testing here: +# https://docs.puppet.com/guides/tests_smoke.html +# +include ::appserver_tomcat diff --git a/PuppetResources/ClassRoomExamples/appserver_tomcat/manifests/init.pp b/PuppetResources/ClassRoomExamples/appserver_tomcat/manifests/init.pp new file mode 100644 index 0000000..c269e3c --- /dev/null +++ b/PuppetResources/ClassRoomExamples/appserver_tomcat/manifests/init.pp @@ -0,0 +1,70 @@ +# Class: appserver_tomcat +# =========================== +# +# Full description of class appserver_tomcat here. +# +# Parameters +# ---------- +# +# Document parameters here. +# +# * `sample parameter` +# Explanation of what this parameter affects and what it defaults to. +# e.g. "Specify one or more upstream ntp servers as an array." +# +# Variables +# ---------- +# +# Here you should define a list of variables that this module would require. +# +# * `sample variable` +# Explanation of how this variable affects the function of this class and if +# it has a default. e.g. "The parameter enc_ntp_servers must be set by the +# External Node Classifier as a comma separated list of hostnames." (Note, +# global variables should be avoided in favor of class parameters as +# of Puppet 2.6.) +# +# Examples +# -------- +# +# @example +# class { 'appserver_tomcat': +# servers => [ 'pool.ntp.org', 'ntp.local.company.com' ], +# } +# +# Authors +# ------- +# +# Author Name +# +# Copyright +# --------- +# +# Copyright 2017 Your name here, unless otherwise noted. +# +class appserver_tomcat { +# $package_name = $facts['os']['family']?{ +# 'RedHat' => 'tomcat', +# 'Debian' => 'tomcat7', +# } + + # class { appserver_tomcat::install : + # package_name => $package_name , + # install_message => "${package_name} is installed " + # + # } + + #include appserver_tomcat::install + + # class { appserver_tomcat::service : + # package_name => $package_name , + # + # } + + include appserver_tomcat::install + + include appserver_tomcat::service + + + +} diff --git a/PuppetResources/ClassRoomExamples/appserver_tomcat/manifests/install.pp b/PuppetResources/ClassRoomExamples/appserver_tomcat/manifests/install.pp new file mode 100644 index 0000000..e2c4ff0 --- /dev/null +++ b/PuppetResources/ClassRoomExamples/appserver_tomcat/manifests/install.pp @@ -0,0 +1,11 @@ +class appserver_tomcat::install ( + $package_name = $appserver_tomcat::params::package_name, + $install_message = $appserver_tomcat::params::install_message + ) inherits appserver_tomcat::params { + package { $package_name: + ensure => installed, + } + + notify { $install_message: } + +} \ No newline at end of file diff --git a/PuppetResources/ClassRoomExamples/appserver_tomcat/manifests/params.pp b/PuppetResources/ClassRoomExamples/appserver_tomcat/manifests/params.pp new file mode 100644 index 0000000..d62798d --- /dev/null +++ b/PuppetResources/ClassRoomExamples/appserver_tomcat/manifests/params.pp @@ -0,0 +1,10 @@ +class appserver_tomat::params{ + $package_name = $facts['os']['family']?{ + 'RedHat' => 'tomcat', + 'Debian' => 'tomcat7', + } + + $install_message = "${package_name} is installed" + + $service_message ="${package_name} service is running" +} \ No newline at end of file diff --git a/PuppetResources/ClassRoomExamples/appserver_tomcat/manifests/service.pp b/PuppetResources/ClassRoomExamples/appserver_tomcat/manifests/service.pp new file mode 100644 index 0000000..203282d --- /dev/null +++ b/PuppetResources/ClassRoomExamples/appserver_tomcat/manifests/service.pp @@ -0,0 +1,19 @@ +# Class: service +# +# +class appserver_tomcat::service ( + $service_name = $appserver_tomcat::params::package_name, + $service_message = $appserver_tomcat::params::service_message + ) inherits appserver_tomcat::params { + + +# This resource enables the tomcat service + + service { $service_name: + ensure => running, + enable => true, + hasrestart => true, + hasstatus => true, + # pattern => $package_name, + } +} \ No newline at end of file diff --git a/PuppetResources/ClassRoomExamples/appserver_tomcat/manifests/usersconfig.pp b/PuppetResources/ClassRoomExamples/appserver_tomcat/manifests/usersconfig.pp new file mode 100644 index 0000000..830e4bb --- /dev/null +++ b/PuppetResources/ClassRoomExamples/appserver_tomcat/manifests/usersconfig.pp @@ -0,0 +1,16 @@ +# Class usersconfig +# +# +class appserver_tomcat::usersconfig ($tomcat_users_location= '') { + # resources + $tomcat_username ='admin' + $tomcat_password = 'password' + $tomcat_roles ='manager-gui,admin-gui' + + file{ $tomcat_users_location : + ensure => present, + content => template('appserver_tomcat/tomcat-users.xml.erb') + + } + +} \ No newline at end of file diff --git a/PuppetResources/ClassRoomExamples/appserver_tomcat/metadata.json b/PuppetResources/ClassRoomExamples/appserver_tomcat/metadata.json new file mode 100644 index 0000000..87024c0 --- /dev/null +++ b/PuppetResources/ClassRoomExamples/appserver_tomcat/metadata.json @@ -0,0 +1,15 @@ +{ + "name": "asquarezone/appserver_tomcat", + "version": "0.1.0", + "author": "asquarezone", + "summary": "this module is for installing & configuring tomcat", + "license": "Apache-2.0", + "source": "https://github.com/asquarezone/PuppetZone.git", + "project_page": "https://github.com/asquarezone/PuppetZone", + "issues_url": "https://github.com/asquarezone/PuppetZone/issues", + "dependencies": [ + {"name":"puppetlabs-stdlib","version_requirement":">= 1.0.0"} + ], + "data_provider": null +} + diff --git a/PuppetResources/ClassRoomExamples/appserver_tomcat/spec/classes/init_spec.rb b/PuppetResources/ClassRoomExamples/appserver_tomcat/spec/classes/init_spec.rb new file mode 100644 index 0000000..4e73b15 --- /dev/null +++ b/PuppetResources/ClassRoomExamples/appserver_tomcat/spec/classes/init_spec.rb @@ -0,0 +1,6 @@ +require 'spec_helper' +describe 'appserver_tomcat' do + context 'with default values for all parameters' do + it { should contain_class('appserver_tomcat') } + end +end diff --git a/PuppetResources/ClassRoomExamples/appserver_tomcat/spec/spec_helper.rb b/PuppetResources/ClassRoomExamples/appserver_tomcat/spec/spec_helper.rb new file mode 100644 index 0000000..2c6f566 --- /dev/null +++ b/PuppetResources/ClassRoomExamples/appserver_tomcat/spec/spec_helper.rb @@ -0,0 +1 @@ +require 'puppetlabs_spec_helper/module_spec_helper' diff --git a/PuppetResources/ClassRoomExamples/appserver_tomcat/templates/tomcat-users.xml.erb b/PuppetResources/ClassRoomExamples/appserver_tomcat/templates/tomcat-users.xml.erb new file mode 100644 index 0000000..e71383b --- /dev/null +++ b/PuppetResources/ClassRoomExamples/appserver_tomcat/templates/tomcat-users.xml.erb @@ -0,0 +1,47 @@ + + + + + + + + + diff --git a/PuppetResources/ClassRoomExamples/case_example.pp b/PuppetResources/ClassRoomExamples/case_example.pp new file mode 100644 index 0000000..051c2c1 --- /dev/null +++ b/PuppetResources/ClassRoomExamples/case_example.pp @@ -0,0 +1,24 @@ + +case $facts['os']['name'] { + 'Centos': { + # code + notify { 'Iam in Centos': } + + } + 'Ubuntu' :{ + notify { 'Iam in Ubuntu': } + + } + 'Fedora' : { + notify { 'Iam in Fedora': } + + } + 'OpenSuse' : { + notify { 'Iam in OpenSuse': } + + } + default: { + # code + notify { "Iam lost please help. Iam in os named ${facts['os']['name']}": } + } +} \ No newline at end of file diff --git a/PuppetResources/ClassRoomExamples/definedresource_example.pp b/PuppetResources/ClassRoomExamples/definedresource_example.pp new file mode 100644 index 0000000..0f198be --- /dev/null +++ b/PuppetResources/ClassRoomExamples/definedresource_example.pp @@ -0,0 +1,36 @@ +define remote_file($remote_location=undef, $mode='0644'){ + exec{"retrieve_${title}": + command => "/usr/bin/wget -q ${remote_location} -O ${title}", + creates => $title, + } + + file{$title: + mode => $mode, + require => Exec["retrieve_${title}"], + } +} + +remote_file{'/home/vagrant/bin/lein': + remote_location => 'https://raw.github.com/technomancy/leiningen/stable/bin/lein', + mode => '0755', +} + + + + +define echo($message = undef){ + exec { "echo_${title}" : + command => "echo ${message}" + + } +} + +echo { 'myecho': + message => 'hi' + +} + +echo { 'test': + message => 'hello', + name => 'test1' +} \ No newline at end of file diff --git a/PuppetResources/ClassRoomExamples/if_example.pp b/PuppetResources/ClassRoomExamples/if_example.pp new file mode 100644 index 0000000..e856ccb --- /dev/null +++ b/PuppetResources/ClassRoomExamples/if_example.pp @@ -0,0 +1,12 @@ +$os_name =$facts['os']['name'] +if $os_name == 'Centos'{ + notify { 'Iam in Centos': } +} elsif $os_name == 'Ubuntu' { + notify { 'Iam in Ubuntu': } +} elsif $os_name == 'Fedora' { + notify { 'Iam in Fedora': } +} elsif $os_name == 'OpenSuse' { + notify { 'Iam in OpenSuse': } +} else { + notify { "Iam lost please help. Iam in os named ${facts['os']['name']}": } +} diff --git a/PuppetResources/ClassRoomExamples/inline_erb_example.pp b/PuppetResources/ClassRoomExamples/inline_erb_example.pp new file mode 100644 index 0000000..5bacec8 --- /dev/null +++ b/PuppetResources/ClassRoomExamples/inline_erb_example.pp @@ -0,0 +1,17 @@ +$osname= $facts['os']['name'] + +$erb_message= @(BEGIN) +#This is managed by puppet +# operating System = <%= @osname %> +# This is erb template +BEGIN + +notify { inline_template($erb_message): } + +$epp_message= @(BEGIN) +#This is managed by puppet +# operating System = <%= $osname %> +# This is epp template +BEGIN + +notify{ inline_epp($epp_message):} \ No newline at end of file diff --git a/PuppetResources/ClassRoomExamples/motd/README.md b/PuppetResources/ClassRoomExamples/motd/README.md new file mode 100644 index 0000000..701cfca --- /dev/null +++ b/PuppetResources/ClassRoomExamples/motd/README.md @@ -0,0 +1,83 @@ +# motd + +#### Table of Contents + +1. [Description](#description) +1. [Setup - The basics of getting started with motd](#setup) + * [What motd affects](#what-motd-affects) + * [Setup requirements](#setup-requirements) + * [Beginning with motd](#beginning-with-motd) +1. [Usage - Configuration options and additional functionality](#usage) +1. [Reference - An under-the-hood peek at what the module is doing and how](#reference) +1. [Limitations - OS compatibility, etc.](#limitations) +1. [Development - Guide for contributing to the module](#development) + +## Description + +Start with a one- or two-sentence summary of what the module does and/or what +problem it solves. This is your 30-second elevator pitch for your module. +Consider including OS/Puppet version it works with. + +You can give more descriptive information in a second paragraph. This paragraph +should answer the questions: "What does this module *do*?" and "Why would I use +it?" If your module has a range of functionality (installation, configuration, +management, etc.), this is the time to mention it. + +## Setup + +### What motd affects **OPTIONAL** + +If it's obvious what your module touches, you can skip this section. For +example, folks can probably figure out that your mysql_instance module affects +their MySQL instances. + +If there's more that they should know about, though, this is the place to mention: + +* A list of files, packages, services, or operations that the module will alter, + impact, or execute. +* Dependencies that your module automatically installs. +* Warnings or other important notices. + +### Setup Requirements **OPTIONAL** + +If your module requires anything extra before setting up (pluginsync enabled, +etc.), mention it here. + +If your most recent release breaks compatibility or requires particular steps +for upgrading, you might want to include an additional "Upgrading" section +here. + +### Beginning with motd + +The very basic steps needed for a user to get the module up and running. This +can include setup steps, if necessary, or it can be an example of the most +basic use of the module. + +## Usage + +This section is where you describe how to customize, configure, and do the +fancy stuff with your module here. It's especially helpful if you include usage +examples and code samples for doing things with your module. + +## Reference + +Here, include a complete list of your module's classes, types, providers, +facts, along with the parameters for each. Users refer to this section (thus +the name "Reference") to find specific details; most users don't read it per +se. + +## Limitations + +This is where you list OS compatibility, version compatibility, etc. If there +are Known Issues, you might want to include them under their own heading here. + +## Development + +Since your module is awesome, other users will want to play with it. Let them +know what the ground rules for contributing are. + +## Release Notes/Contributors/Etc. **Optional** + +If you aren't using changelog, put your release notes here (though you should +consider using changelog). You can also add any additional sections you feel +are necessary or important to include here. Please use the `## ` header. diff --git a/PuppetResources/ClassRoomExamples/motd/Rakefile b/PuppetResources/ClassRoomExamples/motd/Rakefile new file mode 100644 index 0000000..02609e3 --- /dev/null +++ b/PuppetResources/ClassRoomExamples/motd/Rakefile @@ -0,0 +1,32 @@ +require 'puppetlabs_spec_helper/rake_tasks' +require 'puppet-lint/tasks/puppet-lint' +require 'metadata-json-lint/rake_task' + +if RUBY_VERSION >= '1.9' + require 'rubocop/rake_task' + RuboCop::RakeTask.new +end + +PuppetLint.configuration.send('disable_80chars') +PuppetLint.configuration.relative = true +PuppetLint.configuration.ignore_paths = ['spec/**/*.pp', 'pkg/**/*.pp'] + +desc 'Validate manifests, templates, and ruby files' +task :validate do + Dir['manifests/**/*.pp'].each do |manifest| + sh "puppet parser validate --noop #{manifest}" + end + Dir['spec/**/*.rb', 'lib/**/*.rb'].each do |ruby_file| + sh "ruby -c #{ruby_file}" unless ruby_file =~ %r{spec/fixtures} + end + Dir['templates/**/*.erb'].each do |template| + sh "erb -P -x -T '-' #{template} | ruby -c" + end +end + +desc 'Run metadata_lint, lint, validate, and spec tests.' +task :test do + [:metadata_lint, :lint, :validate, :spec].each do |test| + Rake::Task[test].invoke + end +end diff --git a/PuppetResources/ClassRoomExamples/motd/examples/init.pp b/PuppetResources/ClassRoomExamples/motd/examples/init.pp new file mode 100644 index 0000000..b161743 --- /dev/null +++ b/PuppetResources/ClassRoomExamples/motd/examples/init.pp @@ -0,0 +1,12 @@ +# The baseline for module testing used by Puppet Labs is that each manifest +# should have a corresponding test manifest that declares that class or defined +# type. +# +# Tests are then run by using puppet apply --noop (to check for compilation +# errors and view a log of events) or by fully applying the test in a virtual +# environment (to compare the resulting system state to the desired state). +# +# Learn more about module testing here: +# https://docs.puppet.com/guides/tests_smoke.html +# +include ::motd diff --git a/PuppetResources/ClassRoomExamples/motd/files/message b/PuppetResources/ClassRoomExamples/motd/files/message new file mode 100644 index 0000000..fb260d5 --- /dev/null +++ b/PuppetResources/ClassRoomExamples/motd/files/message @@ -0,0 +1,4 @@ +#This is managed by puppet +This is done as class room example + +Your server should be shutdown by 5 pm today \ No newline at end of file diff --git a/PuppetResources/ClassRoomExamples/motd/manifests/init.pp b/PuppetResources/ClassRoomExamples/motd/manifests/init.pp new file mode 100644 index 0000000..d769350 --- /dev/null +++ b/PuppetResources/ClassRoomExamples/motd/manifests/init.pp @@ -0,0 +1,59 @@ +# Class: motd +# =========================== +# +# Full description of class motd here. +# +# Parameters +# ---------- +# +# Document parameters here. +# +# * `sample parameter` +# Explanation of what this parameter affects and what it defaults to. +# e.g. "Specify one or more upstream ntp servers as an array." +# +# Variables +# ---------- +# +# Here you should define a list of variables that this module would require. +# +# * `sample variable` +# Explanation of how this variable affects the function of this class and if +# it has a default. e.g. "The parameter enc_ntp_servers must be set by the +# External Node Classifier as a comma separated list of hostnames." (Note, +# global variables should be avoided in favor of class parameters as +# of Puppet 2.6.) +# +# Examples +# -------- +# +# @example +# class { 'motd': +# servers => [ 'pool.ntp.org', 'ntp.local.company.com' ], +# } +# +# Authors +# ------- +# +# Author Name +# +# Copyright +# --------- +# +# Copyright 2017 Your name here, unless otherwise noted. +# +class motd($message='test') { + + + + file { '/etc/motd': + ensure => file, + #owner => owner, + #group => group, + #mode => mode, + #source => 'puppet:///modules/class/file.txt'; + content => $message, + } + + +} diff --git a/PuppetResources/ClassRoomExamples/motd/spec/classes/Gemfile b/PuppetResources/ClassRoomExamples/motd/spec/classes/Gemfile new file mode 100644 index 0000000..4f662dc --- /dev/null +++ b/PuppetResources/ClassRoomExamples/motd/spec/classes/Gemfile @@ -0,0 +1,18 @@ +source ENV['GEM_SOURCE'] || 'https://rubygems.org' + +puppetversion = ENV.key?('PUPPET_VERSION') ? ENV['PUPPET_VERSION'] : ['>= 3.3'] +gem 'metadata-json-lint' +gem 'puppet', puppetversion +gem 'puppetlabs_spec_helper', '>= 1.0.0' +gem 'puppet-lint', '>= 1.0.0' +gem 'facter', '>= 1.7.0' +gem 'rspec-puppet' + +# rspec must be v2 for ruby 1.8.7 +if RUBY_VERSION >= '1.8.7' && RUBY_VERSION < '1.9' + gem 'rspec', '~> 2.0' + gem 'rake', '~> 10.0' +else + # rubocop requires ruby >= 1.9 + gem 'rubocop' +end diff --git a/PuppetResources/ClassRoomExamples/motd/spec/classes/init_spec.rb b/PuppetResources/ClassRoomExamples/motd/spec/classes/init_spec.rb new file mode 100644 index 0000000..7ed9953 --- /dev/null +++ b/PuppetResources/ClassRoomExamples/motd/spec/classes/init_spec.rb @@ -0,0 +1,6 @@ +require 'spec_helper' +describe 'motd' do + context 'with default values for all parameters' do + it { should contain_class('motd') } + end +end diff --git a/PuppetResources/ClassRoomExamples/motd/spec/metadata.json b/PuppetResources/ClassRoomExamples/motd/spec/metadata.json new file mode 100644 index 0000000..acaf009 --- /dev/null +++ b/PuppetResources/ClassRoomExamples/motd/spec/metadata.json @@ -0,0 +1,15 @@ +{ + "name": "asquarezone/motd", + "version": "0.1.0", + "author": "asquarezone", + "summary": "this is for class room training", + "license": "Apache-2.0", + "source": "https://github.com/asquarezone/puppet.git", + "project_page": "https://github.com/asquarezone/puppet", + "issues_url": "https://github.com/asquarezone/puppet/issues", + "dependencies": [ + {"name":"puppetlabs-stdlib","version_requirement":">= 1.0.0"} + ], + "data_provider": null +} + diff --git a/PuppetResources/ClassRoomExamples/motd/spec/spec_helper.rb b/PuppetResources/ClassRoomExamples/motd/spec/spec_helper.rb new file mode 100644 index 0000000..2c6f566 --- /dev/null +++ b/PuppetResources/ClassRoomExamples/motd/spec/spec_helper.rb @@ -0,0 +1 @@ +require 'puppetlabs_spec_helper/module_spec_helper' diff --git a/PuppetResources/ClassRoomExamples/nagios_install_example.pp b/PuppetResources/ClassRoomExamples/nagios_install_example.pp new file mode 100644 index 0000000..22df22d --- /dev/null +++ b/PuppetResources/ClassRoomExamples/nagios_install_example.pp @@ -0,0 +1,11 @@ + +# This resource will install apache +package { 'apache2': + ensure => installed, + + +echo { 'test' : + message => 'test it' , + name => 'tes1' + +} \ No newline at end of file diff --git a/PuppetResources/ClassRoomExamples/params_demo/Gemfile b/PuppetResources/ClassRoomExamples/params_demo/Gemfile new file mode 100644 index 0000000..4f662dc --- /dev/null +++ b/PuppetResources/ClassRoomExamples/params_demo/Gemfile @@ -0,0 +1,18 @@ +source ENV['GEM_SOURCE'] || 'https://rubygems.org' + +puppetversion = ENV.key?('PUPPET_VERSION') ? ENV['PUPPET_VERSION'] : ['>= 3.3'] +gem 'metadata-json-lint' +gem 'puppet', puppetversion +gem 'puppetlabs_spec_helper', '>= 1.0.0' +gem 'puppet-lint', '>= 1.0.0' +gem 'facter', '>= 1.7.0' +gem 'rspec-puppet' + +# rspec must be v2 for ruby 1.8.7 +if RUBY_VERSION >= '1.8.7' && RUBY_VERSION < '1.9' + gem 'rspec', '~> 2.0' + gem 'rake', '~> 10.0' +else + # rubocop requires ruby >= 1.9 + gem 'rubocop' +end diff --git a/PuppetResources/ClassRoomExamples/params_demo/README.md b/PuppetResources/ClassRoomExamples/params_demo/README.md new file mode 100644 index 0000000..671b883 --- /dev/null +++ b/PuppetResources/ClassRoomExamples/params_demo/README.md @@ -0,0 +1,83 @@ +# params_demo + +#### Table of Contents + +1. [Description](#description) +1. [Setup - The basics of getting started with params_demo](#setup) + * [What params_demo affects](#what-params_demo-affects) + * [Setup requirements](#setup-requirements) + * [Beginning with params_demo](#beginning-with-params_demo) +1. [Usage - Configuration options and additional functionality](#usage) +1. [Reference - An under-the-hood peek at what the module is doing and how](#reference) +1. [Limitations - OS compatibility, etc.](#limitations) +1. [Development - Guide for contributing to the module](#development) + +## Description + +Start with a one- or two-sentence summary of what the module does and/or what +problem it solves. This is your 30-second elevator pitch for your module. +Consider including OS/Puppet version it works with. + +You can give more descriptive information in a second paragraph. This paragraph +should answer the questions: "What does this module *do*?" and "Why would I use +it?" If your module has a range of functionality (installation, configuration, +management, etc.), this is the time to mention it. + +## Setup + +### What params_demo affects **OPTIONAL** + +If it's obvious what your module touches, you can skip this section. For +example, folks can probably figure out that your mysql_instance module affects +their MySQL instances. + +If there's more that they should know about, though, this is the place to mention: + +* A list of files, packages, services, or operations that the module will alter, + impact, or execute. +* Dependencies that your module automatically installs. +* Warnings or other important notices. + +### Setup Requirements **OPTIONAL** + +If your module requires anything extra before setting up (pluginsync enabled, +etc.), mention it here. + +If your most recent release breaks compatibility or requires particular steps +for upgrading, you might want to include an additional "Upgrading" section +here. + +### Beginning with params_demo + +The very basic steps needed for a user to get the module up and running. This +can include setup steps, if necessary, or it can be an example of the most +basic use of the module. + +## Usage + +This section is where you describe how to customize, configure, and do the +fancy stuff with your module here. It's especially helpful if you include usage +examples and code samples for doing things with your module. + +## Reference + +Here, include a complete list of your module's classes, types, providers, +facts, along with the parameters for each. Users refer to this section (thus +the name "Reference") to find specific details; most users don't read it per +se. + +## Limitations + +This is where you list OS compatibility, version compatibility, etc. If there +are Known Issues, you might want to include them under their own heading here. + +## Development + +Since your module is awesome, other users will want to play with it. Let them +know what the ground rules for contributing are. + +## Release Notes/Contributors/Etc. **Optional** + +If you aren't using changelog, put your release notes here (though you should +consider using changelog). You can also add any additional sections you feel +are necessary or important to include here. Please use the `## ` header. diff --git a/PuppetResources/ClassRoomExamples/params_demo/Rakefile b/PuppetResources/ClassRoomExamples/params_demo/Rakefile new file mode 100644 index 0000000..02609e3 --- /dev/null +++ b/PuppetResources/ClassRoomExamples/params_demo/Rakefile @@ -0,0 +1,32 @@ +require 'puppetlabs_spec_helper/rake_tasks' +require 'puppet-lint/tasks/puppet-lint' +require 'metadata-json-lint/rake_task' + +if RUBY_VERSION >= '1.9' + require 'rubocop/rake_task' + RuboCop::RakeTask.new +end + +PuppetLint.configuration.send('disable_80chars') +PuppetLint.configuration.relative = true +PuppetLint.configuration.ignore_paths = ['spec/**/*.pp', 'pkg/**/*.pp'] + +desc 'Validate manifests, templates, and ruby files' +task :validate do + Dir['manifests/**/*.pp'].each do |manifest| + sh "puppet parser validate --noop #{manifest}" + end + Dir['spec/**/*.rb', 'lib/**/*.rb'].each do |ruby_file| + sh "ruby -c #{ruby_file}" unless ruby_file =~ %r{spec/fixtures} + end + Dir['templates/**/*.erb'].each do |template| + sh "erb -P -x -T '-' #{template} | ruby -c" + end +end + +desc 'Run metadata_lint, lint, validate, and spec tests.' +task :test do + [:metadata_lint, :lint, :validate, :spec].each do |test| + Rake::Task[test].invoke + end +end diff --git a/PuppetResources/ClassRoomExamples/params_demo/examples/init.pp b/PuppetResources/ClassRoomExamples/params_demo/examples/init.pp new file mode 100644 index 0000000..8556982 --- /dev/null +++ b/PuppetResources/ClassRoomExamples/params_demo/examples/init.pp @@ -0,0 +1,12 @@ +# The baseline for module testing used by Puppet Labs is that each manifest +# should have a corresponding test manifest that declares that class or defined +# type. +# +# Tests are then run by using puppet apply --noop (to check for compilation +# errors and view a log of events) or by fully applying the test in a virtual +# environment (to compare the resulting system state to the desired state). +# +# Learn more about module testing here: +# https://docs.puppet.com/guides/tests_smoke.html +# +include ::params_demo diff --git a/PuppetResources/ClassRoomExamples/params_demo/manifests/display_message.pp b/PuppetResources/ClassRoomExamples/params_demo/manifests/display_message.pp new file mode 100644 index 0000000..446f851 --- /dev/null +++ b/PuppetResources/ClassRoomExamples/params_demo/manifests/display_message.pp @@ -0,0 +1,4 @@ +class params_demo::display_message ($message_n='Nothing') { + notify { $message_n: } + +} \ No newline at end of file diff --git a/PuppetResources/ClassRoomExamples/params_demo/manifests/init.pp b/PuppetResources/ClassRoomExamples/params_demo/manifests/init.pp new file mode 100644 index 0000000..0e6b3bd --- /dev/null +++ b/PuppetResources/ClassRoomExamples/params_demo/manifests/init.pp @@ -0,0 +1,54 @@ +# Class: params_demo +# =========================== +# +# Full description of class params_demo here. +# +# Parameters +# ---------- +# +# Document parameters here. +# +# * `sample parameter` +# Explanation of what this parameter affects and what it defaults to. +# e.g. "Specify one or more upstream ntp servers as an array." +# +# Variables +# ---------- +# +# Here you should define a list of variables that this module would require. +# +# * `sample variable` +# Explanation of how this variable affects the function of this class and if +# it has a default. e.g. "The parameter enc_ntp_servers must be set by the +# External Node Classifier as a comma separated list of hostnames." (Note, +# global variables should be avoided in favor of class parameters as +# of Puppet 2.6.) +# +# Examples +# -------- +# +# @example +# class { 'params_demo': +# servers => [ 'pool.ntp.org', 'ntp.local.company.com' ], +# } +# +# Authors +# ------- +# +# Author Name +# +# Copyright +# --------- +# +# Copyright 2017 Your name here, unless otherwise noted. +# +class params_demo { + # This can be used multiple times but + # cannot set parameters (need to use hiera) + # include params_demo::display_message + + class { params_demo::display_message : + message_n => "This is puppet class parameter" + } + +} diff --git a/PuppetResources/ClassRoomExamples/params_demo/metadata.json b/PuppetResources/ClassRoomExamples/params_demo/metadata.json new file mode 100644 index 0000000..bba2ff2 --- /dev/null +++ b/PuppetResources/ClassRoomExamples/params_demo/metadata.json @@ -0,0 +1,15 @@ +{ + "name": "asquarezone/params_demo", + "version": "0.1.0", + "author": "asquarezone", + "summary": null, + "license": "Apache-2.0", + "source": "", + "project_page": null, + "issues_url": null, + "dependencies": [ + {"name":"puppetlabs-stdlib","version_requirement":">= 1.0.0"} + ], + "data_provider": null +} + diff --git a/PuppetResources/ClassRoomExamples/params_demo/spec/classes/init_spec.rb b/PuppetResources/ClassRoomExamples/params_demo/spec/classes/init_spec.rb new file mode 100644 index 0000000..e1e313e --- /dev/null +++ b/PuppetResources/ClassRoomExamples/params_demo/spec/classes/init_spec.rb @@ -0,0 +1,6 @@ +require 'spec_helper' +describe 'params_demo' do + context 'with default values for all parameters' do + it { should contain_class('params_demo') } + end +end diff --git a/PuppetResources/ClassRoomExamples/params_demo/spec/spec_helper.rb b/PuppetResources/ClassRoomExamples/params_demo/spec/spec_helper.rb new file mode 100644 index 0000000..2c6f566 --- /dev/null +++ b/PuppetResources/ClassRoomExamples/params_demo/spec/spec_helper.rb @@ -0,0 +1 @@ +require 'puppetlabs_spec_helper/module_spec_helper' diff --git a/PuppetResources/ClassRoomExamples/remove_package.pp b/PuppetResources/ClassRoomExamples/remove_package.pp new file mode 100644 index 0000000..7062028 --- /dev/null +++ b/PuppetResources/ClassRoomExamples/remove_package.pp @@ -0,0 +1,6 @@ +$package_name = 'tomcat' + +package { $package_name: + ensure => purged, + +} \ No newline at end of file diff --git a/PuppetResources/ClassRoomExamples/resource_relations_example.pp b/PuppetResources/ClassRoomExamples/resource_relations_example.pp new file mode 100644 index 0000000..7b3f5f4 --- /dev/null +++ b/PuppetResources/ClassRoomExamples/resource_relations_example.pp @@ -0,0 +1,15 @@ + + +service { 'tomcat': + ensure => running, + enable => true, + hasrestart => true, + hasstatus => true, + require => Package['tomcat'], + # pattern => 'tomcat', +} + +package { 'tomcat': + ensure => installed, + before => Service['tomcat'], +} \ No newline at end of file diff --git a/PuppetResources/ClassRoomExamples/selector_example.pp b/PuppetResources/ClassRoomExamples/selector_example.pp new file mode 100644 index 0000000..6e14e30 --- /dev/null +++ b/PuppetResources/ClassRoomExamples/selector_example.pp @@ -0,0 +1,15 @@ + +#if $facts['os']['family'] == 'RedHat' { +# $package_name = 'httpd' +#} +#else { +# $package_name = 'apache2' +#} + +$package_name = $facts['os']['family'] ? { + 'RedHat' => 'httpd' , + 'Debian' => 'apache2' , +} + +notify { $package_name: } + diff --git a/PuppetResources/ClassRoomExamples/subclass_ex/Gemfile b/PuppetResources/ClassRoomExamples/subclass_ex/Gemfile new file mode 100644 index 0000000..4f662dc --- /dev/null +++ b/PuppetResources/ClassRoomExamples/subclass_ex/Gemfile @@ -0,0 +1,18 @@ +source ENV['GEM_SOURCE'] || 'https://rubygems.org' + +puppetversion = ENV.key?('PUPPET_VERSION') ? ENV['PUPPET_VERSION'] : ['>= 3.3'] +gem 'metadata-json-lint' +gem 'puppet', puppetversion +gem 'puppetlabs_spec_helper', '>= 1.0.0' +gem 'puppet-lint', '>= 1.0.0' +gem 'facter', '>= 1.7.0' +gem 'rspec-puppet' + +# rspec must be v2 for ruby 1.8.7 +if RUBY_VERSION >= '1.8.7' && RUBY_VERSION < '1.9' + gem 'rspec', '~> 2.0' + gem 'rake', '~> 10.0' +else + # rubocop requires ruby >= 1.9 + gem 'rubocop' +end diff --git a/PuppetResources/ClassRoomExamples/subclass_ex/README.md b/PuppetResources/ClassRoomExamples/subclass_ex/README.md new file mode 100644 index 0000000..3bd9560 --- /dev/null +++ b/PuppetResources/ClassRoomExamples/subclass_ex/README.md @@ -0,0 +1,83 @@ +# subclass_ex + +#### Table of Contents + +1. [Description](#description) +1. [Setup - The basics of getting started with subclass_ex](#setup) + * [What subclass_ex affects](#what-subclass_ex-affects) + * [Setup requirements](#setup-requirements) + * [Beginning with subclass_ex](#beginning-with-subclass_ex) +1. [Usage - Configuration options and additional functionality](#usage) +1. [Reference - An under-the-hood peek at what the module is doing and how](#reference) +1. [Limitations - OS compatibility, etc.](#limitations) +1. [Development - Guide for contributing to the module](#development) + +## Description + +Start with a one- or two-sentence summary of what the module does and/or what +problem it solves. This is your 30-second elevator pitch for your module. +Consider including OS/Puppet version it works with. + +You can give more descriptive information in a second paragraph. This paragraph +should answer the questions: "What does this module *do*?" and "Why would I use +it?" If your module has a range of functionality (installation, configuration, +management, etc.), this is the time to mention it. + +## Setup + +### What subclass_ex affects **OPTIONAL** + +If it's obvious what your module touches, you can skip this section. For +example, folks can probably figure out that your mysql_instance module affects +their MySQL instances. + +If there's more that they should know about, though, this is the place to mention: + +* A list of files, packages, services, or operations that the module will alter, + impact, or execute. +* Dependencies that your module automatically installs. +* Warnings or other important notices. + +### Setup Requirements **OPTIONAL** + +If your module requires anything extra before setting up (pluginsync enabled, +etc.), mention it here. + +If your most recent release breaks compatibility or requires particular steps +for upgrading, you might want to include an additional "Upgrading" section +here. + +### Beginning with subclass_ex + +The very basic steps needed for a user to get the module up and running. This +can include setup steps, if necessary, or it can be an example of the most +basic use of the module. + +## Usage + +This section is where you describe how to customize, configure, and do the +fancy stuff with your module here. It's especially helpful if you include usage +examples and code samples for doing things with your module. + +## Reference + +Here, include a complete list of your module's classes, types, providers, +facts, along with the parameters for each. Users refer to this section (thus +the name "Reference") to find specific details; most users don't read it per +se. + +## Limitations + +This is where you list OS compatibility, version compatibility, etc. If there +are Known Issues, you might want to include them under their own heading here. + +## Development + +Since your module is awesome, other users will want to play with it. Let them +know what the ground rules for contributing are. + +## Release Notes/Contributors/Etc. **Optional** + +If you aren't using changelog, put your release notes here (though you should +consider using changelog). You can also add any additional sections you feel +are necessary or important to include here. Please use the `## ` header. diff --git a/PuppetResources/ClassRoomExamples/subclass_ex/Rakefile b/PuppetResources/ClassRoomExamples/subclass_ex/Rakefile new file mode 100644 index 0000000..02609e3 --- /dev/null +++ b/PuppetResources/ClassRoomExamples/subclass_ex/Rakefile @@ -0,0 +1,32 @@ +require 'puppetlabs_spec_helper/rake_tasks' +require 'puppet-lint/tasks/puppet-lint' +require 'metadata-json-lint/rake_task' + +if RUBY_VERSION >= '1.9' + require 'rubocop/rake_task' + RuboCop::RakeTask.new +end + +PuppetLint.configuration.send('disable_80chars') +PuppetLint.configuration.relative = true +PuppetLint.configuration.ignore_paths = ['spec/**/*.pp', 'pkg/**/*.pp'] + +desc 'Validate manifests, templates, and ruby files' +task :validate do + Dir['manifests/**/*.pp'].each do |manifest| + sh "puppet parser validate --noop #{manifest}" + end + Dir['spec/**/*.rb', 'lib/**/*.rb'].each do |ruby_file| + sh "ruby -c #{ruby_file}" unless ruby_file =~ %r{spec/fixtures} + end + Dir['templates/**/*.erb'].each do |template| + sh "erb -P -x -T '-' #{template} | ruby -c" + end +end + +desc 'Run metadata_lint, lint, validate, and spec tests.' +task :test do + [:metadata_lint, :lint, :validate, :spec].each do |test| + Rake::Task[test].invoke + end +end diff --git a/PuppetResources/ClassRoomExamples/subclass_ex/examples/init.pp b/PuppetResources/ClassRoomExamples/subclass_ex/examples/init.pp new file mode 100644 index 0000000..88c5a7d --- /dev/null +++ b/PuppetResources/ClassRoomExamples/subclass_ex/examples/init.pp @@ -0,0 +1,12 @@ +# The baseline for module testing used by Puppet Labs is that each manifest +# should have a corresponding test manifest that declares that class or defined +# type. +# +# Tests are then run by using puppet apply --noop (to check for compilation +# errors and view a log of events) or by fully applying the test in a virtual +# environment (to compare the resulting system state to the desired state). +# +# Learn more about module testing here: +# https://docs.puppet.com/guides/tests_smoke.html +# +include ::subclass_ex diff --git a/PuppetResources/ClassRoomExamples/subclass_ex/manifests/init.pp b/PuppetResources/ClassRoomExamples/subclass_ex/manifests/init.pp new file mode 100644 index 0000000..6628422 --- /dev/null +++ b/PuppetResources/ClassRoomExamples/subclass_ex/manifests/init.pp @@ -0,0 +1,50 @@ +# Class: subclass_ex +# =========================== +# +# Full description of class subclass_ex here. +# +# Parameters +# ---------- +# +# Document parameters here. +# +# * `sample parameter` +# Explanation of what this parameter affects and what it defaults to. +# e.g. "Specify one or more upstream ntp servers as an array." +# +# Variables +# ---------- +# +# Here you should define a list of variables that this module would require. +# +# * `sample variable` +# Explanation of how this variable affects the function of this class and if +# it has a default. e.g. "The parameter enc_ntp_servers must be set by the +# External Node Classifier as a comma separated list of hostnames." (Note, +# global variables should be avoided in favor of class parameters as +# of Puppet 2.6.) +# +# Examples +# -------- +# +# @example +# class { 'subclass_ex': +# servers => [ 'pool.ntp.org', 'ntp.local.company.com' ], +# } +# +# Authors +# ------- +# +# Author Name +# +# Copyright +# --------- +# +# Copyright 2017 Your name here, unless otherwise noted. +# +class subclass_ex { + include subclass_ex::install + + include subclass_ex::myservice + +} diff --git a/PuppetResources/ClassRoomExamples/subclass_ex/manifests/install.pp b/PuppetResources/ClassRoomExamples/subclass_ex/manifests/install.pp new file mode 100644 index 0000000..25615d1 --- /dev/null +++ b/PuppetResources/ClassRoomExamples/subclass_ex/manifests/install.pp @@ -0,0 +1,15 @@ +# Class: install +# +# +class subclass_ex::install($package_name= params::$package_name) +inherits params { + # resources + + package { $package_name: + ensure => installed, + notify => Class['myservice'] + + } + + +} \ No newline at end of file diff --git a/PuppetResources/ClassRoomExamples/subclass_ex/manifests/myservice.pp b/PuppetResources/ClassRoomExamples/subclass_ex/manifests/myservice.pp new file mode 100644 index 0000000..1dadff3 --- /dev/null +++ b/PuppetResources/ClassRoomExamples/subclass_ex/manifests/myservice.pp @@ -0,0 +1,9 @@ +class myservice($service_name= params::$package_name) inherits params{ + service { $service_name: + ensure => running, + enable => true, + hasrestart => true, + hasstatus => true, + # pattern => 'tomcat', + } +} \ No newline at end of file diff --git a/PuppetResources/ClassRoomExamples/subclass_ex/manifests/params.pp b/PuppetResources/ClassRoomExamples/subclass_ex/manifests/params.pp new file mode 100644 index 0000000..16ced27 --- /dev/null +++ b/PuppetResources/ClassRoomExamples/subclass_ex/manifests/params.pp @@ -0,0 +1,6 @@ +class params { + $package_name = $facts['os']['family'] ? { + 'RedHat' => 'httpd', + 'Debian' => 'apache2', + } +} \ No newline at end of file diff --git a/PuppetResources/ClassRoomExamples/subclass_ex/metadata.json b/PuppetResources/ClassRoomExamples/subclass_ex/metadata.json new file mode 100644 index 0000000..833e13d --- /dev/null +++ b/PuppetResources/ClassRoomExamples/subclass_ex/metadata.json @@ -0,0 +1,15 @@ +{ + "name": "asquarezone/subclass_ex", + "version": "0.1.0", + "author": "asquarezone", + "summary": "sub classes ( multiple classes)", + "license": "Apache-2.0", + "source": "", + "project_page": null, + "issues_url": null, + "dependencies": [ + {"name":"puppetlabs-stdlib","version_requirement":">= 1.0.0"} + ], + "data_provider": null +} + diff --git a/PuppetResources/ClassRoomExamples/subclass_ex/spec/classes/init_spec.rb b/PuppetResources/ClassRoomExamples/subclass_ex/spec/classes/init_spec.rb new file mode 100644 index 0000000..fcf6ab3 --- /dev/null +++ b/PuppetResources/ClassRoomExamples/subclass_ex/spec/classes/init_spec.rb @@ -0,0 +1,6 @@ +require 'spec_helper' +describe 'subclass_ex' do + context 'with default values for all parameters' do + it { should contain_class('subclass_ex') } + end +end diff --git a/PuppetResources/ClassRoomExamples/subclass_ex/spec/spec_helper.rb b/PuppetResources/ClassRoomExamples/subclass_ex/spec/spec_helper.rb new file mode 100644 index 0000000..2c6f566 --- /dev/null +++ b/PuppetResources/ClassRoomExamples/subclass_ex/spec/spec_helper.rb @@ -0,0 +1 @@ +require 'puppetlabs_spec_helper/module_spec_helper' diff --git a/PuppetResources/ClassRoomExamples/template_ex/Gemfile b/PuppetResources/ClassRoomExamples/template_ex/Gemfile new file mode 100644 index 0000000..4f662dc --- /dev/null +++ b/PuppetResources/ClassRoomExamples/template_ex/Gemfile @@ -0,0 +1,18 @@ +source ENV['GEM_SOURCE'] || 'https://rubygems.org' + +puppetversion = ENV.key?('PUPPET_VERSION') ? ENV['PUPPET_VERSION'] : ['>= 3.3'] +gem 'metadata-json-lint' +gem 'puppet', puppetversion +gem 'puppetlabs_spec_helper', '>= 1.0.0' +gem 'puppet-lint', '>= 1.0.0' +gem 'facter', '>= 1.7.0' +gem 'rspec-puppet' + +# rspec must be v2 for ruby 1.8.7 +if RUBY_VERSION >= '1.8.7' && RUBY_VERSION < '1.9' + gem 'rspec', '~> 2.0' + gem 'rake', '~> 10.0' +else + # rubocop requires ruby >= 1.9 + gem 'rubocop' +end diff --git a/PuppetResources/ClassRoomExamples/template_ex/README.md b/PuppetResources/ClassRoomExamples/template_ex/README.md new file mode 100644 index 0000000..2415019 --- /dev/null +++ b/PuppetResources/ClassRoomExamples/template_ex/README.md @@ -0,0 +1,83 @@ +# template_ex + +#### Table of Contents + +1. [Description](#description) +1. [Setup - The basics of getting started with template_ex](#setup) + * [What template_ex affects](#what-template_ex-affects) + * [Setup requirements](#setup-requirements) + * [Beginning with template_ex](#beginning-with-template_ex) +1. [Usage - Configuration options and additional functionality](#usage) +1. [Reference - An under-the-hood peek at what the module is doing and how](#reference) +1. [Limitations - OS compatibility, etc.](#limitations) +1. [Development - Guide for contributing to the module](#development) + +## Description + +Start with a one- or two-sentence summary of what the module does and/or what +problem it solves. This is your 30-second elevator pitch for your module. +Consider including OS/Puppet version it works with. + +You can give more descriptive information in a second paragraph. This paragraph +should answer the questions: "What does this module *do*?" and "Why would I use +it?" If your module has a range of functionality (installation, configuration, +management, etc.), this is the time to mention it. + +## Setup + +### What template_ex affects **OPTIONAL** + +If it's obvious what your module touches, you can skip this section. For +example, folks can probably figure out that your mysql_instance module affects +their MySQL instances. + +If there's more that they should know about, though, this is the place to mention: + +* A list of files, packages, services, or operations that the module will alter, + impact, or execute. +* Dependencies that your module automatically installs. +* Warnings or other important notices. + +### Setup Requirements **OPTIONAL** + +If your module requires anything extra before setting up (pluginsync enabled, +etc.), mention it here. + +If your most recent release breaks compatibility or requires particular steps +for upgrading, you might want to include an additional "Upgrading" section +here. + +### Beginning with template_ex + +The very basic steps needed for a user to get the module up and running. This +can include setup steps, if necessary, or it can be an example of the most +basic use of the module. + +## Usage + +This section is where you describe how to customize, configure, and do the +fancy stuff with your module here. It's especially helpful if you include usage +examples and code samples for doing things with your module. + +## Reference + +Here, include a complete list of your module's classes, types, providers, +facts, along with the parameters for each. Users refer to this section (thus +the name "Reference") to find specific details; most users don't read it per +se. + +## Limitations + +This is where you list OS compatibility, version compatibility, etc. If there +are Known Issues, you might want to include them under their own heading here. + +## Development + +Since your module is awesome, other users will want to play with it. Let them +know what the ground rules for contributing are. + +## Release Notes/Contributors/Etc. **Optional** + +If you aren't using changelog, put your release notes here (though you should +consider using changelog). You can also add any additional sections you feel +are necessary or important to include here. Please use the `## ` header. diff --git a/PuppetResources/ClassRoomExamples/template_ex/Rakefile b/PuppetResources/ClassRoomExamples/template_ex/Rakefile new file mode 100644 index 0000000..02609e3 --- /dev/null +++ b/PuppetResources/ClassRoomExamples/template_ex/Rakefile @@ -0,0 +1,32 @@ +require 'puppetlabs_spec_helper/rake_tasks' +require 'puppet-lint/tasks/puppet-lint' +require 'metadata-json-lint/rake_task' + +if RUBY_VERSION >= '1.9' + require 'rubocop/rake_task' + RuboCop::RakeTask.new +end + +PuppetLint.configuration.send('disable_80chars') +PuppetLint.configuration.relative = true +PuppetLint.configuration.ignore_paths = ['spec/**/*.pp', 'pkg/**/*.pp'] + +desc 'Validate manifests, templates, and ruby files' +task :validate do + Dir['manifests/**/*.pp'].each do |manifest| + sh "puppet parser validate --noop #{manifest}" + end + Dir['spec/**/*.rb', 'lib/**/*.rb'].each do |ruby_file| + sh "ruby -c #{ruby_file}" unless ruby_file =~ %r{spec/fixtures} + end + Dir['templates/**/*.erb'].each do |template| + sh "erb -P -x -T '-' #{template} | ruby -c" + end +end + +desc 'Run metadata_lint, lint, validate, and spec tests.' +task :test do + [:metadata_lint, :lint, :validate, :spec].each do |test| + Rake::Task[test].invoke + end +end diff --git a/PuppetResources/ClassRoomExamples/template_ex/examples/init.pp b/PuppetResources/ClassRoomExamples/template_ex/examples/init.pp new file mode 100644 index 0000000..6d7b406 --- /dev/null +++ b/PuppetResources/ClassRoomExamples/template_ex/examples/init.pp @@ -0,0 +1,12 @@ +# The baseline for module testing used by Puppet Labs is that each manifest +# should have a corresponding test manifest that declares that class or defined +# type. +# +# Tests are then run by using puppet apply --noop (to check for compilation +# errors and view a log of events) or by fully applying the test in a virtual +# environment (to compare the resulting system state to the desired state). +# +# Learn more about module testing here: +# https://docs.puppet.com/guides/tests_smoke.html +# +include ::template_ex diff --git a/PuppetResources/ClassRoomExamples/template_ex/manifests/init.pp b/PuppetResources/ClassRoomExamples/template_ex/manifests/init.pp new file mode 100644 index 0000000..8d28350 --- /dev/null +++ b/PuppetResources/ClassRoomExamples/template_ex/manifests/init.pp @@ -0,0 +1,55 @@ +# Class: template_ex +# =========================== +# +# Full description of class template_ex here. +# +# Parameters +# ---------- +# +# Document parameters here. +# +# * `sample parameter` +# Explanation of what this parameter affects and what it defaults to. +# e.g. "Specify one or more upstream ntp servers as an array." +# +# Variables +# ---------- +# +# Here you should define a list of variables that this module would require. +# +# * `sample variable` +# Explanation of how this variable affects the function of this class and if +# it has a default. e.g. "The parameter enc_ntp_servers must be set by the +# External Node Classifier as a comma separated list of hostnames." (Note, +# global variables should be avoided in favor of class parameters as +# of Puppet 2.6.) +# +# Examples +# -------- +# +# @example +# class { 'template_ex': +# servers => [ 'pool.ntp.org', 'ntp.local.company.com' ], +# } +# +# Authors +# ------- +# +# Author Name +# +# Copyright +# --------- +# +# Copyright 2017 Your name here, unless otherwise noted. +# +class template_ex { + $os_name= $facts['os']['name'] + $my_fqdn =$facts['networking']['fqdn'] + $processer = $facts['processors']['models'][0] + + file { '/home/vagrant/dummy.txt': + ensure => file, + content => epp('template_ex/dummy.txt.epp',) + } + +} diff --git a/PuppetResources/ClassRoomExamples/template_ex/metadata.json b/PuppetResources/ClassRoomExamples/template_ex/metadata.json new file mode 100644 index 0000000..06f266c --- /dev/null +++ b/PuppetResources/ClassRoomExamples/template_ex/metadata.json @@ -0,0 +1,15 @@ +{ + "name": "asquarezone/template_ex", + "version": "0.1.0", + "author": "asquarezone", + "summary": null, + "license": "Apache-2.0", + "source": "", + "project_page": null, + "issues_url": null, + "dependencies": [ + {"name":"puppetlabs-stdlib","version_requirement":">= 1.0.0"} + ], + "data_provider": null +} + diff --git a/PuppetResources/ClassRoomExamples/template_ex/spec/classes/init_spec.rb b/PuppetResources/ClassRoomExamples/template_ex/spec/classes/init_spec.rb new file mode 100644 index 0000000..280bcc3 --- /dev/null +++ b/PuppetResources/ClassRoomExamples/template_ex/spec/classes/init_spec.rb @@ -0,0 +1,6 @@ +require 'spec_helper' +describe 'template_ex' do + context 'with default values for all parameters' do + it { should contain_class('template_ex') } + end +end diff --git a/PuppetResources/ClassRoomExamples/template_ex/spec/spec_helper.rb b/PuppetResources/ClassRoomExamples/template_ex/spec/spec_helper.rb new file mode 100644 index 0000000..2c6f566 --- /dev/null +++ b/PuppetResources/ClassRoomExamples/template_ex/spec/spec_helper.rb @@ -0,0 +1 @@ +require 'puppetlabs_spec_helper/module_spec_helper' diff --git a/PuppetResources/ClassRoomExamples/template_ex/templates/dummy.txt.epp b/PuppetResources/ClassRoomExamples/template_ex/templates/dummy.txt.epp new file mode 100644 index 0000000..11d2de2 --- /dev/null +++ b/PuppetResources/ClassRoomExamples/template_ex/templates/dummy.txt.epp @@ -0,0 +1,4 @@ +#This is managed by puppet +# Operating System is <%= $facts['os']['name'] %> +# FQDN is <%= $my_fqdn %> +# my processer is <%= $processer %> \ No newline at end of file diff --git a/PuppetResources/ClassRoomExamples/template_ex/templates/dummy.txt.erb b/PuppetResources/ClassRoomExamples/template_ex/templates/dummy.txt.erb new file mode 100644 index 0000000..0c03f11 --- /dev/null +++ b/PuppetResources/ClassRoomExamples/template_ex/templates/dummy.txt.erb @@ -0,0 +1,4 @@ +#This is managed by puppet +# Operating System is <%= @os_name %> +# FQDN is <%= @my_fqdn %> +# my ip address is <%= @ip_addr %> \ No newline at end of file diff --git a/PuppetResources/ClassRoomExamples/tomcat_install_example.pp b/PuppetResources/ClassRoomExamples/tomcat_install_example.pp new file mode 100644 index 0000000..12982e9 --- /dev/null +++ b/PuppetResources/ClassRoomExamples/tomcat_install_example.pp @@ -0,0 +1,17 @@ +$tomcat_pname = $facts['os']['family'] ? { + 'Redhat' => 'tomcat' , + 'Debian' => 'tomcat7' +} + +package { $tomcat_pname : + ensure => installed, +} + +service { $tomcat_pname: + ensure => running, + enable => true, +} + +service { $tomcat: + ensure => restart +} \ No newline at end of file diff --git a/PuppetResources/ClassRoomExamples/wget_example.pp b/PuppetResources/ClassRoomExamples/wget_example.pp new file mode 100644 index 0000000..c20457c --- /dev/null +++ b/PuppetResources/ClassRoomExamples/wget_example.pp @@ -0,0 +1,4 @@ + +file { '/tmp/nagios-4.1.1.tar.gz': + source => 'https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.1.1.tar.gz' + } diff --git a/PuppetResources/OtherExamples/cyclos/Gemfile b/PuppetResources/OtherExamples/cyclos/Gemfile new file mode 100644 index 0000000..4f662dc --- /dev/null +++ b/PuppetResources/OtherExamples/cyclos/Gemfile @@ -0,0 +1,18 @@ +source ENV['GEM_SOURCE'] || 'https://rubygems.org' + +puppetversion = ENV.key?('PUPPET_VERSION') ? ENV['PUPPET_VERSION'] : ['>= 3.3'] +gem 'metadata-json-lint' +gem 'puppet', puppetversion +gem 'puppetlabs_spec_helper', '>= 1.0.0' +gem 'puppet-lint', '>= 1.0.0' +gem 'facter', '>= 1.7.0' +gem 'rspec-puppet' + +# rspec must be v2 for ruby 1.8.7 +if RUBY_VERSION >= '1.8.7' && RUBY_VERSION < '1.9' + gem 'rspec', '~> 2.0' + gem 'rake', '~> 10.0' +else + # rubocop requires ruby >= 1.9 + gem 'rubocop' +end diff --git a/PuppetResources/OtherExamples/cyclos/README.md b/PuppetResources/OtherExamples/cyclos/README.md new file mode 100644 index 0000000..881c876 --- /dev/null +++ b/PuppetResources/OtherExamples/cyclos/README.md @@ -0,0 +1,83 @@ +# cyclos + +#### Table of Contents + +1. [Description](#description) +1. [Setup - The basics of getting started with cyclos](#setup) + * [What cyclos affects](#what-cyclos-affects) + * [Setup requirements](#setup-requirements) + * [Beginning with cyclos](#beginning-with-cyclos) +1. [Usage - Configuration options and additional functionality](#usage) +1. [Reference - An under-the-hood peek at what the module is doing and how](#reference) +1. [Limitations - OS compatibility, etc.](#limitations) +1. [Development - Guide for contributing to the module](#development) + +## Description + +Start with a one- or two-sentence summary of what the module does and/or what +problem it solves. This is your 30-second elevator pitch for your module. +Consider including OS/Puppet version it works with. + +You can give more descriptive information in a second paragraph. This paragraph +should answer the questions: "What does this module *do*?" and "Why would I use +it?" If your module has a range of functionality (installation, configuration, +management, etc.), this is the time to mention it. + +## Setup + +### What cyclos affects **OPTIONAL** + +If it's obvious what your module touches, you can skip this section. For +example, folks can probably figure out that your mysql_instance module affects +their MySQL instances. + +If there's more that they should know about, though, this is the place to mention: + +* A list of files, packages, services, or operations that the module will alter, + impact, or execute. +* Dependencies that your module automatically installs. +* Warnings or other important notices. + +### Setup Requirements **OPTIONAL** + +If your module requires anything extra before setting up (pluginsync enabled, +etc.), mention it here. + +If your most recent release breaks compatibility or requires particular steps +for upgrading, you might want to include an additional "Upgrading" section +here. + +### Beginning with cyclos + +The very basic steps needed for a user to get the module up and running. This +can include setup steps, if necessary, or it can be an example of the most +basic use of the module. + +## Usage + +This section is where you describe how to customize, configure, and do the +fancy stuff with your module here. It's especially helpful if you include usage +examples and code samples for doing things with your module. + +## Reference + +Here, include a complete list of your module's classes, types, providers, +facts, along with the parameters for each. Users refer to this section (thus +the name "Reference") to find specific details; most users don't read it per +se. + +## Limitations + +This is where you list OS compatibility, version compatibility, etc. If there +are Known Issues, you might want to include them under their own heading here. + +## Development + +Since your module is awesome, other users will want to play with it. Let them +know what the ground rules for contributing are. + +## Release Notes/Contributors/Etc. **Optional** + +If you aren't using changelog, put your release notes here (though you should +consider using changelog). You can also add any additional sections you feel +are necessary or important to include here. Please use the `## ` header. diff --git a/PuppetResources/OtherExamples/cyclos/Rakefile b/PuppetResources/OtherExamples/cyclos/Rakefile new file mode 100644 index 0000000..02609e3 --- /dev/null +++ b/PuppetResources/OtherExamples/cyclos/Rakefile @@ -0,0 +1,32 @@ +require 'puppetlabs_spec_helper/rake_tasks' +require 'puppet-lint/tasks/puppet-lint' +require 'metadata-json-lint/rake_task' + +if RUBY_VERSION >= '1.9' + require 'rubocop/rake_task' + RuboCop::RakeTask.new +end + +PuppetLint.configuration.send('disable_80chars') +PuppetLint.configuration.relative = true +PuppetLint.configuration.ignore_paths = ['spec/**/*.pp', 'pkg/**/*.pp'] + +desc 'Validate manifests, templates, and ruby files' +task :validate do + Dir['manifests/**/*.pp'].each do |manifest| + sh "puppet parser validate --noop #{manifest}" + end + Dir['spec/**/*.rb', 'lib/**/*.rb'].each do |ruby_file| + sh "ruby -c #{ruby_file}" unless ruby_file =~ %r{spec/fixtures} + end + Dir['templates/**/*.erb'].each do |template| + sh "erb -P -x -T '-' #{template} | ruby -c" + end +end + +desc 'Run metadata_lint, lint, validate, and spec tests.' +task :test do + [:metadata_lint, :lint, :validate, :spec].each do |test| + Rake::Task[test].invoke + end +end diff --git a/PuppetResources/OtherExamples/cyclos/examples/init.pp b/PuppetResources/OtherExamples/cyclos/examples/init.pp new file mode 100644 index 0000000..b27eef2 --- /dev/null +++ b/PuppetResources/OtherExamples/cyclos/examples/init.pp @@ -0,0 +1,12 @@ +# The baseline for module testing used by Puppet Labs is that each manifest +# should have a corresponding test manifest that declares that class or defined +# type. +# +# Tests are then run by using puppet apply --noop (to check for compilation +# errors and view a log of events) or by fully applying the test in a virtual +# environment (to compare the resulting system state to the desired state). +# +# Learn more about module testing here: +# https://docs.puppet.com/guides/tests_smoke.html +# +include ::cyclos diff --git a/PuppetResources/OtherExamples/cyclos/manifests/downloadcyclos.pp b/PuppetResources/OtherExamples/cyclos/manifests/downloadcyclos.pp new file mode 100644 index 0000000..e7e8543 --- /dev/null +++ b/PuppetResources/OtherExamples/cyclos/manifests/downloadcyclos.pp @@ -0,0 +1,8 @@ +class cyclos::downloadcyclos($install_path='/home/vagrant/cyclos_3.7.3.zip'){ + $cyclos_path = "https://downloads.sourceforge.net/project/cyclos/Cyclos3/3.7.3/cyclos_3.7.3.zip" + file { $install_path : + ensure => present , + source => $cyclos_path + } + +} \ No newline at end of file diff --git a/PuppetResources/OtherExamples/cyclos/manifests/init.pp b/PuppetResources/OtherExamples/cyclos/manifests/init.pp new file mode 100644 index 0000000..2e4f262 --- /dev/null +++ b/PuppetResources/OtherExamples/cyclos/manifests/init.pp @@ -0,0 +1,65 @@ +# Class: cyclos +# =========================== +# +# Full description of class cyclos here. +# +# Parameters +# ---------- +# +# Document parameters here. +# +# * `sample parameter` +# Explanation of what this parameter affects and what it defaults to. +# e.g. "Specify one or more upstream ntp servers as an array." +# +# Variables +# ---------- +# +# Here you should define a list of variables that this module would require. +# +# * `sample variable` +# Explanation of how this variable affects the function of this class and if +# it has a default. e.g. "The parameter enc_ntp_servers must be set by the +# External Node Classifier as a comma separated list of hostnames." (Note, +# global variables should be avoided in favor of class parameters as +# of Puppet 2.6.) +# +# Examples +# -------- +# +# @example +# class { 'cyclos': +# servers => [ 'pool.ntp.org', 'ntp.local.company.com' ], +# } +# +# Authors +# ------- +# +# Author Name +# +# Copyright +# --------- +# +# Copyright 2017 Your name here, unless otherwise noted. +# +# This module is developed based on documentation present @ https://www.cyclos.org/wiki/index.php/Installation_%26_maintenance +class cyclos { + + #install java based out of puppet forge puppetlabs/java and documentation @ https://forge.puppet.com/puppetlabs/java + include cyclos::install_java + + #install tomcat7 + include cyclos::install_tomcat + + #install mysql and configure root users default password + include cyclos::install_mysql + + #download cyclos + include cyclos::downloadcyclos + + + + + + +} diff --git a/PuppetResources/OtherExamples/cyclos/manifests/install_java.pp b/PuppetResources/OtherExamples/cyclos/manifests/install_java.pp new file mode 100644 index 0000000..366fc5f --- /dev/null +++ b/PuppetResources/OtherExamples/cyclos/manifests/install_java.pp @@ -0,0 +1,35 @@ +class cyclos::install_java { + + + if $facts['os']['name'] == 'Ubuntu' { + + class { 'apt': } + + package { "python-software-properties": } + + apt::ppa { 'ppa:webupd8team/java': } + + exec { + 'set-licence-selected': + command => '/bin/echo debconf shared/accepted-oracle-license-v1-1 select true | /usr/bin/debconf-set-selections'; + + 'set-licence-seen': + command => '/bin/echo debconf shared/accepted-oracle-license-v1-1 seen true | /usr/bin/debconf-set-selections'; + } + + package { 'oracle-java6-installer': + ensure => "installed", + require => [Apt::Ppa['ppa:webupd8team/java'], Exec['set-licence-selected'], Exec['set-licence-seen']], + } + + } + else { + java::oracle { 'jdk6': + ensure => 'present', + version => '6', + } + + } + + +} \ No newline at end of file diff --git a/PuppetResources/OtherExamples/cyclos/manifests/install_mysql.pp b/PuppetResources/OtherExamples/cyclos/manifests/install_mysql.pp new file mode 100644 index 0000000..c30bf4f --- /dev/null +++ b/PuppetResources/OtherExamples/cyclos/manifests/install_mysql.pp @@ -0,0 +1,31 @@ +class cyclos::install_mysql($default_password= 'p1234',$cyclos_db_password='cyclos1234') { + + #install mysql server + class {'mysql::server': + root_password => $default_password, + } + + #create user cyclos + mysql_user { 'cyclos@localhost': + ensure => present, + password_hash => mysql_password(cyclos_db_password), + } + + #create database cyclos + mysql::db { 'cyclos3': + ensure => present, + user => 'cyclos@localhost', + password => cyclos_db_password, + charset => 'utf8', + require => 'Class[mysql::server]', + } + + # grant previlages to cyclos + #grant all privileges on cyclos3.* to cyclos@localhost identified by 'cyclos1234'; + mysql_grant { 'cyclos@localhost/cyclos3.*': + user => 'cyclos@localhost', + table => 'cyclos3.*', + options => ['GRANT'], + privileges => ['ALL'], + } +} \ No newline at end of file diff --git a/PuppetResources/OtherExamples/cyclos/manifests/install_tomcat.pp b/PuppetResources/OtherExamples/cyclos/manifests/install_tomcat.pp new file mode 100644 index 0000000..2f4b782 --- /dev/null +++ b/PuppetResources/OtherExamples/cyclos/manifests/install_tomcat.pp @@ -0,0 +1,21 @@ +class cyclos::install_tomcat{ + + $tomcat_package_name= $facts['os']['family'] ? { + 'RedHat' => 'tomcat', + 'Debian' => 'tomcat7', + } + + package { $tomcat_package_name: + ensure => installed, + before => Service[$tomcat_package_name] + } + + service { $tomcat_package_name: + ensure => running, + enable => true, + hasrestart => true, + hasstatus => true, + # pattern => $tomcat_package_name, + } + +} \ No newline at end of file diff --git a/PuppetResources/OtherExamples/cyclos/metadata.json b/PuppetResources/OtherExamples/cyclos/metadata.json new file mode 100644 index 0000000..cffb882 --- /dev/null +++ b/PuppetResources/OtherExamples/cyclos/metadata.json @@ -0,0 +1,29 @@ +{ + "name": "asquarezone/cyclos", + "version": "0.1.0", + "author": "asquarezone", + "summary": "This module will be used to install cylcos", + "license": "Apache-2.0", + "source": "", + "project_page": null, + "issues_url": null, + "operatingsystem_support": [ + { + "operatingsystem":"RedHat", + "operatingsystemrelease":[ "6.0","7.0" ] + }, + { + "operatingsystem": "Ubuntu", + "operatingsystemrelease": [ "12.04", "14.04" ] + } + ], + "dependencies": [ + { "name":"puppetlabs-stdlib","version_requirement":">= 1.0.0" }, + { "name":"puppetlabs/java"}, + {"name":"puppet/archive"}, + {"name":"puppetlabs/mysql"}, + {"name":"puppetlabs/apt"} + ], + "data_provider": null +} + diff --git a/PuppetResources/OtherExamples/cyclos/spec/classes/init_spec.rb b/PuppetResources/OtherExamples/cyclos/spec/classes/init_spec.rb new file mode 100644 index 0000000..02c3f94 --- /dev/null +++ b/PuppetResources/OtherExamples/cyclos/spec/classes/init_spec.rb @@ -0,0 +1,6 @@ +require 'spec_helper' +describe 'cyclos' do + context 'with default values for all parameters' do + it { should contain_class('cyclos') } + end +end diff --git a/PuppetResources/OtherExamples/cyclos/spec/spec_helper.rb b/PuppetResources/OtherExamples/cyclos/spec/spec_helper.rb new file mode 100644 index 0000000..2c6f566 --- /dev/null +++ b/PuppetResources/OtherExamples/cyclos/spec/spec_helper.rb @@ -0,0 +1 @@ +require 'puppetlabs_spec_helper/module_spec_helper' diff --git a/PuppetResources/OtherExamples/ntp/examples/init.pp b/PuppetResources/OtherExamples/ntp/examples/init.pp new file mode 100644 index 0000000..9f87de7 --- /dev/null +++ b/PuppetResources/OtherExamples/ntp/examples/init.pp @@ -0,0 +1 @@ +include ntp diff --git a/PuppetResources/OtherExamples/ntp/files/london b/PuppetResources/OtherExamples/ntp/files/london new file mode 100644 index 0000000..c00dfc5 --- /dev/null +++ b/PuppetResources/OtherExamples/ntp/files/london @@ -0,0 +1,4 @@ +#Managed by puppet - do not edit +server 192.168.0.3 iburst prefer +server uk.pool.ntp.org +driftfile /var/lib/ntp/drift diff --git a/PuppetResources/OtherExamples/ntp/files/ntp.conf b/PuppetResources/OtherExamples/ntp/files/ntp.conf new file mode 100644 index 0000000..c00dfc5 --- /dev/null +++ b/PuppetResources/OtherExamples/ntp/files/ntp.conf @@ -0,0 +1,4 @@ +#Managed by puppet - do not edit +server 192.168.0.3 iburst prefer +server uk.pool.ntp.org +driftfile /var/lib/ntp/drift diff --git a/PuppetResources/OtherExamples/ntp/files/nyc b/PuppetResources/OtherExamples/ntp/files/nyc new file mode 100644 index 0000000..8d3ac7a --- /dev/null +++ b/PuppetResources/OtherExamples/ntp/files/nyc @@ -0,0 +1,4 @@ +#Managed by puppet - do not edit +server 192.168.0.3 iburst prefer +server us.pool.ntp.org +driftfile /var/lib/ntp/drift diff --git a/PuppetResources/OtherExamples/ntp/files/paris b/PuppetResources/OtherExamples/ntp/files/paris new file mode 100644 index 0000000..46bac27 --- /dev/null +++ b/PuppetResources/OtherExamples/ntp/files/paris @@ -0,0 +1,4 @@ +#Managed by puppet - do not edit +server 192.168.0.3 iburst prefer +server fr.pool.ntp.org +driftfile /var/lib/ntp/drift diff --git a/PuppetResources/OtherExamples/ntp/manifests/admin_file.pp b/PuppetResources/OtherExamples/ntp/manifests/admin_file.pp new file mode 100644 index 0000000..2a0f907 --- /dev/null +++ b/PuppetResources/OtherExamples/ntp/manifests/admin_file.pp @@ -0,0 +1,12 @@ +define ntp::admin_file { + include ntp::params + $admingroup = $ntp::params::admingroup + file { $title : + content => file('ntp/ntp.conf'), + owner => 'root', + group => $admingroup, + mode => '0664', + ensure => 'file', + notify => Class['ntp::service'], + } +} diff --git a/PuppetResources/OtherExamples/ntp/manifests/config.pp b/PuppetResources/OtherExamples/ntp/manifests/config.pp new file mode 100644 index 0000000..18bf93f --- /dev/null +++ b/PuppetResources/OtherExamples/ntp/manifests/config.pp @@ -0,0 +1,11 @@ +class ntp::config ( + $location = 'london', +) { + $valid_locations = [ + '^london$', + '^paris$', + '^nyc$', + ] + validate_re($location, $valid_locations) + ntp::admin_file{ '/etc/ntp.conf': } +} diff --git a/PuppetResources/OtherExamples/ntp/manifests/init.pp b/PuppetResources/OtherExamples/ntp/manifests/init.pp new file mode 100644 index 0000000..bd6280c --- /dev/null +++ b/PuppetResources/OtherExamples/ntp/manifests/init.pp @@ -0,0 +1,11 @@ +#Manage NTP on CentOS and Ubuntu hosts +class ntp { + + package { 'ntp': + before => Class['ntp::config'], + } + class { ntp::config: location => 'paris', } + include ntp::service + + + } diff --git a/PuppetResources/OtherExamples/ntp/manifests/params.pp b/PuppetResources/OtherExamples/ntp/manifests/params.pp new file mode 100644 index 0000000..a92ed71 --- /dev/null +++ b/PuppetResources/OtherExamples/ntp/manifests/params.pp @@ -0,0 +1,15 @@ +class ntp::params { + case $facts['os']['family'] { + 'RedHat': { + $ntp_service = 'ntpd' + $admingroup = 'wheel' + } + 'Debian': { + $ntp_service = 'ntp' + $admingroup = 'sudo' + } + default : { + fail("Your ${facts['os']['family']} is not supported") + } + } +} diff --git a/PuppetResources/OtherExamples/ntp/manifests/service.pp b/PuppetResources/OtherExamples/ntp/manifests/service.pp new file mode 100644 index 0000000..6dcd4a4 --- /dev/null +++ b/PuppetResources/OtherExamples/ntp/manifests/service.pp @@ -0,0 +1,10 @@ +class ntp::service ( + $ntp_service = $ntp::params::ntp_service, +) inherits ntp::params { + service {'NTP_Service': + ensure => 'running', + enable => true, + name => $ntp_service, + subscribe => Class['ntp::config'], + } +} diff --git a/PuppetResources/Practice/inline_template.pp b/PuppetResources/Practice/inline_template.pp new file mode 100644 index 0000000..552883f --- /dev/null +++ b/PuppetResources/Practice/inline_template.pp @@ -0,0 +1,12 @@ +$downtime = "17:00" + +$message = @(BEGIN) +welcome to the server: <%= @facts['networking']['fqdn'] %> +This is managed by puppet +The server will be shutdown <%= @downtime %> +BEGIN + +file { '/etc/motd' : + ensure => 'file' , + content => inline_template($message) +} \ No newline at end of file diff --git a/PuppetVM/.gitignore b/PuppetVM/.gitignore new file mode 100644 index 0000000..b93d2de --- /dev/null +++ b/PuppetVM/.gitignore @@ -0,0 +1,9 @@ + +# Created by https://www.gitignore.io/api/vag,vagrant + +#!! ERROR: vag is undefined. Use list command to see defined gitignore types !!# + +### Vagrant ### +.vagrant/ + +# End of https://www.gitignore.io/api/vag,vagrant diff --git a/PuppetVM/Centos7/Vagrantfile b/PuppetVM/Centos7/Vagrantfile new file mode 100644 index 0000000..4ef14d1 --- /dev/null +++ b/PuppetVM/Centos7/Vagrantfile @@ -0,0 +1,71 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : + +# All Vagrant configuration is done below. The "2" in Vagrant.configure +# configures the configuration version (we support older styles for +# backwards compatibility). Please don't change it unless you know what +# you're doing. +Vagrant.configure("2") do |config| + # The most common configuration options are documented and commented below. + # For a complete reference, please see the online documentation at + # https://docs.vagrantup.com. + + # Every Vagrant development environment requires a box. You can search for + # boxes at https://atlas.hashicorp.com/search. + config.vm.box = "centos/7" + + # Disable automatic box update checking. If you disable this, then + # boxes will only be checked for updates when the user runs + # `vagrant box outdated`. This is not recommended. + # config.vm.box_check_update = false + + # Create a forwarded port mapping which allows access to a specific port + # within the machine from a port on the host machine. In the example below, + # accessing "localhost:8080" will access port 80 on the guest machine. + # config.vm.network "forwarded_port", guest: 80, host: 8080 + + # Create a private network, which allows host-only access to the machine + # using a specific IP. + config.vm.network "private_network", ip: "192.168.33.16" + + # Create a public network, which generally matched to bridged network. + # Bridged networks make the machine appear as another physical device on + # your network. + # config.vm.network "public_network" + + # Share an additional folder to the guest VM. The first argument is + # the path on the host to the actual folder. The second argument is + # the path on the guest to mount the folder. And the optional third + # argument is a set of non-required options. + config.vm.synced_folder ".", "/vagrant", disabled: true + + # Provider-specific configuration so you can fine-tune various + # backing providers for Vagrant. These expose provider-specific options. + # Example for VirtualBox: + # + config.vm.provider "virtualbox" do |vb| + # # Display the VirtualBox GUI when booting the machine + # vb.gui = true + # + # # Customize the amount of memory on the VM: + vb.memory = "1024" + end + # + # View the documentation for the provider you are using for more + # information on available options. + + # Define a Vagrant Push strategy for pushing to Atlas. Other push strategies + # such as FTP and Heroku are also available. See the documentation at + # https://docs.vagrantup.com/v2/push/atlas.html for more information. + # config.push.define "atlas" do |push| + # push.app = "YOUR_ATLAS_USERNAME/YOUR_APPLICATION_NAME" + # end + + # Enable provisioning with a shell script. Additional provisioners such as + # Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the + # documentation for more information about their specific syntax and use. + config.vm.provision "shell", path: "provision.sh" + # apt-get update + # apt-get install -y apache2 + # SHELL +end diff --git a/PuppetVM/Centos7/provision.sh b/PuppetVM/Centos7/provision.sh new file mode 100644 index 0000000..ce6b5f9 --- /dev/null +++ b/PuppetVM/Centos7/provision.sh @@ -0,0 +1,3 @@ +sudo yum -y update +sudo yum -y install http://yum.puppetlabs.com/puppetlabs-release-pc1-el-7.noarch.rpm +sudo yum -y install puppet-agent diff --git a/PuppetVM/Ubuntu14/Vagrantfile b/PuppetVM/Ubuntu14/Vagrantfile new file mode 100644 index 0000000..af51f98 --- /dev/null +++ b/PuppetVM/Ubuntu14/Vagrantfile @@ -0,0 +1,71 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : + +# All Vagrant configuration is done below. The "2" in Vagrant.configure +# configures the configuration version (we support older styles for +# backwards compatibility). Please don't change it unless you know what +# you're doing. +Vagrant.configure("2") do |config| + # The most common configuration options are documented and commented below. + # For a complete reference, please see the online documentation at + # https://docs.vagrantup.com. + + # Every Vagrant development environment requires a box. You can search for + # boxes at https://atlas.hashicorp.com/search. + config.vm.box = "ubuntu/trusty64" + + # Disable automatic box update checking. If you disable this, then + # boxes will only be checked for updates when the user runs + # `vagrant box outdated`. This is not recommended. + # config.vm.box_check_update = false + + # Create a forwarded port mapping which allows access to a specific port + # within the machine from a port on the host machine. In the example below, + # accessing "localhost:8080" will access port 80 on the guest machine. + # config.vm.network "forwarded_port", guest: 80, host: 8080 + + # Create a private network, which allows host-only access to the machine + # using a specific IP. + config.vm.network "private_network", ip: "192.168.33.17" + + # Create a public network, which generally matched to bridged network. + # Bridged networks make the machine appear as another physical device on + # your network. + # config.vm.network "public_network" + + # Share an additional folder to the guest VM. The first argument is + # the path on the host to the actual folder. The second argument is + # the path on the guest to mount the folder. And the optional third + # argument is a set of non-required options. + # config.vm.synced_folder "../data", "/vagrant_data" + + # Provider-specific configuration so you can fine-tune various + # backing providers for Vagrant. These expose provider-specific options. + # Example for VirtualBox: + # + config.vm.provider "virtualbox" do |vb| + # # Display the VirtualBox GUI when booting the machine + # vb.gui = true + # + # # Customize the amount of memory on the VM: + vb.memory = "1024" + end + # + # View the documentation for the provider you are using for more + # information on available options. + + # Define a Vagrant Push strategy for pushing to Atlas. Other push strategies + # such as FTP and Heroku are also available. See the documentation at + # https://docs.vagrantup.com/v2/push/atlas.html for more information. + # config.push.define "atlas" do |push| + # push.app = "YOUR_ATLAS_USERNAME/YOUR_APPLICATION_NAME" + # end + + # Enable provisioning with a shell script. Additional provisioners such as + # Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the + # documentation for more information about their specific syntax and use. + config.vm.provision "shell", path: "provision.sh" + # apt-get update + # apt-get install -y apache2 + # SHELL +end diff --git a/PuppetVM/Ubuntu14/provision.sh b/PuppetVM/Ubuntu14/provision.sh new file mode 100644 index 0000000..9801dc4 --- /dev/null +++ b/PuppetVM/Ubuntu14/provision.sh @@ -0,0 +1,5 @@ +sudo apt-get -y update +sudo wget https://apt.puppetlabs.com/puppetlabs-release-pc1-trusty.deb +sudo dpkg -i puppetlabs-release-pc1-trusty.deb +sudo apt-get -y update +sudo apt-get -y install puppet-agent