Skip to content
Snippets Groups Projects
Commit 6cbf00ad authored by Fabien Combernous's avatar Fabien Combernous
Browse files

close #33

parent fbe6b649
No related branches found
No related tags found
1 merge request!31Resolve "Be able to use parameter to define archives path"
...@@ -8,6 +8,7 @@ All notable changes to this project will be documented in this file. ...@@ -8,6 +8,7 @@ All notable changes to this project will be documented in this file.
**Bugfixes** **Bugfixes**
* #33 Be able to use parameter to define archives path.
* #34 Use nokogiri provided by pdk for tests. * #34 Use nokogiri provided by pdk for tests.
* #35 Update README description. * #35 Update README description.
......
...@@ -107,6 +107,14 @@ Describes all availables settings in this module for all wordpress instances on ...@@ -107,6 +107,14 @@ Describes all availables settings in this module for all wordpress instances on
Default value: {} 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` ##### `wpcli_url`
Data type: `Pattern['^http']` Data type: `Pattern['^http']`
...@@ -177,6 +185,12 @@ Data type: `Pattern['^/']` ...@@ -177,6 +185,12 @@ Data type: `Pattern['^/']`
The PATH where the WP-CLI tools is deployed. 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` ##### `settings`
Data type: `Wordpress::Settings` Data type: `Wordpress::Settings`
...@@ -385,6 +399,12 @@ Data type: `String` ...@@ -385,6 +399,12 @@ Data type: `String`
The path of the WP-CLI tool. 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 ### wordpress::resource::activate
Activates an already installed resource aka plugin or theme. Activates an already installed resource aka plugin or theme.
......
...@@ -3,12 +3,16 @@ ...@@ -3,12 +3,16 @@
#@param wpcli_bin #@param wpcli_bin
# The PATH where the WP-CLI tools is deployed. # 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 #@param settings
# Describes all availables settings in this module for all wordpress instances on this node. Defaults to empty hash. # 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. #@note This class should be considered as private.
class wordpress::core ( class wordpress::core (
Pattern['^/'] $wpcli_bin, Pattern['^/'] $wpcli_bin,
Pattern['^/'] $wparchives_path,
Wordpress::Settings $settings = {}, Wordpress::Settings $settings = {},
) { ) {
...@@ -81,7 +85,7 @@ class wordpress::core ( ...@@ -81,7 +85,7 @@ class wordpress::core (
} }
} }
'latest': { 'latest': {
file { $::wordpress::params::wordpress_archives : file { $wparchives_path :
ensure => 'directory', ensure => 'directory',
mode => '0700', mode => '0700',
owner => 0, owner => 0,
...@@ -95,13 +99,14 @@ class wordpress::core ( ...@@ -95,13 +99,14 @@ class wordpress::core (
$_wp_core_update_status = $::facts['wordpress']["${_wp_servername}"]['core']['update'] $_wp_core_update_status = $::facts['wordpress']["${_wp_servername}"]['core']['update']
if $_wp_core_update_status != 'none' { if $_wp_core_update_status != 'none' {
wordpress::core::update { $_wp_servername : wordpress::core::update { $_wp_servername :
wp_servername => $_wp_servername, wp_servername => $_wp_servername,
wp_root => $_wp_root, wp_root => $_wp_root,
owner => $_owner, owner => $_owner,
locale => $_locale, locale => $_locale,
wpselfupdate => $_wpselfupdate, wpselfupdate => $_wpselfupdate,
wpcli_bin => $wpcli_bin, wpcli_bin => $wpcli_bin,
require => File[$::wordpress::params::wordpress_archives], wparchives_path => $wparchives_path,
require => File[$wparchives_path],
} }
} }
} else { } else {
...@@ -124,13 +129,14 @@ class wordpress::core ( ...@@ -124,13 +129,14 @@ class wordpress::core (
} }
-> ->
wordpress::core::update { $_wp_servername : wordpress::core::update { $_wp_servername :
wp_servername => $_wp_servername, wp_servername => $_wp_servername,
wp_root => $_wp_root, wp_root => $_wp_root,
owner => $_owner, owner => $_owner,
locale => $_locale, locale => $_locale,
wpselfupdate => $_wpselfupdate, wpselfupdate => $_wpselfupdate,
wpcli_bin => $wpcli_bin, wpcli_bin => $wpcli_bin,
require => File[$::wordpress::params::wordpress_archives], wparchives_path => $wparchives_path,
require => File[$wparchives_path],
} }
} }
} }
......
...@@ -2,16 +2,25 @@ ...@@ -2,16 +2,25 @@
# #
#@param wp_servername #@param wp_servername
# The URI of the WordPress instance (like : www.foo.org). # The URI of the WordPress instance (like : www.foo.org).
#
#@param wp_root #@param wp_root
# The root path of the WordPress instance. # The root path of the WordPress instance.
#
#@param owner #@param owner
# The OS account, owner of files of the WordPress instance. # The OS account, owner of files of the WordPress instance.
#
#@param locale #@param locale
# Language used by WordPress instance (defaults en_US). # Language used by WordPress instance (defaults en_US).
#
#@param wpselfupdate #@param wpselfupdate
# Possible values : disabled , enabled (defaults disabled). # Possible values : disabled , enabled (defaults disabled).
#
#@param wpcli_bin #@param wpcli_bin
# The path of the WP-CLI tool. # 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. #@note This defined type should be considered as private.
define wordpress::core::update ( define wordpress::core::update (
String $wp_servername, String $wp_servername,
...@@ -20,6 +29,7 @@ define wordpress::core::update ( ...@@ -20,6 +29,7 @@ define wordpress::core::update (
String $locale, String $locale,
String $wpselfupdate, String $wpselfupdate,
String $wpcli_bin, String $wpcli_bin,
String $wparchives_path,
) { ) {
# four steps : # four steps :
# 1. make a backup # 1. make a backup
...@@ -28,19 +38,19 @@ define wordpress::core::update ( ...@@ -28,19 +38,19 @@ define wordpress::core::update (
# 4. update language # 4. update language
$_date = strftime('%Y-%m-%d') $_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" : exec { "${wp_servername} > Export database before upgrade" :
command => "${wpcli_bin} --allow-root --path=${wp_root} db export", command => "${wpcli_bin} --allow-root --path=${wp_root} db export",
cwd => $_archives_path, cwd => $wparchives_path,
creates => "${_archives_path}/${wp_servername}_${_date}.tar.gz", creates => "${wparchives_path}/${wp_servername}_${_date}.tar.gz",
} }
-> ->
exec { "${wp_servername} > Archive files before upgrade" : 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, cwd => $wp_root,
creates => "${_archives_path}/${wp_servername}_${_date}.tar.gz", creates => "${wparchives_path}/${wp_servername}_${_date}.tar.gz",
} }
case $locale { case $locale {
......
...@@ -67,15 +67,22 @@ ...@@ -67,15 +67,22 @@
# #
#@param settings #@param settings
# Describes all availables settings in this module for all wordpress instances on this node. Defaults to empty hash. # 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 #@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'. # 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 #@param wpcli_bin
# Gives the path where the WP-CLI tools is deployed. Defaults to '/usr/local/bin/wp'. # Gives the path where the WP-CLI tools is deployed. Defaults to '/usr/local/bin/wp'.
#
#@param hour_fact_update #@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. # Gives the time (hour between 1 and 23) at which the update of external fact is done (use cron). Defaults to 7.
# #
class wordpress ( class wordpress (
Hash $settings = {}, Hash $settings = {},
Pattern['^/'] $wparchives_path = $wordpress::params::default_wparchives_path,
Pattern['^http'] $wpcli_url = $wordpress::params::default_wpcli_url, Pattern['^http'] $wpcli_url = $wordpress::params::default_wpcli_url,
Pattern['^/'] $wpcli_bin = $wordpress::params::default_wpcli_bin, Pattern['^/'] $wpcli_bin = $wordpress::params::default_wpcli_bin,
Integer[1,23] $hour_fact_update = $wordpress::params::default_hour_fact_update, Integer[1,23] $hour_fact_update = $wordpress::params::default_hour_fact_update,
...@@ -96,8 +103,9 @@ class wordpress ( ...@@ -96,8 +103,9 @@ class wordpress (
# * set condifguration settings # * set condifguration settings
# * connect to db server and create tables # * connect to db server and create tables
class { 'wordpress::core' : class { 'wordpress::core' :
settings => $settings, settings => $settings,
wpcli_bin => $wpcli_bin, wpcli_bin => $wpcli_bin,
wparchives_path => $wparchives_path,
} }
-> ->
# then manage others resources like plugins and themes # then manage others resources like plugins and themes
......
...@@ -26,7 +26,7 @@ class wordpress::params { ...@@ -26,7 +26,7 @@ class wordpress::params {
$default_wpselfupdate = 'disabled' $default_wpselfupdate = 'disabled'
$default_wpresource_ensure = 'present' $default_wpresource_ensure = 'present'
$wordpress_archives = '/var/wordpress_archives' $default_wparchives_path = '/var/wordpress_archives'
} }
...@@ -4,7 +4,7 @@ $wpcli_bin = '/usr/local/bin/wp' ...@@ -4,7 +4,7 @@ $wpcli_bin = '/usr/local/bin/wp'
$wp_root = '/var/www/wordpress.foo.org' $wp_root = '/var/www/wordpress.foo.org'
$wp2_root = '/var/www/wp2.foo.org' $wp2_root = '/var/www/wp2.foo.org'
$wp3_root = '/var/www/wp3.foo.org' $wp3_root = '/var/www/wp3.foo.org'
$wparchives = '/var/wordpress_archives' $wparchives = '/var/mywp_archives'
if fact('osfamily') == 'Debian' if fact('osfamily') == 'Debian'
$crontabs_path='/var/spool/cron/crontabs' $crontabs_path='/var/spool/cron/crontabs'
elsif fact('osfamily') == 'RedHat' elsif fact('osfamily') == 'RedHat'
...@@ -203,11 +203,12 @@ describe 'wordpress class' do ...@@ -203,11 +203,12 @@ describe 'wordpress class' do
end end
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 it 'applies idempotently' do
pp = <<-EOS pp = <<-EOS
class { 'wordpress': class { 'wordpress':
settings => { wparchives_path => '/var/mywp_archives',
settings => {
'wp2.foo.org' => { 'wp2.foo.org' => {
ensure => 'latest', ensure => 'latest',
owner => 'wp2', owner => 'wp2',
......
...@@ -4,6 +4,7 @@ describe 'wordpress::core' do ...@@ -4,6 +4,7 @@ describe 'wordpress::core' do
let :default_params do let :default_params do
{ {
wpcli_bin: '/bin/wpcli', wpcli_bin: '/bin/wpcli',
wparchives_path: '/var/archives',
} }
end end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment