Nov 11, 2014

Puppet Module: adding cron jobs, software packages, services

Node configuration (Default, and Individual node)
# site.pp

Package {
  allow_virtual => true,
}

# Install update job and ntp to all nodes
node default {
  include apps::update
  include apps::ntp
}

# Install tomcat6 and httpd to tomcat1.lan
node 'tomcat1.lan' {
  include apps::ntp
  include apps::update
  include apps::tomcat6
  include apps::httpd
}

Module and Class Configuration
# apps/init.pp

# Cron jobs for OS and puppet update.
class apps::update {
  cron { yum-update:
    command => "/usr/bin/yum -y update",
    user    => root,
    minute  => "*/5"
  }

  cron { puppet-update:
    command => "/usr/bin/puppet agent --test",
    user    => root,
    minute  => "*/5"
  }
}

# Auto install, and auto start-up
class apps::ntp {
  package { 'ntp': ensure => installed }

  service { "ntpd":
    ensure => running,
    enable => true,
    subscribe => Package["ntp"]
  }
}

class apps::httpd {
  package { 'httpd': ensure => installed }

  service { "httpd":
    ensure => running,
    enable => true,
    pattern => "httpd",
    subscribe => Package["httpd"]
  }

}

# Same as above, resolved package dependencies.
class apps::tomcat6 {
  package { 'tomcat6': ensure => installed }
  package { 'glibc-headers': ensure => installed }
  package { 'kernel-headers': ensure => installed }

  Package['kernel-headers'] -> Package['glibc-headers'] -> Package['tomcat6']

  service { "tomcat6":
    ensure => running,
    enable => true,
    pattern => "tomcat6",
    subscribe => Package["tomcat6"]
  }

}

No comments: