We can automate WordPress installation with Puppet running on Ubuntu instance on Rackspace Cloud Server for our own multiple WordPress sites. In the age of cloud automation and for this scenario, lesser need of abstraction makes the idea near ideal depending upon the number of websites.
Why Automate WordPress Installation With Puppet on Rackspace Cloud Server?
Why automate WordPress Installation with Puppet on Rackspace Cloud Server when OpenStack Heat Template Exists? Because OpenStack Heat can not give you the fine granular control for your personalized need? No. Puppet and OpenStack Heat Template, can not be compared so bravely. OpenStack Heat Template is an orchestration tool for managing stacks or applications deployed on Rackspace cloud. Packaging can also be installed via OpenStack Heat Templates to do things like deploying a stack and make it a 4 node WordPress cluster.
Puppet is client-server based. Puppetmaster and Puppet Clients. Declarative Language for write once deploy many. Puppet has open-source Openstack Packages for on-demand Openstack Delivery/Configuration Version control. Deployment of monitoring tools, security tools all possible within private cloud.
That is said, but you can, in many cases should, use both types of tools together. There are also valid strategies for deploying some applications using Heat alone.
---
Why Automate WordPress Installation With Puppet on Rackspace Cloud Server?
It is not acceptable to think that you are a newbie to install WordPress from Command Line. In this tutorial we will create a Puppet module that can install Apache, MySQL; add a database and a database user on MySQL for WordPress and configure WordPress. It is a kind o template for your need.
We can not downgrade from a server Image – this must be understood. If we could easily use one VHD image optimized for 2 GB instance for 512 MB device, we would never need it. So, this kind of setup is only required when multiple 512, 1 GB, 2 GB to 512 GB Bare Metal installation is needed. Otherwise, the amount of work will not give significant advantage.
First step is to download and install Puppet :
1 2 3 4 5 6 | mkdir -p ~/Downloads && cd ~/Downloads wget https://apt.puppetlabs.com/puppetlabs-release-trusty.deb sudo dpkg -i puppetlabs-release-trusty.deb apt-get update -y && apt-get install puppet puppet --version # output |
Next we need to set the configuration file to install the components needed to run WordPress :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | nano /etc/puppet/puppet.conf *** This Should Look Like This *** [main] logdir=/var/log/puppet vardir=/var/lib/puppet ssldir=/var/lib/puppet/ssl rundir=/var/run/puppet factpath=$vardir/lib/facter templatedir=$confdir/templates [master] ssl_client_header = SSL_CLIENT_S_DN ssl_client_verify_header = SSL_CLIENT_VERIFY *** Example Ends Above This *** |
Now install MySQL and Apache :
1 2 3 4 | puppet module install puppetlabs-apache puppet module install puppetlabs-mysql # check the list of stuffs puppet module list |
Add modules for WordPress :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | mkdir -p ~/MyModules && cd ~/MyModules puppet module generate do-wordpress --skip-interview # do-wordpress is just a name # if you do not include `--skip-interview` # you'll face interactive mode # do-wordpress is a directory, you can cd and do ls to check # it nano ~/MyModules/do-wordpress/metadata.json *** It Should Look Like This *** { "name": "do-wordpress", "version": "0.1.0", "author": "do", "summary": null, "license": "Apache 2.0", "source": "", "project_page": null, "issues_url": null, "dependencies": [ {"name":"puppetlabs/stdlib","version_requirement":">= 1.0.0"} ] } *** Example Ends Above This Line *** # we will use prefork nano ~/MyModules/do-wordpress/manifests/web.pp *** It Should Look Like This *** class wordpress::web { class {'apache': mpm_module => 'prefork' } class {'::apache::mod::php': } } # configuration for php and apache2 *** Example Ends Above This Line *** # we will modify the .conf nano ~/MyModules/do-wordpress/manifests/conf.pp *** It Should Look Like This But Values Should Be Changed *** class wordpress::conf { # You can change the values of these variables # according to your preferences $root_password = 'password' $db_name = 'wordpress' $db_user = 'wordpressuser' $db_user_password = 'password' $db_host = 'localhost' $db_user_host = "${db_user}@${db_host}" # notice the .* $db_user_host_db = "${db_user}@${db_host}/${db_name}.*" } *** Example Ends Above This Line *** # same for MySQL nano ~/MyModules/do-wordpress/manifests/db.pp *** It Should Look Like This But Values Should Be Changed *** class wordpress::db { class { '::mysql::server': # we are defining => password, user, privileges and bind root_password => $wordpress::conf::root_password, databases => { "${wordpress::conf::db_name}" => { ensure => 'present', charset => 'utf8' } }, users => { "${wordpress::conf::db_user_host}" => { ensure => present, password_hash => mysql_password("${wordpress::conf::db_user_password}") } }, grants => { "${wordpress::conf::db_user_host_db}" => { ensure => 'present', options => ['GRANT'], privileges => ['ALL'], table => "${wordpress::conf::db_name}.*", user => "${wordpress::conf::db_user_host}", } }, } # we can toggle binding at my.cnf class { '::mysql::client': require => Class['::mysql::server'], bindings_enable => true } } *** Example Ends Above This Line *** |
Backend is ready, we can install WordPress now :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | mkdir -p ~/MyModules/do-wordpress/files && cd ~/MyModules/do-wordpress/files mkdir -p ~/MyModules/do-wordpress/templates && cd /tmp tar -xvzf ~/MyModules/do-wordpress/files/latest.tar.gz && cp /tmp/wordpress/wp-config-sample.php ~/MyModules/do-wordpress/templates/wp-config.php.erb rm -rf /tmp/wordpress* latest* && nano ~/MyModules/do-wordpress/templates/wp-config.php.erb # copy paste this gist and write out with ^ + O https://gist.github.com/AbhishekGhosh/85dd163c5d70a78f8d7e # here is the raw https://gist.githubusercontent.com/AbhishekGhosh/85dd163c5d70a78f8d7e/raw/6ad6531ef9c82bac7a017c1dd6191821e45498fb/puppet-wordpress-multi.php # edit the wordpress specific file nano ~/MyModules/do-wordpress/manifests/wp.pp *** Example Starts Below This Line *** class wordpress::wp { file { '/tmp/latest.tar.gz': ensure => present, source => "puppet:///modules/wordpress/latest.tar.gz" } exec { 'extract': cwd => "/tmp", command => "tar -xvzf latest.tar.gz", require => File['/tmp/latest.tar.gz'], path => ['/bin'], } exec { 'copy': command => "cp -r /tmp/wordpress/* /var/www/", require => Exec['extract'], path => ['/bin'], } file { '/var/www/wp-config.php': ensure => present, require => Exec['copy'], content => template("wordpress/wp-config.php.erb") } } *** Example Ends Above This Line *** |
Do not worry ! this is the last step :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | nano ~/MyModules/do-wordpress/manifests/init.pp *** Example Starts Below This Line *** class wordpress { class { 'wordpress::conf': } class { 'wordpress::web': } class { 'wordpress::db': } class { 'wordpress::wp': require => Notify['Apache Installation Done'] } notify { 'MySQL Installation Done': require => Class['wordpress::db'] } notify { 'Apache Installation Done': require => Class['wordpress::web'] } notify { 'Wordpress Installation Done': require => Class['wordpress::wp'] } } *** Example Ends Above This Line *** |
Now build your package :
1 | cd ~/MyModules && puppet module build do-wordpress |
Now you can use it to install easily. To check the right name, cd to pkg
directory :
1 2 3 4 5 6 7 8 9 10 | cd ~/MyModules/do-wordpress/pkg/ && ls -al # example command to install WordPress puppet module install ~/MyModules/do-wordpress/pkg/do-wordpress-0.1.0.tar.gz nano /tmp/install-wp.pp # add this class { 'wordpress': } # thats it sudo puppet apply /tmp/install-wp.pp # point to domain name or bare IP on browser |
It is tested on Rackspace PVHVM 2 GB instance. It takes a bit time (~15 minutes) to get the custom setup installed.
Tagged With automate installation wordpress ubuntu , automate wp installation , installation of wordpress on puppet , wordpress pupet ubuntu