diff --git a/README.md b/README.md index c8b480a0f698599cd9b3a7b7a69c7908d5796f5b..4860848f7ee1995b74eb529638085a129af800ff 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ They have to be created before for instance by `puppetlabs-mysql`, `puppetlabs-a ### Setup Requirements -This `wordpress` module use `cron` service and depends on `puppetlabs-stdlib` and `puppet-archive` +This `wordpress` module depends on `puppetlabs-stdlib` and `puppet-archive` ### Beginning with wordpress diff --git a/REFERENCE.md b/REFERENCE.md index ced31fad36c794bbff3520cbd115d930567a8d10..c0dd13cdecc17b13dce35f2ca33446527d7a723a 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -143,7 +143,7 @@ Default value: $wordpress::params::default_wpcli_bin Data type: `Integer[1,23]` -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. Defaults to 7. Default value: $wordpress::params::default_hour_fact_update diff --git a/manifests/core.pp b/manifests/core.pp index 03dda1d76846aa4899bb45141b7e173e829af0c6..a9e4f144f8c92f04a94ba6ce4a186d38fbf36ee7 100644 --- a/manifests/core.pp +++ b/manifests/core.pp @@ -100,7 +100,7 @@ class wordpress::core ( exec { "${_wp_servername} > Erase wordpress": command => "rm -Rf ${_real_wproot}/*", onlyif => "test -f ${_real_wproot}/wp-config.php", - notify => Exec['update external fact wordpress'], + notify => Exec['updates external fact wordpress'], } } 'latest': { diff --git a/manifests/core/install.pp b/manifests/core/install.pp index 69a79f68d21a6bb35e7739ebc51397774e10074d..ff2995a0117284cef04d948d030cd7d4f2a30419 100644 --- a/manifests/core/install.pp +++ b/manifests/core/install.pp @@ -76,7 +76,7 @@ define wordpress::core::install ( cwd => $wp_root, creates => "${wp_root}/wp-config.php", user => $owner, - notify => Exec['update external fact wordpress'], + notify => Exec['updates external fact wordpress'], } # the database, granted user and credentials must be already created by other process @@ -89,7 +89,7 @@ define wordpress::core::install ( Exec["${wp_servername} > Create wp-config.php"], ], refreshonly => true, - notify => Exec['update external fact wordpress'], + notify => Exec['updates external fact wordpress'], } } diff --git a/manifests/core/update.pp b/manifests/core/update.pp index 67217618a228179ffaa1d637be1b19f62435740e..89e3f8f842cb07ad917a748337290030b584b730 100644 --- a/manifests/core/update.pp +++ b/manifests/core/update.pp @@ -84,6 +84,6 @@ define wordpress::core::update ( user => $owner, subscribe => Exec["${wp_servername} > Update database structure"], refreshonly => true, - notify => Exec['update external fact wordpress'], + notify => Exec['updates external fact wordpress'], } } diff --git a/manifests/external_fact.pp b/manifests/external_fact.pp index c7803161b818d8ccc84838a47d1c1a65fd090af0..47822958e0ad16834d467af978bee8f324e10143 100644 --- a/manifests/external_fact.pp +++ b/manifests/external_fact.pp @@ -12,7 +12,6 @@ class wordpress::external_fact ( Wordpress::Settings $settings = {}, ) { - $_minute = fqdn_rand(59) $_fact_script_path = '/usr/local/sbin/external_fact_wordpress.rb' $_fact_output_yaml = '/opt/puppetlabs/facter/facts.d/wordpress.yaml' @@ -33,21 +32,24 @@ class wordpress::external_fact ( owner => 0, group => 0, mode => '0755', - notify => Exec['update external fact wordpress'], + notify => Exec['updates external fact wordpress'], } - -> - exec { 'update external fact wordpress': + + exec { 'updates external fact wordpress': command => "${_fact_script_path} > ${_fact_output_yaml}", user => 'root', refreshonly => true, } - cron { 'external_fact workpress update': - command => "${_fact_script_path} > ${_fact_output_yaml} &> /dev/null", - environment => 'PATH=/usr/local/sbin:/usr/local/bin:/opt/puppetlabs/bin:/usr/sbin:/usr/bin:/sbin:/bin', - user => 'root', - hour => $hour_fact_update, - minute => $_minute, + exec { 'daily update external fact wordpress': + command => "${_fact_script_path} > ${_fact_output_yaml}", + user => 'root', + schedule => 'external_fact update', + } + + schedule { 'external_fact update': + period => daily, + range => "${hour_fact_update}:01 - ${hour_fact_update}:59", } } diff --git a/manifests/init.pp b/manifests/init.pp index dfded332657850402b882d71e2c3c44243a17018..ceab3cbd3da3e9f3efece97dc7d648636eba168f 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -78,7 +78,7 @@ # 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. +# Gives the time (hour between 1 and 23) at which the update of external fact is done. Defaults to 7. # class wordpress ( Hash $settings = {}, diff --git a/manifests/resource/activate.pp b/manifests/resource/activate.pp index 95e28884e7addc65db2641a9a700f5fa06c14a13..c04490e6598c7559ed4481b6e64130bd1b7152df 100644 --- a/manifests/resource/activate.pp +++ b/manifests/resource/activate.pp @@ -29,6 +29,6 @@ define wordpress::resource::activate ( "${wpcli_bin} --format=csv --path=${wp_root} --fields=name,status ${wp_resource_type} list | grep -qP '^${wp_resource_name},inactive'", ] , user => $owner, - notify => Exec['update external fact wordpress'], + notify => Exec['updates external fact wordpress'], } } diff --git a/manifests/resource/install.pp b/manifests/resource/install.pp index 90c00d0a73964578e2605cb1239db96737704f98..d77a3da4883b230bd049e03b1a73069e3544c64c 100644 --- a/manifests/resource/install.pp +++ b/manifests/resource/install.pp @@ -26,6 +26,6 @@ define wordpress::resource::install ( command => "${wpcli_bin} --path=${wp_root} ${wp_resource_type} install ${wp_resource_name}", unless => "${wpcli_bin} --path=${wp_root} ${wp_resource_type} is-installed ${wp_resource_name}", user => $owner, - notify => Exec['update external fact wordpress'], + notify => Exec['updates external fact wordpress'], } } diff --git a/manifests/resource/uninstall.pp b/manifests/resource/uninstall.pp index 37fec4c7eb892fe579903342b33fd0663a50dc95..c98df282b9283807c95475f7aaac28ae68fe735e 100644 --- a/manifests/resource/uninstall.pp +++ b/manifests/resource/uninstall.pp @@ -26,6 +26,6 @@ define wordpress::resource::uninstall ( command => "${wpcli_bin} --path=${wp_root} ${wp_resource_type} uninstall ${wp_resource_name}", onlyif => "${wpcli_bin} --path=${wp_root} ${wp_resource_type} is-installed ${wp_resource_name}", user => $owner, - notify => Exec['update external fact wordpress'], + notify => Exec['updates external fact wordpress'], } } diff --git a/manifests/resource/update.pp b/manifests/resource/update.pp index 63904b21bc1336b1e82aee0bd5881a9fc1c351f1..ef0b98f6190b96b7d41b59118d43725113c8a7a8 100644 --- a/manifests/resource/update.pp +++ b/manifests/resource/update.pp @@ -26,6 +26,6 @@ define wordpress::resource::update ( command => "${wpcli_bin} --path=${wp_root} ${wp_resource_type} update ${wp_resource_name}", onlyif => "${wpcli_bin} --format=csv --path=${wp_root} --update=available ${wp_resource_type} list | grep -qP '^${wp_resource_name},", user => $owner, - notify => Exec['update external fact wordpress'], + notify => Exec['updates external fact wordpress'], } } diff --git a/spec/acceptance/wordpress_spec.rb b/spec/acceptance/wordpress_spec.rb index 40242548be252f294c97c1c2cf17d9b31ed674bb..d35f1c5ca0d262fc39f99226e5887721dfd19426 100644 --- a/spec/acceptance/wordpress_spec.rb +++ b/spec/acceptance/wordpress_spec.rb @@ -6,13 +6,7 @@ wp_root = "/var/www/#{myfqdn}" wp2_root = '/var/www/wp2.foo.org' wp3_root = '/var/www/wp3.foo.org' wparchives = '/var/mywp_archives' -crontabs_path = if fact('osfamily') == 'Debian' - '/var/spool/cron/crontabs' - elsif fact('osfamily') == 'RedHat' - '/var/spool/cron/' - else - '/unsupported_OS' - end +external_fact = '/opt/puppetlabs/facter/facts.d/wordpress.yaml' describe 'wordpress class' do context 'with defaults parameters' do @@ -54,8 +48,12 @@ describe 'wordpress class' do apply_manifest(pp, catch_changes: true) end - describe file("#{crontabs_path}/root") do - it { is_expected.to contain('7 * * * /usr/local/sbin/external_fact_wordpress.rb > /opt/puppetlabs/facter/facts.d/wordpress.yaml') } + describe file(external_fact.to_s) do + it { is_expected.to be_file } + it { is_expected.to be_owned_by 'root' } + it { is_expected.to be_grouped_into 'root' } + it { is_expected.to be_mode 644 } + its(:content) { is_expected.to match %r{---.+wordpress.+localhost.+}m } end describe file(wpcli_bin.to_s) do @@ -120,10 +118,6 @@ describe 'wordpress class' do apply_manifest(pp, catch_failures: true) apply_manifest(pp, catch_changes: true) end - - describe file("#{crontabs_path}/root") do - it { is_expected.to contain('3 * * * /usr/local/sbin/external_fact_wordpress.rb > /opt/puppetlabs/facter/facts.d/wordpress.yaml') } - end end context 'with parameters setting new password for admin user and new title for site ' do @@ -198,6 +192,14 @@ describe 'wordpress class' do apply_manifest(pp, catch_changes: true) end + describe file(external_fact.to_s) do + it { is_expected.to be_file } + it { is_expected.to be_owned_by 'root' } + it { is_expected.to be_grouped_into 'root' } + it { is_expected.to be_mode 644 } + its(:content) { is_expected.to match %r{---.+localhost.+akismet.+twentyseventeen.+}m } + end + describe file(wpcli_bin.to_s) do it { is_expected.to be_file } it { is_expected.to be_owned_by 'root' } @@ -242,10 +244,6 @@ describe 'wordpress class' do describe command("/usr/local/bin/wp --allow-root --format=csv --path=#{wp_root} --fields=name,status theme list") do its(:stdout) { is_expected.not_to match %r{.*twentysixteen,active.*} } end - - describe file("#{crontabs_path}/root") do - it { is_expected.to contain('7 * * * /usr/local/sbin/external_fact_wordpress.rb > /opt/puppetlabs/facter/facts.d/wordpress.yaml') } - end end context 'with parameters about two wordpress instances with customs locales and archives path' do @@ -294,6 +292,14 @@ describe 'wordpress class' do apply_manifest(pp, catch_changes: true) end + describe file(external_fact.to_s) do + it { is_expected.to be_file } + it { is_expected.to be_owned_by 'root' } + it { is_expected.to be_grouped_into 'root' } + it { is_expected.to be_mode 644 } + its(:content) { is_expected.to match %r{---.+wp2.+wp3.*}m } + end + describe file(wpcli_bin.to_s) do it { is_expected.to be_file } it { is_expected.to be_owned_by 'root' } diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index c6797ce07561e0db11d7533595281114acd1a8af..fceec94b85fa097d24cd53db9ec72adedc6b134f 100644 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -37,8 +37,7 @@ RSpec.configure do |c| elsif host[:platform] =~ %r{ubuntu-16.04-amd64} on(host, 'apt-get update', acceptable_exit_codes: [0]).stdout # curl is used in tests to access at a wordpress newly installed - # cron package is not install on docker image - on(host, 'apt install cron curl php7.0-cli php7.0-mysql --yes', acceptable_exit_codes: [0]).stdout + on(host, 'apt install curl php7.0-cli php7.0-mysql --yes', acceptable_exit_codes: [0]).stdout end end diff --git a/templates/external_fact_wordpress.rb.erb b/templates/external_fact_wordpress.rb.erb index 3287700106c2d5e438a5bf163bc94212fc76d687..9a3471b9e5ac9d800e6d16577bbe9d67a5a88cfc 100755 --- a/templates/external_fact_wordpress.rb.erb +++ b/templates/external_fact_wordpress.rb.erb @@ -1,6 +1,6 @@ #!/opt/puppetlabs/puppet/bin/ruby -# This ruby script is planed to be executer about one time a day with cron. +# This ruby script is planed to be executer about one time a day with puppet schedule type. # And the yaml output redirected to a file in facter.d directory to produce an external fact. # This setup is like this because a fact in a standard way is updated during each run. # And we do not need update of the infirmation so often.