Created
March 13, 2013 03:31
-
-
Save romaricpascal/5149181 to your computer and use it in GitHub Desktop.
A Puppet manifest to create host entry, apache vhost and mysql database for PHP projects (eg. Wordpress projects)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -------------------------------------------------------------------------- | |
# Puppet manifest for wordpress projects: | |
# - Creates a host entry | |
# - Configures a vhost on an Apache server | |
# - Creates a database with a specific user | |
# | |
# The manifest relies on Hiera to access server specific information like | |
# the folder where the project is deployed or the database password. | |
# | |
# Apache configuration uses a fork of puppetlabs-apache module, available at | |
# https://github.com/rhumaric/puppetlabs-apache | |
# | |
# Author: Romaric Pascal (rhumaric) | |
# License: MIT | |
# -------------------------------------------------------------------------- | |
# Wrapper to encapsulate the whole application configuration. This is mainly | |
# to give Hiera an `application_name` variable, which I use to structure | |
# my database: | |
# | |
# - my-app.yaml : app specific values (eg. mysql user and password, host name, docroot...) | |
# - common.yaml : server wide values (eg. mysql root password) | |
# | |
class application($application_name){ | |
# The name of the mysql database | |
$mysql_db = "${application_name}.${environment}" | |
# -------------------------------------------------------------------------- | |
# Host entry | |
# -------------------------------------------------------------------------- | |
# On staging and production environment, this is handled by having | |
# a new entry in the DNS server. Only in 'local' environments does the project | |
# need a host entry. | |
if($environment == 'local') { | |
host { '${application_name}': | |
ensure => 'present', | |
# This allows | |
name => hiera('hostname'), | |
ip => '127.0.0.1' | |
} | |
} | |
# -------------------------------------------------------------------------- | |
# Apache configuration | |
# -------------------------------------------------------------------------- | |
# Makes sure apache is installed on the system. Leaves any vhost already | |
# deployed as it is. | |
class { 'apache': | |
purge_vhosts_dir => false | |
} | |
# Env module is needed to pass database configuration to Wordpress using | |
# environment variables | |
a2mod { 'env': | |
name => 'env', | |
ensure => 'present' | |
} | |
# Rewrite module is necessary to have custom permalinks in Wordpress | |
a2mod { 'rewrite': | |
name => 'rewrite', | |
ensure => 'present' | |
} | |
# Creates the vhost, passing along the necessary mysql information | |
apache::vhost{ '${application_name}': | |
name => "${application_name}.${::environment}", | |
port => 80, | |
docroot => hiera('docroot'), | |
configure_firewall => false, | |
servername => hiera('hostname'), | |
ssl => false, | |
override => all, | |
setenv => { | |
'WORDPRESS_DB_USER' => hiera('mysql_user'), | |
'WORDPRESS_DB_PASSWORD' => hiera('mysql_password'), | |
'WORDPRESS_DB_HOST' => hiera('mysql_host'), | |
'WORDPRESS_DB_NAME' => $mysql_db | |
} | |
} | |
# -------------------------------------------------------------------------- | |
# MySQL | |
# -------------------------------------------------------------------------- | |
# Makes sure MySQL is available on the server | |
class { 'mysql::server': | |
config_hash => { | |
'root_password' => hiera('mysql_root_password') | |
} | |
} | |
# And creates the database | |
mysql::db {"${mysql_db}": | |
user => hiera('mysql_user'), | |
password => hiera('mysql_password'), | |
host => 'localhost', | |
grant => ['all'], | |
require => Class['mysql::server'] | |
} | |
} | |
# Creates the application | |
class {'application': | |
application_name => 'rhumaric.com' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment