From 7cdd934c721a5d73b2374045137294d19b8f30c8 Mon Sep 17 00:00:00 2001 From: shaikkhajaibrahim Date: Sat, 21 Jan 2017 09:54:32 +0530 Subject: [PATCH 01/27] Added branch and examples for batch 4 --- .../ClassRoomExamples/case_example.pp | 24 +++++++++++++++++++ .../ClassRoomExamples/if_example.pp | 12 ++++++++++ 2 files changed, 36 insertions(+) create mode 100644 PuppetResources/ClassRoomExamples/case_example.pp create mode 100644 PuppetResources/ClassRoomExamples/if_example.pp 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/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']}": } +} From e0386c813cda47b19573c10041160524393dfb64 Mon Sep 17 00:00:00 2001 From: shaikkhajaibrahim Date: Sat, 21 Jan 2017 10:11:55 +0530 Subject: [PATCH 02/27] Added selector example --- .../ClassRoomExamples/selector_example.pp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 PuppetResources/ClassRoomExamples/selector_example.pp 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: } + From c6ad08b9f32c3e432ea6d2c83075bd51c5825402 Mon Sep 17 00:00:00 2001 From: shaikkhajaibrahim Date: Sat, 21 Jan 2017 10:38:39 +0530 Subject: [PATCH 03/27] Added tomcat install --- .../ClassRoomExamples/tomcat_install_example.pp | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 PuppetResources/ClassRoomExamples/tomcat_install_example.pp diff --git a/PuppetResources/ClassRoomExamples/tomcat_install_example.pp b/PuppetResources/ClassRoomExamples/tomcat_install_example.pp new file mode 100644 index 0000000..d3dd67a --- /dev/null +++ b/PuppetResources/ClassRoomExamples/tomcat_install_example.pp @@ -0,0 +1,13 @@ +$tomcat_pname = $facts['os']['family'] ? { + 'Redhat' => 'tomcat' , + 'Debian' => 'tomcat7' +} + +package { $tomcat_pname : + ensure => installed, +} + +service { $tomcat_pname: + ensure => running, + enable => true, +} \ No newline at end of file From 7b68c70a40db156fb09815f5652db9e48d577b7c Mon Sep 17 00:00:00 2001 From: shaikkhajaibrahim Date: Mon, 23 Jan 2017 08:16:42 +0530 Subject: [PATCH 04/27] Added new files for rr --- .../ClassRoomExamples/nagios_install_example.pp | 0 .../ClassRoomExamples/remove_package.pp | 6 ++++++ .../resource_relations_example.pp | 15 +++++++++++++++ 3 files changed, 21 insertions(+) create mode 100644 PuppetResources/ClassRoomExamples/nagios_install_example.pp create mode 100644 PuppetResources/ClassRoomExamples/remove_package.pp create mode 100644 PuppetResources/ClassRoomExamples/resource_relations_example.pp diff --git a/PuppetResources/ClassRoomExamples/nagios_install_example.pp b/PuppetResources/ClassRoomExamples/nagios_install_example.pp new file mode 100644 index 0000000..e69de29 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 From ab4a7345b9eba1b8f92fe6fd514c667a3365bb7d Mon Sep 17 00:00:00 2001 From: shaikkhajaibrahim Date: Mon, 23 Jan 2017 08:47:59 +0530 Subject: [PATCH 05/27] Added wget --- PuppetResources/ClassRoomExamples/wget_example.pp | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 PuppetResources/ClassRoomExamples/wget_example.pp 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' + } From 9ceff3e493c7b963a60108ae010c9f15b5b70727 Mon Sep 17 00:00:00 2001 From: shaikkhajaibrahim Date: Wed, 25 Jan 2017 07:54:47 +0530 Subject: [PATCH 06/27] Added defined resources --- .../definedresource_example.pp | 36 +++++++++++++++++++ .../nagios_install_example.pp | 11 ++++++ .../tomcat_install_example.pp | 4 +++ 3 files changed, 51 insertions(+) create mode 100644 PuppetResources/ClassRoomExamples/definedresource_example.pp 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/nagios_install_example.pp b/PuppetResources/ClassRoomExamples/nagios_install_example.pp index e69de29..22df22d 100644 --- a/PuppetResources/ClassRoomExamples/nagios_install_example.pp +++ 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/tomcat_install_example.pp b/PuppetResources/ClassRoomExamples/tomcat_install_example.pp index d3dd67a..12982e9 100644 --- a/PuppetResources/ClassRoomExamples/tomcat_install_example.pp +++ b/PuppetResources/ClassRoomExamples/tomcat_install_example.pp @@ -10,4 +10,8 @@ service { $tomcat_pname: ensure => running, enable => true, +} + +service { $tomcat: + ensure => restart } \ No newline at end of file From 2ad9efee8d78ddeb25041cd02235fab29a0114ee Mon Sep 17 00:00:00 2001 From: shaikkhajaibrahim Date: Wed, 25 Jan 2017 08:40:22 +0530 Subject: [PATCH 07/27] added module --- .../appserver_tomcat/Gemfile | 18 ++++ .../appserver_tomcat/README.md | 83 +++++++++++++++++++ .../appserver_tomcat/Rakefile | 32 +++++++ .../appserver_tomcat/examples/init.pp | 12 +++ .../appserver_tomcat/manifests/init.pp | 58 +++++++++++++ .../appserver_tomcat/manifests/service.pp | 20 +++++ .../appserver_tomcat/manifests/usersconfig.pp | 8 ++ .../appserver_tomcat/metadata.json | 15 ++++ .../spec/classes/init_spec.rb | 6 ++ .../appserver_tomcat/spec/spec_helper.rb | 1 + 10 files changed, 253 insertions(+) create mode 100644 PuppetResources/ClassRoomExamples/appserver_tomcat/Gemfile create mode 100644 PuppetResources/ClassRoomExamples/appserver_tomcat/README.md create mode 100644 PuppetResources/ClassRoomExamples/appserver_tomcat/Rakefile create mode 100644 PuppetResources/ClassRoomExamples/appserver_tomcat/examples/init.pp create mode 100644 PuppetResources/ClassRoomExamples/appserver_tomcat/manifests/init.pp create mode 100644 PuppetResources/ClassRoomExamples/appserver_tomcat/manifests/service.pp create mode 100644 PuppetResources/ClassRoomExamples/appserver_tomcat/manifests/usersconfig.pp create mode 100644 PuppetResources/ClassRoomExamples/appserver_tomcat/metadata.json create mode 100644 PuppetResources/ClassRoomExamples/appserver_tomcat/spec/classes/init_spec.rb create mode 100644 PuppetResources/ClassRoomExamples/appserver_tomcat/spec/spec_helper.rb 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..0550878 --- /dev/null +++ b/PuppetResources/ClassRoomExamples/appserver_tomcat/manifests/init.pp @@ -0,0 +1,58 @@ +# 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', + } + + package { $package_name: + ensure => installed, + + } + + + +} diff --git a/PuppetResources/ClassRoomExamples/appserver_tomcat/manifests/service.pp b/PuppetResources/ClassRoomExamples/appserver_tomcat/manifests/service.pp new file mode 100644 index 0000000..2663564 --- /dev/null +++ b/PuppetResources/ClassRoomExamples/appserver_tomcat/manifests/service.pp @@ -0,0 +1,20 @@ +# Class: service +# +# +class appserver_tomcat::service { + # resources + $package_name = $facts['os']['family']?{ + 'RedHat' => 'tomcat', + 'Debian' => 'tomcat7', + } + +# This resource enables the tomcat service + + service { $package_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..a9fdef5 --- /dev/null +++ b/PuppetResources/ClassRoomExamples/appserver_tomcat/manifests/usersconfig.pp @@ -0,0 +1,8 @@ +# Class usersconfig +# +# +class appserver_tomcat::usersconfig { + # resources + + +} \ 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' From 4e97391a734f9d92ef9568af2bf6eaf87e4d001d Mon Sep 17 00:00:00 2001 From: shaikkhajaibrahim Date: Wed, 25 Jan 2017 12:25:38 +0530 Subject: [PATCH 08/27] Added Vagrant Machines for puppet VMS --- PuppetVM/.gitignore | 9 +++++ PuppetVM/Centos7/Vagrantfile | 71 ++++++++++++++++++++++++++++++++++ PuppetVM/Centos7/provision.sh | 3 ++ PuppetVM/Ubuntu14/Vagrantfile | 71 ++++++++++++++++++++++++++++++++++ PuppetVM/Ubuntu14/provision.sh | 5 +++ 5 files changed, 159 insertions(+) create mode 100644 PuppetVM/.gitignore create mode 100644 PuppetVM/Centos7/Vagrantfile create mode 100644 PuppetVM/Centos7/provision.sh create mode 100644 PuppetVM/Ubuntu14/Vagrantfile create mode 100644 PuppetVM/Ubuntu14/provision.sh 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 From 78548a17ad937de04f16ee28ae7148faf119674e Mon Sep 17 00:00:00 2001 From: shaikkhajaibrahim Date: Thu, 26 Jan 2017 08:51:47 +0530 Subject: [PATCH 09/27] Added motd --- .../ClassRoomExamples/motd/Gemfile | 18 ++++ .../ClassRoomExamples/motd/README.md | 83 +++++++++++++++++++ .../ClassRoomExamples/motd/Rakefile | 32 +++++++ .../ClassRoomExamples/motd/examples/init.pp | 12 +++ .../ClassRoomExamples/motd/manifests/init.pp | 57 +++++++++++++ .../motd/spec/classes/init_spec.rb | 6 ++ .../ClassRoomExamples/motd/spec/metadata.json | 15 ++++ .../motd/spec/spec_helper.rb | 1 + 8 files changed, 224 insertions(+) create mode 100644 PuppetResources/ClassRoomExamples/motd/Gemfile create mode 100644 PuppetResources/ClassRoomExamples/motd/README.md create mode 100644 PuppetResources/ClassRoomExamples/motd/Rakefile create mode 100644 PuppetResources/ClassRoomExamples/motd/examples/init.pp create mode 100644 PuppetResources/ClassRoomExamples/motd/manifests/init.pp create mode 100644 PuppetResources/ClassRoomExamples/motd/spec/classes/init_spec.rb create mode 100644 PuppetResources/ClassRoomExamples/motd/spec/metadata.json create mode 100644 PuppetResources/ClassRoomExamples/motd/spec/spec_helper.rb diff --git a/PuppetResources/ClassRoomExamples/motd/Gemfile b/PuppetResources/ClassRoomExamples/motd/Gemfile new file mode 100644 index 0000000..4f662dc --- /dev/null +++ b/PuppetResources/ClassRoomExamples/motd/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/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/manifests/init.pp b/PuppetResources/ClassRoomExamples/motd/manifests/init.pp new file mode 100644 index 0000000..77995ae --- /dev/null +++ b/PuppetResources/ClassRoomExamples/motd/manifests/init.pp @@ -0,0 +1,57 @@ +# 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 { + + file { '/etc/motd': + ensure => file, + #owner => owner, + #group => group, + #mode => mode, + #source => 'puppet:///modules/class/file.txt'; + content => "This is managed by puppet", + } + + +} 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' From c38c3d077d3213a5071cdd3d5ce6e2f398607f3e Mon Sep 17 00:00:00 2001 From: shaikkhajaibrahim Date: Thu, 26 Jan 2017 09:38:20 +0530 Subject: [PATCH 10/27] Added subclass_ex --- .../ClassRoomExamples/motd/files/message | 4 + .../ClassRoomExamples/motd/manifests/init.pp | 7 +- .../motd/{ => spec/classes}/Gemfile | 0 .../ClassRoomExamples/subclass_ex/Gemfile | 18 ++++ .../ClassRoomExamples/subclass_ex/README.md | 83 +++++++++++++++++++ .../ClassRoomExamples/subclass_ex/Rakefile | 32 +++++++ .../subclass_ex/examples/init.pp | 12 +++ .../subclass_ex/manifests/init.pp | 50 +++++++++++ .../subclass_ex/manifests/install.pp | 14 ++++ .../subclass_ex/manifests/myservice.pp | 9 ++ .../subclass_ex/metadata.json | 15 ++++ .../subclass_ex/spec/classes/init_spec.rb | 6 ++ .../subclass_ex/spec/spec_helper.rb | 1 + 13 files changed, 250 insertions(+), 1 deletion(-) create mode 100644 PuppetResources/ClassRoomExamples/motd/files/message rename PuppetResources/ClassRoomExamples/motd/{ => spec/classes}/Gemfile (100%) create mode 100644 PuppetResources/ClassRoomExamples/subclass_ex/Gemfile create mode 100644 PuppetResources/ClassRoomExamples/subclass_ex/README.md create mode 100644 PuppetResources/ClassRoomExamples/subclass_ex/Rakefile create mode 100644 PuppetResources/ClassRoomExamples/subclass_ex/examples/init.pp create mode 100644 PuppetResources/ClassRoomExamples/subclass_ex/manifests/init.pp create mode 100644 PuppetResources/ClassRoomExamples/subclass_ex/manifests/install.pp create mode 100644 PuppetResources/ClassRoomExamples/subclass_ex/manifests/myservice.pp create mode 100644 PuppetResources/ClassRoomExamples/subclass_ex/metadata.json create mode 100644 PuppetResources/ClassRoomExamples/subclass_ex/spec/classes/init_spec.rb create mode 100644 PuppetResources/ClassRoomExamples/subclass_ex/spec/spec_helper.rb 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 index 77995ae..7cb1b5f 100644 --- a/PuppetResources/ClassRoomExamples/motd/manifests/init.pp +++ b/PuppetResources/ClassRoomExamples/motd/manifests/init.pp @@ -44,13 +44,18 @@ # class motd { + $my_message = @("BEGIN") + This is my message + This is managed by puppet + BEGIN + file { '/etc/motd': ensure => file, #owner => owner, #group => group, #mode => mode, #source => 'puppet:///modules/class/file.txt'; - content => "This is managed by puppet", + content => file('motd/message'), } diff --git a/PuppetResources/ClassRoomExamples/motd/Gemfile b/PuppetResources/ClassRoomExamples/motd/spec/classes/Gemfile similarity index 100% rename from PuppetResources/ClassRoomExamples/motd/Gemfile rename to PuppetResources/ClassRoomExamples/motd/spec/classes/Gemfile 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..70785ca --- /dev/null +++ b/PuppetResources/ClassRoomExamples/subclass_ex/manifests/install.pp @@ -0,0 +1,14 @@ +# Class: install +# +# +class subclass_ex::install { + # resources + + package { 'tomcat': + 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..afaa4a5 --- /dev/null +++ b/PuppetResources/ClassRoomExamples/subclass_ex/manifests/myservice.pp @@ -0,0 +1,9 @@ +class myservice { + service { "tomcat": + ensure => running, + enable => true, + hasrestart => true, + hasstatus => true, + # pattern => 'tomcat', + } +} \ 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' From 0616d816226639550ce2dc4f1450a0af3fef4f1d Mon Sep 17 00:00:00 2001 From: shaikkhajaibrahim Date: Fri, 27 Jan 2017 08:02:42 +0530 Subject: [PATCH 11/27] Added Parameters demo module --- .../ClassRoomExamples/params_demo/Gemfile | 18 ++++ .../ClassRoomExamples/params_demo/README.md | 83 +++++++++++++++++++ .../ClassRoomExamples/params_demo/Rakefile | 32 +++++++ .../params_demo/examples/init.pp | 12 +++ .../params_demo/manifests/display_message.pp | 4 + .../params_demo/manifests/init.pp | 48 +++++++++++ .../params_demo/metadata.json | 15 ++++ .../params_demo/spec/classes/init_spec.rb | 6 ++ .../params_demo/spec/spec_helper.rb | 1 + 9 files changed, 219 insertions(+) create mode 100644 PuppetResources/ClassRoomExamples/params_demo/Gemfile create mode 100644 PuppetResources/ClassRoomExamples/params_demo/README.md create mode 100644 PuppetResources/ClassRoomExamples/params_demo/Rakefile create mode 100644 PuppetResources/ClassRoomExamples/params_demo/examples/init.pp create mode 100644 PuppetResources/ClassRoomExamples/params_demo/manifests/display_message.pp create mode 100644 PuppetResources/ClassRoomExamples/params_demo/manifests/init.pp create mode 100644 PuppetResources/ClassRoomExamples/params_demo/metadata.json create mode 100644 PuppetResources/ClassRoomExamples/params_demo/spec/classes/init_spec.rb create mode 100644 PuppetResources/ClassRoomExamples/params_demo/spec/spec_helper.rb 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..61a0a0c --- /dev/null +++ b/PuppetResources/ClassRoomExamples/params_demo/manifests/init.pp @@ -0,0 +1,48 @@ +# 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 { + include params_demo::display_message + +} 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' From 51523de623511a3c507201e84e607d268db2fdaf Mon Sep 17 00:00:00 2001 From: shaikkhajaibrahim Date: Fri, 27 Jan 2017 08:36:12 +0530 Subject: [PATCH 12/27] Added params_demo and parametrized tomcat --- .../appserver_tomcat/manifests/init.pp | 14 +++++++++++--- .../appserver_tomcat/manifests/install.pp | 8 ++++++++ .../appserver_tomcat/manifests/service.pp | 8 ++------ .../params_demo/manifests/init.pp | 8 +++++++- 4 files changed, 28 insertions(+), 10 deletions(-) create mode 100644 PuppetResources/ClassRoomExamples/appserver_tomcat/manifests/install.pp diff --git a/PuppetResources/ClassRoomExamples/appserver_tomcat/manifests/init.pp b/PuppetResources/ClassRoomExamples/appserver_tomcat/manifests/init.pp index 0550878..adbaa28 100644 --- a/PuppetResources/ClassRoomExamples/appserver_tomcat/manifests/init.pp +++ b/PuppetResources/ClassRoomExamples/appserver_tomcat/manifests/init.pp @@ -48,9 +48,17 @@ 'Debian' => 'tomcat7', } - package { $package_name: - ensure => installed, - + 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 , + } diff --git a/PuppetResources/ClassRoomExamples/appserver_tomcat/manifests/install.pp b/PuppetResources/ClassRoomExamples/appserver_tomcat/manifests/install.pp new file mode 100644 index 0000000..928ff36 --- /dev/null +++ b/PuppetResources/ClassRoomExamples/appserver_tomcat/manifests/install.pp @@ -0,0 +1,8 @@ +class appserver_tomcat::install ($package_name,$install_message) { + package { $package_name: + ensure => installed, + } + + notify { $install_message: } + +} \ No newline at end of file diff --git a/PuppetResources/ClassRoomExamples/appserver_tomcat/manifests/service.pp b/PuppetResources/ClassRoomExamples/appserver_tomcat/manifests/service.pp index 2663564..4810757 100644 --- a/PuppetResources/ClassRoomExamples/appserver_tomcat/manifests/service.pp +++ b/PuppetResources/ClassRoomExamples/appserver_tomcat/manifests/service.pp @@ -1,12 +1,8 @@ # Class: service # # -class appserver_tomcat::service { - # resources - $package_name = $facts['os']['family']?{ - 'RedHat' => 'tomcat', - 'Debian' => 'tomcat7', - } +class appserver_tomcat::service ($package_name) { + # This resource enables the tomcat service diff --git a/PuppetResources/ClassRoomExamples/params_demo/manifests/init.pp b/PuppetResources/ClassRoomExamples/params_demo/manifests/init.pp index 61a0a0c..0e6b3bd 100644 --- a/PuppetResources/ClassRoomExamples/params_demo/manifests/init.pp +++ b/PuppetResources/ClassRoomExamples/params_demo/manifests/init.pp @@ -43,6 +43,12 @@ # Copyright 2017 Your name here, unless otherwise noted. # class params_demo { - include params_demo::display_message + # 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" + } } From 3f4473e1e4b9a80fc749801dbcea059713793281 Mon Sep 17 00:00:00 2001 From: shaikkhajaibrahim Date: Fri, 27 Jan 2017 08:58:52 +0530 Subject: [PATCH 13/27] Inheritance --- .../appserver_tomcat/manifests/init.pp | 28 +++++++++++-------- .../appserver_tomcat/manifests/install.pp | 5 +++- .../appserver_tomcat/manifests/params.pp | 10 +++++++ .../appserver_tomcat/manifests/service.pp | 7 +++-- 4 files changed, 35 insertions(+), 15 deletions(-) create mode 100644 PuppetResources/ClassRoomExamples/appserver_tomcat/manifests/params.pp diff --git a/PuppetResources/ClassRoomExamples/appserver_tomcat/manifests/init.pp b/PuppetResources/ClassRoomExamples/appserver_tomcat/manifests/init.pp index adbaa28..c269e3c 100644 --- a/PuppetResources/ClassRoomExamples/appserver_tomcat/manifests/init.pp +++ b/PuppetResources/ClassRoomExamples/appserver_tomcat/manifests/init.pp @@ -43,23 +43,27 @@ # 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 " +# $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 , + # 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 index 928ff36..e2c4ff0 100644 --- a/PuppetResources/ClassRoomExamples/appserver_tomcat/manifests/install.pp +++ b/PuppetResources/ClassRoomExamples/appserver_tomcat/manifests/install.pp @@ -1,4 +1,7 @@ -class appserver_tomcat::install ($package_name,$install_message) { +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, } 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 index 4810757..203282d 100644 --- a/PuppetResources/ClassRoomExamples/appserver_tomcat/manifests/service.pp +++ b/PuppetResources/ClassRoomExamples/appserver_tomcat/manifests/service.pp @@ -1,12 +1,15 @@ # Class: service # # -class appserver_tomcat::service ($package_name) { +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 { $package_name: + service { $service_name: ensure => running, enable => true, hasrestart => true, From 591fc9fb8a252770d91a10f72a378990f1bcf530 Mon Sep 17 00:00:00 2001 From: shaikkhajaibrahim Date: Fri, 27 Jan 2017 12:09:20 +0530 Subject: [PATCH 14/27] Added ntp --- PuppetResources/OtherExamples/ntp/Gemfile | 18 ++++ PuppetResources/OtherExamples/ntp/README.md | 83 +++++++++++++++++++ PuppetResources/OtherExamples/ntp/Rakefile | 32 +++++++ .../OtherExamples/ntp/examples/init.pp | 12 +++ .../OtherExamples/ntp/files/london | 4 + .../OtherExamples/ntp/files/ntp.conf | 4 + PuppetResources/OtherExamples/ntp/files/nyc | 4 + PuppetResources/OtherExamples/ntp/files/paris | 4 + .../OtherExamples/ntp/manifests/admin_file.pp | 12 +++ .../OtherExamples/ntp/manifests/config.pp | 11 +++ .../OtherExamples/ntp/manifests/init.pp | 11 +++ .../OtherExamples/ntp/manifests/params.pp | 15 ++++ .../OtherExamples/ntp/manifests/service.pp | 10 +++ .../OtherExamples/ntp/metadata.json | 15 ++++ .../ntp/spec/classes/init_spec.rb | 6 ++ .../OtherExamples/ntp/spec/spec_helper.rb | 1 + 16 files changed, 242 insertions(+) create mode 100644 PuppetResources/OtherExamples/ntp/Gemfile create mode 100644 PuppetResources/OtherExamples/ntp/README.md create mode 100644 PuppetResources/OtherExamples/ntp/Rakefile create mode 100644 PuppetResources/OtherExamples/ntp/examples/init.pp create mode 100644 PuppetResources/OtherExamples/ntp/files/london create mode 100644 PuppetResources/OtherExamples/ntp/files/ntp.conf create mode 100644 PuppetResources/OtherExamples/ntp/files/nyc create mode 100644 PuppetResources/OtherExamples/ntp/files/paris create mode 100644 PuppetResources/OtherExamples/ntp/manifests/admin_file.pp create mode 100644 PuppetResources/OtherExamples/ntp/manifests/config.pp create mode 100644 PuppetResources/OtherExamples/ntp/manifests/init.pp create mode 100644 PuppetResources/OtherExamples/ntp/manifests/params.pp create mode 100644 PuppetResources/OtherExamples/ntp/manifests/service.pp create mode 100644 PuppetResources/OtherExamples/ntp/metadata.json create mode 100644 PuppetResources/OtherExamples/ntp/spec/classes/init_spec.rb create mode 100644 PuppetResources/OtherExamples/ntp/spec/spec_helper.rb diff --git a/PuppetResources/OtherExamples/ntp/Gemfile b/PuppetResources/OtherExamples/ntp/Gemfile new file mode 100644 index 0000000..4f662dc --- /dev/null +++ b/PuppetResources/OtherExamples/ntp/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/ntp/README.md b/PuppetResources/OtherExamples/ntp/README.md new file mode 100644 index 0000000..68dfe10 --- /dev/null +++ b/PuppetResources/OtherExamples/ntp/README.md @@ -0,0 +1,83 @@ +# ntp + +#### Table of Contents + +1. [Description](#description) +1. [Setup - The basics of getting started with ntp](#setup) + * [What ntp affects](#what-ntp-affects) + * [Setup requirements](#setup-requirements) + * [Beginning with ntp](#beginning-with-ntp) +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 ntp 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 ntp + +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/ntp/Rakefile b/PuppetResources/OtherExamples/ntp/Rakefile new file mode 100644 index 0000000..02609e3 --- /dev/null +++ b/PuppetResources/OtherExamples/ntp/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/ntp/examples/init.pp b/PuppetResources/OtherExamples/ntp/examples/init.pp new file mode 100644 index 0000000..388623c --- /dev/null +++ b/PuppetResources/OtherExamples/ntp/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 ::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/OtherExamples/ntp/metadata.json b/PuppetResources/OtherExamples/ntp/metadata.json new file mode 100644 index 0000000..f5ea510 --- /dev/null +++ b/PuppetResources/OtherExamples/ntp/metadata.json @@ -0,0 +1,15 @@ +{ + "name": "asquarezone/ntp", + "version": "0.1.0", + "author": "asquarezone", + "summary": "This module deals with ntp server", + "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/OtherExamples/ntp/spec/classes/init_spec.rb b/PuppetResources/OtherExamples/ntp/spec/classes/init_spec.rb new file mode 100644 index 0000000..d42681a --- /dev/null +++ b/PuppetResources/OtherExamples/ntp/spec/classes/init_spec.rb @@ -0,0 +1,6 @@ +require 'spec_helper' +describe 'ntp' do + context 'with default values for all parameters' do + it { should contain_class('ntp') } + end +end diff --git a/PuppetResources/OtherExamples/ntp/spec/spec_helper.rb b/PuppetResources/OtherExamples/ntp/spec/spec_helper.rb new file mode 100644 index 0000000..2c6f566 --- /dev/null +++ b/PuppetResources/OtherExamples/ntp/spec/spec_helper.rb @@ -0,0 +1 @@ +require 'puppetlabs_spec_helper/module_spec_helper' From 8162be8f902861a7a6b5abb40f51bf058b4455ea Mon Sep 17 00:00:00 2001 From: shaikkhajaibrahim Date: Fri, 27 Jan 2017 12:24:35 +0530 Subject: [PATCH 15/27] Added inline template example --- .../OtherExamples/ntp/manifests/admin_file.pp | 2 +- .../OtherExamples/ntp/manifests/config.pp | 5 ++++- PuppetResources/Practice/inline_template.pp | 12 ++++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 PuppetResources/Practice/inline_template.pp diff --git a/PuppetResources/OtherExamples/ntp/manifests/admin_file.pp b/PuppetResources/OtherExamples/ntp/manifests/admin_file.pp index 2a0f907..1d461ea 100644 --- a/PuppetResources/OtherExamples/ntp/manifests/admin_file.pp +++ b/PuppetResources/OtherExamples/ntp/manifests/admin_file.pp @@ -1,4 +1,4 @@ -define ntp::admin_file { +define ntp::admin_file($ntp_location='london') { include ntp::params $admingroup = $ntp::params::admingroup file { $title : diff --git a/PuppetResources/OtherExamples/ntp/manifests/config.pp b/PuppetResources/OtherExamples/ntp/manifests/config.pp index 18bf93f..fd39797 100644 --- a/PuppetResources/OtherExamples/ntp/manifests/config.pp +++ b/PuppetResources/OtherExamples/ntp/manifests/config.pp @@ -7,5 +7,8 @@ '^nyc$', ] validate_re($location, $valid_locations) - ntp::admin_file{ '/etc/ntp.conf': } + ntp::admin_file { + '/etc/ntp.conf': + ntp_location => $location , + } } 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 From 6d201a045a7554bdecbf618905596740d51089b1 Mon Sep 17 00:00:00 2001 From: shaikkhajaibrahim Date: Fri, 27 Jan 2017 12:52:01 +0530 Subject: [PATCH 16/27] Added cyclos implementation --- PuppetResources/OtherExamples/cyclos/Gemfile | 18 ++++ .../OtherExamples/cyclos/README.md | 83 +++++++++++++++++++ PuppetResources/OtherExamples/cyclos/Rakefile | 32 +++++++ .../OtherExamples/cyclos/examples/init.pp | 12 +++ .../cyclos/manifests/downloadcyclos.pp | 8 ++ .../OtherExamples/cyclos/manifests/init.pp | 61 ++++++++++++++ .../OtherExamples/cyclos/metadata.json | 15 ++++ .../cyclos/spec/classes/init_spec.rb | 6 ++ .../OtherExamples/cyclos/spec/spec_helper.rb | 1 + 9 files changed, 236 insertions(+) create mode 100644 PuppetResources/OtherExamples/cyclos/Gemfile create mode 100644 PuppetResources/OtherExamples/cyclos/README.md create mode 100644 PuppetResources/OtherExamples/cyclos/Rakefile create mode 100644 PuppetResources/OtherExamples/cyclos/examples/init.pp create mode 100644 PuppetResources/OtherExamples/cyclos/manifests/downloadcyclos.pp create mode 100644 PuppetResources/OtherExamples/cyclos/manifests/init.pp create mode 100644 PuppetResources/OtherExamples/cyclos/metadata.json create mode 100644 PuppetResources/OtherExamples/cyclos/spec/classes/init_spec.rb create mode 100644 PuppetResources/OtherExamples/cyclos/spec/spec_helper.rb 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..1d0445f --- /dev/null +++ b/PuppetResources/OtherExamples/cyclos/manifests/downloadcyclos.pp @@ -0,0 +1,8 @@ +class cyclos::downloadcyclos($install_path='/home/vagrant'){ + $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..c949f56 --- /dev/null +++ b/PuppetResources/OtherExamples/cyclos/manifests/init.pp @@ -0,0 +1,61 @@ +# 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 + java::oracle { 'jdk6': + ensure => 'present', + version => '6', + } + + #download cyclos + include cyclos::downloadcyclos + + + + + +} diff --git a/PuppetResources/OtherExamples/cyclos/metadata.json b/PuppetResources/OtherExamples/cyclos/metadata.json new file mode 100644 index 0000000..c326c5e --- /dev/null +++ b/PuppetResources/OtherExamples/cyclos/metadata.json @@ -0,0 +1,15 @@ +{ + "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, + "dependencies": [ + {"name":"puppetlabs-stdlib","version_requirement":">= 1.0.0"} + ], + "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' From 39cb2e9dedf7822a9e749b4ca1726ff90e1bb4f3 Mon Sep 17 00:00:00 2001 From: shaikkhajaibrahim Date: Fri, 27 Jan 2017 13:09:36 +0530 Subject: [PATCH 17/27] Added fix for file --- .../OtherExamples/cyclos/manifests/downloadcyclos.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PuppetResources/OtherExamples/cyclos/manifests/downloadcyclos.pp b/PuppetResources/OtherExamples/cyclos/manifests/downloadcyclos.pp index 1d0445f..e7e8543 100644 --- a/PuppetResources/OtherExamples/cyclos/manifests/downloadcyclos.pp +++ b/PuppetResources/OtherExamples/cyclos/manifests/downloadcyclos.pp @@ -1,4 +1,4 @@ -class cyclos::downloadcyclos($install_path='/home/vagrant'){ +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 , From 317c90b0c98f761d51de446a2b27e01a3f8e2f08 Mon Sep 17 00:00:00 2001 From: shaikkhajaibrahim Date: Fri, 27 Jan 2017 14:46:03 +0530 Subject: [PATCH 18/27] added support for mysql_server --- .../OtherExamples/cyclos/manifests/init.pp | 8 ++--- .../cyclos/manifests/install_java.pp | 7 ++++ .../cyclos/manifests/install_mysql.pp | 36 +++++++++++++++++++ 3 files changed, 47 insertions(+), 4 deletions(-) create mode 100644 PuppetResources/OtherExamples/cyclos/manifests/install_java.pp create mode 100644 PuppetResources/OtherExamples/cyclos/manifests/install_mysql.pp diff --git a/PuppetResources/OtherExamples/cyclos/manifests/init.pp b/PuppetResources/OtherExamples/cyclos/manifests/init.pp index c949f56..2eb6510 100644 --- a/PuppetResources/OtherExamples/cyclos/manifests/init.pp +++ b/PuppetResources/OtherExamples/cyclos/manifests/init.pp @@ -46,14 +46,14 @@ class cyclos { #install java based out of puppet forge puppetlabs/java and documentation @ https://forge.puppet.com/puppetlabs/java - java::oracle { 'jdk6': - ensure => 'present', - version => '6', - } + include cyclos::install_java #download cyclos include cyclos::downloadcyclos + #install mysql and configure root users default password + include cyclos::install_mysql + diff --git a/PuppetResources/OtherExamples/cyclos/manifests/install_java.pp b/PuppetResources/OtherExamples/cyclos/manifests/install_java.pp new file mode 100644 index 0000000..a416ce5 --- /dev/null +++ b/PuppetResources/OtherExamples/cyclos/manifests/install_java.pp @@ -0,0 +1,7 @@ +class install_java { + + 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..94da693 --- /dev/null +++ b/PuppetResources/OtherExamples/cyclos/manifests/install_mysql.pp @@ -0,0 +1,36 @@ +class cyclos::install_mysql($default_password= 'p1234',$cyclos_db_password='cyclos1234') { + + #install mysql server + class {'mysql::server': + root_password => $default_password, + } + + #create database cyclos + mysql::db { 'cyclos3': + ensure => present, + charset => 'utf8', + require => 'Class[mysql::server]', + } + + # grant previlages to cyclos + #grant all privileges on cyclos3.* to cyclos@localhost identified by 'cyclos1234'; + #create user cyclos + + mysql::user { 'cyclos@localhost': + ensure => present, + password_hash => mysql_password(cyclos_db_password), + } + + mysql::grant { 'cyclos@localhost/cyclos3.*': + user => 'cyclos@localhost', + table => 'cyclos3.*', + options => ['GRANT'], + privileges => ['ALL'], + } + + + + + + +} \ No newline at end of file From e5db4764d033aa7b361a58cd8e38229c2c11ef3a Mon Sep 17 00:00:00 2001 From: shaikkhajaibrahim Date: Fri, 27 Jan 2017 16:24:20 +0530 Subject: [PATCH 19/27] fix for failures --- .../cyclos/manifests/install_java.pp | 2 +- .../cyclos/manifests/install_mysql.pp | 25 ++++++++----------- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/PuppetResources/OtherExamples/cyclos/manifests/install_java.pp b/PuppetResources/OtherExamples/cyclos/manifests/install_java.pp index a416ce5..e1a6c91 100644 --- a/PuppetResources/OtherExamples/cyclos/manifests/install_java.pp +++ b/PuppetResources/OtherExamples/cyclos/manifests/install_java.pp @@ -1,4 +1,4 @@ -class install_java { +class cyclos::install_java { java::oracle { 'jdk6': ensure => 'present', diff --git a/PuppetResources/OtherExamples/cyclos/manifests/install_mysql.pp b/PuppetResources/OtherExamples/cyclos/manifests/install_mysql.pp index 94da693..c30bf4f 100644 --- a/PuppetResources/OtherExamples/cyclos/manifests/install_mysql.pp +++ b/PuppetResources/OtherExamples/cyclos/manifests/install_mysql.pp @@ -5,32 +5,27 @@ 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, + 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'; - #create user cyclos - - mysql::user { 'cyclos@localhost': - ensure => present, - password_hash => mysql_password(cyclos_db_password), - } - - mysql::grant { 'cyclos@localhost/cyclos3.*': + mysql_grant { 'cyclos@localhost/cyclos3.*': user => 'cyclos@localhost', table => 'cyclos3.*', options => ['GRANT'], privileges => ['ALL'], } - - - - - - } \ No newline at end of file From 9b18e34458f9b4b44a402fc6b8cc25586a7e042d Mon Sep 17 00:00:00 2001 From: shaikkhajaibrahim Date: Fri, 27 Jan 2017 16:57:13 +0530 Subject: [PATCH 20/27] Corrected java for ubuntu --- .../cyclos/manifests/install_java.pp | 36 ++++++++++++++++--- .../OtherExamples/cyclos/metadata.json | 16 ++++++++- 2 files changed, 47 insertions(+), 5 deletions(-) diff --git a/PuppetResources/OtherExamples/cyclos/manifests/install_java.pp b/PuppetResources/OtherExamples/cyclos/manifests/install_java.pp index e1a6c91..366fc5f 100644 --- a/PuppetResources/OtherExamples/cyclos/manifests/install_java.pp +++ b/PuppetResources/OtherExamples/cyclos/manifests/install_java.pp @@ -1,7 +1,35 @@ class cyclos::install_java { - - java::oracle { 'jdk6': - ensure => 'present', - version => '6', + + + 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/metadata.json b/PuppetResources/OtherExamples/cyclos/metadata.json index c326c5e..cffb882 100644 --- a/PuppetResources/OtherExamples/cyclos/metadata.json +++ b/PuppetResources/OtherExamples/cyclos/metadata.json @@ -7,8 +7,22 @@ "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-stdlib","version_requirement":">= 1.0.0" }, + { "name":"puppetlabs/java"}, + {"name":"puppet/archive"}, + {"name":"puppetlabs/mysql"}, + {"name":"puppetlabs/apt"} ], "data_provider": null } From 4579f02f9775ac0498517c826339e3ff54fc77f4 Mon Sep 17 00:00:00 2001 From: shaikkhajaibrahim Date: Fri, 27 Jan 2017 17:09:20 +0530 Subject: [PATCH 21/27] Added tomcat installation --- .../OtherExamples/cyclos/manifests/init.pp | 8 +++++-- .../cyclos/manifests/install_tomcat.pp | 21 +++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 PuppetResources/OtherExamples/cyclos/manifests/install_tomcat.pp diff --git a/PuppetResources/OtherExamples/cyclos/manifests/init.pp b/PuppetResources/OtherExamples/cyclos/manifests/init.pp index 2eb6510..2e4f262 100644 --- a/PuppetResources/OtherExamples/cyclos/manifests/init.pp +++ b/PuppetResources/OtherExamples/cyclos/manifests/init.pp @@ -48,11 +48,15 @@ #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 - #install mysql and configure root users default password - include cyclos::install_mysql 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 From ad9e229b112f456e9fea9a605028647744ac3527 Mon Sep 17 00:00:00 2001 From: shaikkhajaibrahim Date: Sat, 28 Jan 2017 11:20:28 +0530 Subject: [PATCH 22/27] Added templates --- .../appserver_tomcat/manifests/usersconfig.pp | 10 +++- .../templates/tomcat-users.xml.erb | 47 +++++++++++++++++++ .../ClassRoomExamples/inline_erb_example.pp | 17 +++++++ .../subclass_ex/manifests/install.pp | 5 +- .../subclass_ex/manifests/myservice.pp | 4 +- .../subclass_ex/manifests/params.pp | 6 +++ 6 files changed, 84 insertions(+), 5 deletions(-) create mode 100644 PuppetResources/ClassRoomExamples/appserver_tomcat/templates/tomcat-users.xml.erb create mode 100644 PuppetResources/ClassRoomExamples/inline_erb_example.pp create mode 100644 PuppetResources/ClassRoomExamples/subclass_ex/manifests/params.pp diff --git a/PuppetResources/ClassRoomExamples/appserver_tomcat/manifests/usersconfig.pp b/PuppetResources/ClassRoomExamples/appserver_tomcat/manifests/usersconfig.pp index a9fdef5..830e4bb 100644 --- a/PuppetResources/ClassRoomExamples/appserver_tomcat/manifests/usersconfig.pp +++ b/PuppetResources/ClassRoomExamples/appserver_tomcat/manifests/usersconfig.pp @@ -1,8 +1,16 @@ # Class usersconfig # # -class appserver_tomcat::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/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/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/subclass_ex/manifests/install.pp b/PuppetResources/ClassRoomExamples/subclass_ex/manifests/install.pp index 70785ca..25615d1 100644 --- a/PuppetResources/ClassRoomExamples/subclass_ex/manifests/install.pp +++ b/PuppetResources/ClassRoomExamples/subclass_ex/manifests/install.pp @@ -1,10 +1,11 @@ # Class: install # # -class subclass_ex::install { +class subclass_ex::install($package_name= params::$package_name) +inherits params { # resources - package { 'tomcat': + package { $package_name: ensure => installed, notify => Class['myservice'] diff --git a/PuppetResources/ClassRoomExamples/subclass_ex/manifests/myservice.pp b/PuppetResources/ClassRoomExamples/subclass_ex/manifests/myservice.pp index afaa4a5..1dadff3 100644 --- a/PuppetResources/ClassRoomExamples/subclass_ex/manifests/myservice.pp +++ b/PuppetResources/ClassRoomExamples/subclass_ex/manifests/myservice.pp @@ -1,5 +1,5 @@ -class myservice { - service { "tomcat": +class myservice($service_name= params::$package_name) inherits params{ + service { $service_name: ensure => running, enable => true, hasrestart => true, 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 From 6e017c768599aaea9cef2883529d720e3d6f58d2 Mon Sep 17 00:00:00 2001 From: shaikkhajaibrahim Date: Sat, 28 Jan 2017 15:46:01 +0530 Subject: [PATCH 23/27] Added Resource --- PuppetResources/OtherExamples/ntp/Gemfile | 18 ---- PuppetResources/OtherExamples/ntp/README.md | 83 ------------------- PuppetResources/OtherExamples/ntp/Rakefile | 32 ------- .../OtherExamples/ntp/examples/init.pp | 13 +-- .../OtherExamples/ntp/manifests/admin_file.pp | 2 +- .../OtherExamples/ntp/manifests/config.pp | 5 +- .../OtherExamples/ntp/metadata.json | 15 ---- .../ntp/spec/classes/init_spec.rb | 6 -- .../OtherExamples/ntp/spec/spec_helper.rb | 1 - 9 files changed, 3 insertions(+), 172 deletions(-) delete mode 100644 PuppetResources/OtherExamples/ntp/Gemfile delete mode 100644 PuppetResources/OtherExamples/ntp/README.md delete mode 100644 PuppetResources/OtherExamples/ntp/Rakefile delete mode 100644 PuppetResources/OtherExamples/ntp/metadata.json delete mode 100644 PuppetResources/OtherExamples/ntp/spec/classes/init_spec.rb delete mode 100644 PuppetResources/OtherExamples/ntp/spec/spec_helper.rb diff --git a/PuppetResources/OtherExamples/ntp/Gemfile b/PuppetResources/OtherExamples/ntp/Gemfile deleted file mode 100644 index 4f662dc..0000000 --- a/PuppetResources/OtherExamples/ntp/Gemfile +++ /dev/null @@ -1,18 +0,0 @@ -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/ntp/README.md b/PuppetResources/OtherExamples/ntp/README.md deleted file mode 100644 index 68dfe10..0000000 --- a/PuppetResources/OtherExamples/ntp/README.md +++ /dev/null @@ -1,83 +0,0 @@ -# ntp - -#### Table of Contents - -1. [Description](#description) -1. [Setup - The basics of getting started with ntp](#setup) - * [What ntp affects](#what-ntp-affects) - * [Setup requirements](#setup-requirements) - * [Beginning with ntp](#beginning-with-ntp) -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 ntp 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 ntp - -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/ntp/Rakefile b/PuppetResources/OtherExamples/ntp/Rakefile deleted file mode 100644 index 02609e3..0000000 --- a/PuppetResources/OtherExamples/ntp/Rakefile +++ /dev/null @@ -1,32 +0,0 @@ -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/ntp/examples/init.pp b/PuppetResources/OtherExamples/ntp/examples/init.pp index 388623c..9f87de7 100644 --- a/PuppetResources/OtherExamples/ntp/examples/init.pp +++ b/PuppetResources/OtherExamples/ntp/examples/init.pp @@ -1,12 +1 @@ -# 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 ::ntp +include ntp diff --git a/PuppetResources/OtherExamples/ntp/manifests/admin_file.pp b/PuppetResources/OtherExamples/ntp/manifests/admin_file.pp index 1d461ea..2a0f907 100644 --- a/PuppetResources/OtherExamples/ntp/manifests/admin_file.pp +++ b/PuppetResources/OtherExamples/ntp/manifests/admin_file.pp @@ -1,4 +1,4 @@ -define ntp::admin_file($ntp_location='london') { +define ntp::admin_file { include ntp::params $admingroup = $ntp::params::admingroup file { $title : diff --git a/PuppetResources/OtherExamples/ntp/manifests/config.pp b/PuppetResources/OtherExamples/ntp/manifests/config.pp index fd39797..18bf93f 100644 --- a/PuppetResources/OtherExamples/ntp/manifests/config.pp +++ b/PuppetResources/OtherExamples/ntp/manifests/config.pp @@ -7,8 +7,5 @@ '^nyc$', ] validate_re($location, $valid_locations) - ntp::admin_file { - '/etc/ntp.conf': - ntp_location => $location , - } + ntp::admin_file{ '/etc/ntp.conf': } } diff --git a/PuppetResources/OtherExamples/ntp/metadata.json b/PuppetResources/OtherExamples/ntp/metadata.json deleted file mode 100644 index f5ea510..0000000 --- a/PuppetResources/OtherExamples/ntp/metadata.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "name": "asquarezone/ntp", - "version": "0.1.0", - "author": "asquarezone", - "summary": "This module deals with ntp server", - "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/OtherExamples/ntp/spec/classes/init_spec.rb b/PuppetResources/OtherExamples/ntp/spec/classes/init_spec.rb deleted file mode 100644 index d42681a..0000000 --- a/PuppetResources/OtherExamples/ntp/spec/classes/init_spec.rb +++ /dev/null @@ -1,6 +0,0 @@ -require 'spec_helper' -describe 'ntp' do - context 'with default values for all parameters' do - it { should contain_class('ntp') } - end -end diff --git a/PuppetResources/OtherExamples/ntp/spec/spec_helper.rb b/PuppetResources/OtherExamples/ntp/spec/spec_helper.rb deleted file mode 100644 index 2c6f566..0000000 --- a/PuppetResources/OtherExamples/ntp/spec/spec_helper.rb +++ /dev/null @@ -1 +0,0 @@ -require 'puppetlabs_spec_helper/module_spec_helper' From 677127fa89019a6873ca49a97e11975de616a030 Mon Sep 17 00:00:00 2001 From: shaikkhajaibrahim Date: Sat, 28 Jan 2017 18:48:01 +0530 Subject: [PATCH 24/27] Added template sample --- .../ClassRoomExamples/template_ex/Gemfile | 18 ++++ .../ClassRoomExamples/template_ex/README.md | 83 +++++++++++++++++++ .../ClassRoomExamples/template_ex/Rakefile | 32 +++++++ .../template_ex/examples/init.pp | 12 +++ .../template_ex/manifests/init.pp | 51 ++++++++++++ .../template_ex/metadata.json | 15 ++++ .../template_ex/spec/classes/init_spec.rb | 6 ++ .../template_ex/spec/spec_helper.rb | 1 + .../template_ex/templates/dummy.txt.epp | 2 + .../template_ex/templates/dummy.txt.erb | 4 + 10 files changed, 224 insertions(+) create mode 100644 PuppetResources/ClassRoomExamples/template_ex/Gemfile create mode 100644 PuppetResources/ClassRoomExamples/template_ex/README.md create mode 100644 PuppetResources/ClassRoomExamples/template_ex/Rakefile create mode 100644 PuppetResources/ClassRoomExamples/template_ex/examples/init.pp create mode 100644 PuppetResources/ClassRoomExamples/template_ex/manifests/init.pp create mode 100644 PuppetResources/ClassRoomExamples/template_ex/metadata.json create mode 100644 PuppetResources/ClassRoomExamples/template_ex/spec/classes/init_spec.rb create mode 100644 PuppetResources/ClassRoomExamples/template_ex/spec/spec_helper.rb create mode 100644 PuppetResources/ClassRoomExamples/template_ex/templates/dummy.txt.epp create mode 100644 PuppetResources/ClassRoomExamples/template_ex/templates/dummy.txt.erb 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..b0636d4 --- /dev/null +++ b/PuppetResources/ClassRoomExamples/template_ex/manifests/init.pp @@ -0,0 +1,51 @@ +# 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 { + file { '/home/vagrant/dummy.txt': + ensure => file, + content => template('template_ex/dummy.txt.erb') + } + +} 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..fdc0974 --- /dev/null +++ b/PuppetResources/ClassRoomExamples/template_ex/templates/dummy.txt.epp @@ -0,0 +1,2 @@ +#This is managed by puppet +#server is \ 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..a12e891 --- /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 <%= @fqdn %> +# my ip address is <%= @ip_addr %> \ No newline at end of file From 7f1783aa95aa8234ad78ef7f0bc5c23764c23d8b Mon Sep 17 00:00:00 2001 From: shaikkhajaibrahim Date: Sat, 28 Jan 2017 20:20:22 +0530 Subject: [PATCH 25/27] Added changes for motd --- PuppetResources/ClassRoomExamples/motd/manifests/init.pp | 2 +- .../ClassRoomExamples/template_ex/manifests/init.pp | 6 +++++- .../ClassRoomExamples/template_ex/templates/dummy.txt.epp | 4 +++- .../ClassRoomExamples/template_ex/templates/dummy.txt.erb | 2 +- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/PuppetResources/ClassRoomExamples/motd/manifests/init.pp b/PuppetResources/ClassRoomExamples/motd/manifests/init.pp index 7cb1b5f..84fa0f2 100644 --- a/PuppetResources/ClassRoomExamples/motd/manifests/init.pp +++ b/PuppetResources/ClassRoomExamples/motd/manifests/init.pp @@ -42,7 +42,7 @@ # # Copyright 2017 Your name here, unless otherwise noted. # -class motd { +class motd($message='test') { $my_message = @("BEGIN") This is my message diff --git a/PuppetResources/ClassRoomExamples/template_ex/manifests/init.pp b/PuppetResources/ClassRoomExamples/template_ex/manifests/init.pp index b0636d4..8d28350 100644 --- a/PuppetResources/ClassRoomExamples/template_ex/manifests/init.pp +++ b/PuppetResources/ClassRoomExamples/template_ex/manifests/init.pp @@ -43,9 +43,13 @@ # 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 => template('template_ex/dummy.txt.erb') + content => epp('template_ex/dummy.txt.epp',) } } diff --git a/PuppetResources/ClassRoomExamples/template_ex/templates/dummy.txt.epp b/PuppetResources/ClassRoomExamples/template_ex/templates/dummy.txt.epp index fdc0974..11d2de2 100644 --- a/PuppetResources/ClassRoomExamples/template_ex/templates/dummy.txt.epp +++ b/PuppetResources/ClassRoomExamples/template_ex/templates/dummy.txt.epp @@ -1,2 +1,4 @@ #This is managed by puppet -#server is \ No newline at end of file +# 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 index a12e891..0c03f11 100644 --- a/PuppetResources/ClassRoomExamples/template_ex/templates/dummy.txt.erb +++ b/PuppetResources/ClassRoomExamples/template_ex/templates/dummy.txt.erb @@ -1,4 +1,4 @@ #This is managed by puppet # Operating System is <%= @os_name %> -# FQDN is <%= @fqdn %> +# FQDN is <%= @my_fqdn %> # my ip address is <%= @ip_addr %> \ No newline at end of file From 5222e01546f3c780c17a22d77eaafb5f08b4bf32 Mon Sep 17 00:00:00 2001 From: shaikkhajaibrahim Date: Sun, 29 Jan 2017 10:05:45 +0530 Subject: [PATCH 26/27] Added apache for hiera testing --- .../ClassRoomExamples/apache_ex/Gemfile | 18 ++++ .../ClassRoomExamples/apache_ex/README.md | 83 +++++++++++++++++++ .../ClassRoomExamples/apache_ex/Rakefile | 32 +++++++ .../apache_ex/examples/init.pp | 12 +++ .../apache_ex/manifests/init.pp | 53 ++++++++++++ .../apache_ex/manifests/install.pp | 10 +++ .../apache_ex/manifests/service.pp | 14 ++++ .../ClassRoomExamples/apache_ex/metadata.json | 15 ++++ .../apache_ex/spec/classes/init_spec.rb | 6 ++ .../apache_ex/spec/spec_helper.rb | 1 + .../ClassRoomExamples/motd/manifests/init.pp | 7 +- 11 files changed, 246 insertions(+), 5 deletions(-) create mode 100644 PuppetResources/ClassRoomExamples/apache_ex/Gemfile create mode 100644 PuppetResources/ClassRoomExamples/apache_ex/README.md create mode 100644 PuppetResources/ClassRoomExamples/apache_ex/Rakefile create mode 100644 PuppetResources/ClassRoomExamples/apache_ex/examples/init.pp create mode 100644 PuppetResources/ClassRoomExamples/apache_ex/manifests/init.pp create mode 100644 PuppetResources/ClassRoomExamples/apache_ex/manifests/install.pp create mode 100644 PuppetResources/ClassRoomExamples/apache_ex/manifests/service.pp create mode 100644 PuppetResources/ClassRoomExamples/apache_ex/metadata.json create mode 100644 PuppetResources/ClassRoomExamples/apache_ex/spec/classes/init_spec.rb create mode 100644 PuppetResources/ClassRoomExamples/apache_ex/spec/spec_helper.rb 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..4f939f0 --- /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="Apache Server is installed" + + 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..da21d4f --- /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 = "Apache Service has been started" + 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/motd/manifests/init.pp b/PuppetResources/ClassRoomExamples/motd/manifests/init.pp index 84fa0f2..d769350 100644 --- a/PuppetResources/ClassRoomExamples/motd/manifests/init.pp +++ b/PuppetResources/ClassRoomExamples/motd/manifests/init.pp @@ -44,10 +44,7 @@ # class motd($message='test') { - $my_message = @("BEGIN") - This is my message - This is managed by puppet - BEGIN + file { '/etc/motd': ensure => file, @@ -55,7 +52,7 @@ #group => group, #mode => mode, #source => 'puppet:///modules/class/file.txt'; - content => file('motd/message'), + content => $message, } From 3ae5b05e1647266805a7406e10e31b9591555f7a Mon Sep 17 00:00:00 2001 From: shaikkhajaibrahim Date: Sun, 29 Jan 2017 10:23:59 +0530 Subject: [PATCH 27/27] Added hiera lookup --- .../ClassRoomExamples/apache_ex/manifests/install.pp | 2 +- .../ClassRoomExamples/apache_ex/manifests/service.pp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/PuppetResources/ClassRoomExamples/apache_ex/manifests/install.pp b/PuppetResources/ClassRoomExamples/apache_ex/manifests/install.pp index 4f939f0..979da65 100644 --- a/PuppetResources/ClassRoomExamples/apache_ex/manifests/install.pp +++ b/PuppetResources/ClassRoomExamples/apache_ex/manifests/install.pp @@ -3,7 +3,7 @@ ensure => installed, } - $apache_install_message="Apache Server is installed" + $apache_install_message=hiera('apache_ex::install_message') notify { $apache_install_message: } diff --git a/PuppetResources/ClassRoomExamples/apache_ex/manifests/service.pp b/PuppetResources/ClassRoomExamples/apache_ex/manifests/service.pp index da21d4f..4b2b332 100644 --- a/PuppetResources/ClassRoomExamples/apache_ex/manifests/service.pp +++ b/PuppetResources/ClassRoomExamples/apache_ex/manifests/service.pp @@ -8,7 +8,7 @@ # pattern => $service_name, } - $service_message = "Apache Service has been started" + $service_message = hiera('apache_ex::service_message') notify { $service_message: } } \ No newline at end of file