diff --git a/CHANGELOG.md b/CHANGELOG.md index 15908d4f081f5ee01a98a17e24eb3a55c9bea801..a982acd3215b78eb333a8882ecf45cd0351419cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ All notable changes to this project will be documented in this file. **Bugfixes** + * #33 Be able to use parameter to define archives path. * #34 Use nokogiri provided by pdk for tests. * #35 Update README description. diff --git a/REFERENCE.md b/REFERENCE.md index 4875de4a6fa69d55d1c97bebb842e14a643ba412..9f0de21f78956c6a2c660e8571db056113287f87 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -107,6 +107,14 @@ Describes all availables settings in this module for all wordpress instances on Default value: {} +##### `wparchives_path` + +Data type: `Pattern['^/']` + +Gives the path where are stored archives done before update managed by puppet (not by WordPress itself with `wpselfupdate`). Defaults to /var/wordpress_archives. + +Default value: $wordpress::params::default_wparchives_path + ##### `wpcli_url` Data type: `Pattern['^http']` @@ -177,6 +185,12 @@ Data type: `Pattern['^/']` The PATH where the WP-CLI tools is deployed. +##### `wparchives_path` + +Data type: `Pattern['^/']` + +Gives the path where are stored archives done before update managed by puppet (not by WordPress itself with `wpselfupdate`). Defaults to /var/wordpress_archives. + ##### `settings` Data type: `Wordpress::Settings` @@ -385,6 +399,12 @@ Data type: `String` The path of the WP-CLI tool. +##### `wparchives_path` + +Data type: `String` + +Gives the path where are stored archives done before update managed by puppet (not by WordPress itself with `wpselfupdate`). Defaults to /var/wordpress_archives. + ### wordpress::resource::activate Activates an already installed resource aka plugin or theme. diff --git a/manifests/core.pp b/manifests/core.pp index d4d7a76fb12bc12745214d9e8a00637da12e7b07..4b8b61065b1473ea05e33d2d2d09593d1c8e3ba0 100644 --- a/manifests/core.pp +++ b/manifests/core.pp @@ -3,12 +3,16 @@ #@param wpcli_bin # The PATH where the WP-CLI tools is deployed. # +#@param wparchives_path +# Gives the path where are stored archives done before update managed by puppet (not by WordPress itself with `wpselfupdate`). Defaults to /var/wordpress_archives. +# #@param settings # Describes all availables settings in this module for all wordpress instances on this node. Defaults to empty hash. # #@note This class should be considered as private. class wordpress::core ( Pattern['^/'] $wpcli_bin, + Pattern['^/'] $wparchives_path, Wordpress::Settings $settings = {}, ) { @@ -81,7 +85,7 @@ class wordpress::core ( } } 'latest': { - file { $::wordpress::params::wordpress_archives : + file { $wparchives_path : ensure => 'directory', mode => '0700', owner => 0, @@ -95,13 +99,14 @@ class wordpress::core ( $_wp_core_update_status = $::facts['wordpress']["${_wp_servername}"]['core']['update'] if $_wp_core_update_status != 'none' { wordpress::core::update { $_wp_servername : - wp_servername => $_wp_servername, - wp_root => $_wp_root, - owner => $_owner, - locale => $_locale, - wpselfupdate => $_wpselfupdate, - wpcli_bin => $wpcli_bin, - require => File[$::wordpress::params::wordpress_archives], + wp_servername => $_wp_servername, + wp_root => $_wp_root, + owner => $_owner, + locale => $_locale, + wpselfupdate => $_wpselfupdate, + wpcli_bin => $wpcli_bin, + wparchives_path => $wparchives_path, + require => File[$wparchives_path], } } } else { @@ -124,13 +129,14 @@ class wordpress::core ( } -> wordpress::core::update { $_wp_servername : - wp_servername => $_wp_servername, - wp_root => $_wp_root, - owner => $_owner, - locale => $_locale, - wpselfupdate => $_wpselfupdate, - wpcli_bin => $wpcli_bin, - require => File[$::wordpress::params::wordpress_archives], + wp_servername => $_wp_servername, + wp_root => $_wp_root, + owner => $_owner, + locale => $_locale, + wpselfupdate => $_wpselfupdate, + wpcli_bin => $wpcli_bin, + wparchives_path => $wparchives_path, + require => File[$wparchives_path], } } } diff --git a/manifests/core/update.pp b/manifests/core/update.pp index 61ff8f42cb01349388a20c7e9ee2d05913a77199..80d2a510cf511431fd119c7cd91d2807241e23fd 100644 --- a/manifests/core/update.pp +++ b/manifests/core/update.pp @@ -2,16 +2,25 @@ # #@param wp_servername # The URI of the WordPress instance (like : www.foo.org). +# #@param wp_root # The root path of the WordPress instance. +# #@param owner # The OS account, owner of files of the WordPress instance. +# #@param locale # Language used by WordPress instance (defaults en_US). +# #@param wpselfupdate # Possible values : disabled , enabled (defaults disabled). +# #@param wpcli_bin # The path of the WP-CLI tool. +# +#@param wparchives_path +# Gives the path where are stored archives done before update managed by puppet (not by WordPress itself with `wpselfupdate`). Defaults to /var/wordpress_archives. +# #@note This defined type should be considered as private. define wordpress::core::update ( String $wp_servername, @@ -20,6 +29,7 @@ define wordpress::core::update ( String $locale, String $wpselfupdate, String $wpcli_bin, + String $wparchives_path, ) { # four steps : # 1. make a backup @@ -28,19 +38,19 @@ define wordpress::core::update ( # 4. update language $_date = strftime('%Y-%m-%d') - $_archives_path = $::wordpress::params::wordpress_archives - # Export and Archive is done as root because of mode 0700 for directory $wordpress_archives + # Export and Archive is done as root because directory $wparchives_path + # is with mode 0700 and owned by root. exec { "${wp_servername} > Export database before upgrade" : command => "${wpcli_bin} --allow-root --path=${wp_root} db export", - cwd => $_archives_path, - creates => "${_archives_path}/${wp_servername}_${_date}.tar.gz", + cwd => $wparchives_path, + creates => "${wparchives_path}/${wp_servername}_${_date}.tar.gz", } -> exec { "${wp_servername} > Archive files before upgrade" : - command => "tar -cvf ${_archives_path}/${wp_servername}_${_date}.tar.gz .", + command => "tar -cvf ${wparchives_path}/${wp_servername}_${_date}.tar.gz .", cwd => $wp_root, - creates => "${_archives_path}/${wp_servername}_${_date}.tar.gz", + creates => "${wparchives_path}/${wp_servername}_${_date}.tar.gz", } case $locale { diff --git a/manifests/init.pp b/manifests/init.pp index aa4781a25d468cda7a12a44efe12e4a2a80360fe..d8c7cc817c6e2aca95b9685ce2738e8ee76f8fa2 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -67,15 +67,22 @@ # #@param settings # Describes all availables settings in this module for all wordpress instances on this node. Defaults to empty hash. +# +#@param wparchives_path +# Gives the path where are stored archives done before update managed by puppet (not by WordPress itself with `wpselfupdate`). Defaults to /var/wordpress_archives. +# #@param wpcli_url # Gives the address from which to download the WP-CLI tool. Defaults to 'https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar'. +# #@param wpcli_bin # Gives the path where the WP-CLI tools is deployed. Defaults to '/usr/local/bin/wp'. +# #@param hour_fact_update # Gives the time (hour between 1 and 23) at which the update of external fact is done (use cron). Defaults to 7. # class wordpress ( Hash $settings = {}, + Pattern['^/'] $wparchives_path = $wordpress::params::default_wparchives_path, Pattern['^http'] $wpcli_url = $wordpress::params::default_wpcli_url, Pattern['^/'] $wpcli_bin = $wordpress::params::default_wpcli_bin, Integer[1,23] $hour_fact_update = $wordpress::params::default_hour_fact_update, @@ -96,8 +103,9 @@ class wordpress ( # * set condifguration settings # * connect to db server and create tables class { 'wordpress::core' : - settings => $settings, - wpcli_bin => $wpcli_bin, + settings => $settings, + wpcli_bin => $wpcli_bin, + wparchives_path => $wparchives_path, } -> # then manage others resources like plugins and themes diff --git a/manifests/params.pp b/manifests/params.pp index 9e070c8f818d75995b0a6a0ba2999aa0655279bb..722e5f9991a483110cd7a6b422bd90da4d0a7db8 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -26,7 +26,7 @@ class wordpress::params { $default_wpselfupdate = 'disabled' $default_wpresource_ensure = 'present' - $wordpress_archives = '/var/wordpress_archives' + $default_wparchives_path = '/var/wordpress_archives' } diff --git a/spec/acceptance/wordpress_spec.rb b/spec/acceptance/wordpress_spec.rb index fc60c9605b7164cea98b9bbabfecd39aa98874c1..37d503186a60c70c465a7cb1b86607c777d29dcb 100644 --- a/spec/acceptance/wordpress_spec.rb +++ b/spec/acceptance/wordpress_spec.rb @@ -4,7 +4,7 @@ $wpcli_bin = '/usr/local/bin/wp' $wp_root = '/var/www/wordpress.foo.org' $wp2_root = '/var/www/wp2.foo.org' $wp3_root = '/var/www/wp3.foo.org' -$wparchives = '/var/wordpress_archives' +$wparchives = '/var/mywp_archives' if fact('osfamily') == 'Debian' $crontabs_path='/var/spool/cron/crontabs' elsif fact('osfamily') == 'RedHat' @@ -203,11 +203,12 @@ describe 'wordpress class' do end end - context 'with parameters about two wordpress instances with customs locales' do + context 'with parameters about two wordpress instances with customs locales and archives path' do it 'applies idempotently' do pp = <<-EOS class { 'wordpress': - settings => { + wparchives_path => '/var/mywp_archives', + settings => { 'wp2.foo.org' => { ensure => 'latest', owner => 'wp2', diff --git a/spec/classes/core_spec.rb b/spec/classes/core_spec.rb index 0253ec05f8faba12271c22943786ae215dd39aa9..b3c6a6d53bd0b7264959c5a4ae033f0b3d81edf0 100644 --- a/spec/classes/core_spec.rb +++ b/spec/classes/core_spec.rb @@ -4,6 +4,7 @@ describe 'wordpress::core' do let :default_params do { wpcli_bin: '/bin/wpcli', + wparchives_path: '/var/archives', } end