Skip to content

Instantly share code, notes, and snippets.

@mushkevych
Last active December 21, 2015 07:38
Show Gist options
  • Save mushkevych/6272083 to your computer and use it in GitHub Desktop.
Save mushkevych/6272083 to your computer and use it in GitHub Desktop.
Puppet + Hiera + Jenkins Gist
{
"ntp::restrict" : true,
"ntp::autoupdate" : true,
"ntp::enable" : true,
"ntp::servers" : [
"0.centos.pool.ntp.org iburst",
"1.centos.pool.ntp.org iburst",
"2.centos.pool.ntp.org iburst"
]
}
# file /biz/puppet/modules/configuration/manifests/init.pp
class configuration ($application, $env){
# creating directory structure first
file { ['/biz', '/biz/configuration']:
ensure => directory,
mode => 0640,
}
file { "/biz/configuration/${application}":
ensure => directory, # so make this a directory
recurse => true, # enable recursive directory management
purge => true, # purge all unmanaged junk
force => true, # also purge subdirs and links etc.
mode => 0640,
source => "puppet:///modules/configuration/${env}/${application}",
}
}
.
├── files
│   ├── ci
│   │   ├── enterprise_app_1
│   │   │   ├── dir.1
│   │   │   │   └── file.1
│   │   │   ├── file.1
│   │   │   └── file.2
│   │   └── web_app_1
│   │   ├── dir.1
│   │   │   └── file.1
│   │   ├── file.1
│   │   └── file.2
│   └── qa
│   ├── enterprise_app_1
│   │   ├── dir.1
│   │   │   └── file.1
│   │   ├── file.1
│   │   └── file.2
│   └── web_app_1
│   ├── dir.1
│   │   └── file.1
│   ├── file.1
│   └── file.2
└── manifests
└── init.pp
.
├── biz
│ └── puppet
│ ├── hieradata
│ │ ├── ci
│ │ │ ├── node
│ │ │ │ ├── ip-10-0-8-11.sampup.com.json
│ │ │ │ └── ip-10-0-8-12.sampup.com.json
│ │ │ ├── common.json
│ │ │ └── site.pp
│ │ └── qa
│ │ ├── node
│ │ │ ├── ip-10-0-8-11.sampup.com.json
│ │ │ └── ip-10-0-8-12.sampup.com.json
│ │ ├── common.json
│ │ └── site.pp
│ └── modules
│ ├── configuration
│ │ ├── files
│ │ │ ├── ci
│ │ │ │ ├── enterprise_app_1
│ │ │ │ │ ├── dir.1
│ │ │ │ │ │ └── file.1
│ │ │ │ │ ├── file.1
│ │ │ │ │ └── file.2
│ │ │ │ └── web_app_1
│ │ │ │ ├── dir.1
│ │ │ │ │ └── file.1
│ │ │ │ ├── file.1
│ │ │ │ └── file.2
│ │ │ └── qa
│ │ │ ├── enterprise_app_1
│ │ │ │ ├── dir.1
│ │ │ │ │ └── file.1
│ │ │ │ ├── file.1
│ │ │ │ └── file.2
│ │ │ └── web_app_1
│ │ │ ├── dir.1
│ │ │ │ └── file.1
│ │ │ ├── file.1
│ │ │ └── file.2
│ │ └── manifests
│ │ └── init.pp
│ ├── networking
│ │ └── manifests
│ │ └── init.pp
│ ├── profile
│ │ └── manifests
│ │ ├── base.pp
│ │ ├── init.pp
│ │ └── web_server.pp
│ ├── role
│ │ └── manifests
│ │ ├── enterprise_server.pp
│ │ ├── init.pp
│ │ └── web_portal.pp
│ └── timezone
│ └── manifests
│ ├── init.pp
│ └── utc.pp
├── etc
│ └── puppet
│ ├── hiera.yaml
│ └── puppet.conf
├── agent_deploy.sh
├── deploy.sh
└── install_modules.sh
class role::hello_world_server inherits role {
# ...
class { 'configuration' :
env => "${environment}",
application => 'HelloWorld',
}
}
---
:backends:
- json
:json:
:datadir: /biz/puppet/hieradata/%{::environment}
:hierarchy:
# A single node/ directory will contain any number of files named after some node’s fqdn (fully qualified domain name) fact.
# (E.g. /etc/puppet/hiera/node/grover.example.com.json) This lets us specifically configure any given node with Hiera.
# Not every node needs to have a file in node/ — if it’s not there, Hiera will just move onto the next hierarchy level.
- node/%{::fqdn}
- common
:logger:
- puppet
#!/bin/bash
sudo puppet module install puppetlabs/ntp
sudo puppet module install puppetlabs/apache
sudo puppet module install camptocamp/tomcat
sudo puppet module list
{
"apache::vhost::priority": "10",
"apache::vhost::vhost_name": "web_server.sampup.com",
"apache::vhost::port": "80",
"apache::vhost::docroot": "/var/www",
}
# file /biz/puppet/modules/profile/manifests/init.pp
class profile {
}
# file /biz/puppet/modules/profile/manifests/web_server.pp
class profile::web_server {
class { "apache": }
}
# file /biz/puppet/modules/profile/manifests/base.pp
class profile::base {
include networking
include timezone::utc
include users
}
[main]
server = ip-10-0-8-10.sampup.com
certname = ip-10-0-8-10.sampup.com
#user = puppet
#group = puppet
vardir = /var/lib/puppet
factpath = $vardir/lib/facter
templatedir = $confdir/templates
# The Puppet log directory.
# The default value is '$vardir/log'.
logdir = /var/log/puppet
# Where Puppet PID files are kept.
# The default value is '$vardir/run'.
rundir = /var/run/puppet
# Where SSL certificates are kept.
# The default value is '$confdir/ssl'.
ssldir = $vardir/ssl
[master]
dns_alt_names = ip-10-0-8-10.sampup.com, puppet
# overriding location of the hierra.yaml
hiera_config = /etc/puppet/hiera.yaml
# site.pp path
manifest = /biz/puppet/hieradata/$environment/site.pp
# a multi-directory modulepath:
modulepath = /etc/puppet/modules:/usr/share/puppet/modules:/biz/puppet/modules
[agent]
pluginsync = true
# The file in which puppetd stores a list of the classes
# associated with the retrieved configuratiion. Can be loaded in
# the separate ``puppet`` executable using the ``--loadclasses``
# option.
# The default value is '$confdir/classes.txt'.
classfile = $vardir/classes.txt
# Where puppetd caches the local configuration. An
# extension indicating the cache format is added automatically.
# The default value is '$confdir/localconfig'.
localconfig = $vardir/localconfig
certname = ip-10-0-8-11.sampup.com
dns_alt_names = ip-10-0-8-11.sampup.com
report = true
archive_files = true
environment = qa
# file /biz/puppet/modules/role/manifests/init.pp
class role {
include profile::base
}
# file /biz/puppet/modules/role/manifests/web_portal.pp
class role::web_portal inherits role {
include profile::web_server
class { 'configuration' :
env => "${environment}",
application => 'web_app_1',
}
}
# file /biz/puppet/modules/role/manifests/enterprise_server.pp
class role::enterprise_server inherits role {
# out of the blog post scope - install tomcat+java
# include profile::tomcat_server
class { 'configuration' :
env => "${environment}",
application => 'enterprise_app_1',
}
}
node ip-10-0-8-11 {
include role::web_portal
}
node ip-10-0-8-12 {
include role::enterprise_server
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment