Puppet is a configuration management tool. This article will show you how you to setup a basic web site running WordPress using Puppet 5. It assumes you are already running a Puppet server and you are using r10k with roles and profiles. This code was tested on CentOS 7.
TODO: remove override attribute/add apache rewrite rules. add Certbot.
We’ll need these modules which are available from the Puppet Forge.
If you are using r10K, add them to the Puppetfile in your control repo.
mod 'puppetlabs-apache', '3.0.0' mod 'puppetlabs-mysql', '5.1.0' mod 'neillturner-wordpress', '1.2.2'
Create a new Puppet profile for WordPress. This example will install WordPress in /opt/wordpress.
site/profile/manifests/wordpress.pp:
class profile::wordpress { # set SELinux to allow apache to connect to mysql selboolean { 'httpd_can_network_connect_db': persistent => true, value => on, } # install apache class { 'apache': mpm_module => 'prefork', default_vhost => false, } # install php class {'::apache::mod::php': } # setup apache vhost for WordPress apache::vhost { lookup('profile::wordpress::apache_vhost'): port => '80', docroot => '/opt/wordpress', docroot_owner => 'apache', docroot_group => 'apache', override => 'All', } # install packages needed by WordPress package { [ 'wget', 'php-mysql' ]: ensure => present, } ->class { 'wordpress': version => '4.9.4', db_user => lookup('profile::wordpress::db_user'), db_password => lookup('profile::wordpress::db_password'), db_host => lookup('profile::wordpress::db_host'), db_name => lookup('profile::wordpress::db_name'), wp_owner => 'apache', create_db => true, create_db_user => true, } # fix SELinux context on uploads folder ->file { '/opt/wordpress/wp_content/uploads': ensure => directory, seltype => 'httpd_sys_rw_content_t', } }
Add this profile to a new role or add it to existing roles. Your settings are managed with hiera:
profile::wordpress::apache_vhost: www.mysitename.com profile::wordpress::db_user: myusername profile::wordpress::db_password: mypassword profile::wordpress::db_host: mydbhostname profile::wordpress::db_name: mydbname
For more information, check out the following links: