From 114cb60c97d1b5e9e654954fb8042881d9905ef9 Mon Sep 17 00:00:00 2001 From: Loren Osborn Date: Sun, 24 Nov 2013 03:05:23 -0800 Subject: [PATCH] Fix for issues with ini file on Ubuntu This is a first pass work around. I'm new to Puppet and really don't know what I'm doing, so please give feedback about what I missed. -Thanks --- lib/facter/php_fact_web_ini_file_path.rb | 55 ++++++++++++++++++++++++ manifests/ini.pp | 13 +++--- manifests/params.pp | 20 +++++++-- 3 files changed, 78 insertions(+), 10 deletions(-) create mode 100644 lib/facter/php_fact_web_ini_file_path.rb diff --git a/lib/facter/php_fact_web_ini_file_path.rb b/lib/facter/php_fact_web_ini_file_path.rb new file mode 100644 index 0000000..4de79cc --- /dev/null +++ b/lib/facter/php_fact_web_ini_file_path.rb @@ -0,0 +1,55 @@ +# The path to the php.ini file for apache appears to be the first null terminated string +# in the module binary after the null terminated string "PHP_CONFIG_FILE_PATH". This may +# or may not hold for other versions of php, so a sanity check to make sure that the +# directory is an existing file. +# The location of the module binary is obtained from the module's *php5*.load file +# included in Apache's config file determined from rules borrowed from +# example42/puppet-apache + + +apache_conf_path = '/etc/httpd/conf/httpd.conf' +if /Ubuntu|Debian|Mint/i.match(Facter.value("operatingsystem")) + apache_conf_path = '/etc/apache2/apache2.conf' +elsif /SLES|OpenSuSE/i.match(Facter.value("operatingsystem")) + apache_conf_path = '/etc/apache2/httpd.conf' +elsif Facter.value("operatingsystem") == 'freebsd' + apache_conf_path = '/usr/local/etc/apache20/httpd.conf' +end + +find_php_ini_path_shell_command = + "if [ -f '" + apache_conf_path + "' ] ; then " + + 'ls -d $( ' + + 'grep -azA 1 ' + + "'^PHP_CONFIG_FILE_PATH\$' " + + '$( ' + + "sed -e 's/\\s*\$//' -e 's/^.*\\s//' " + + '$( ' + + 'ls -1 $( ' + + "echo -n '" + apache_conf_path + "' | " + + "sed -e 'sx/[^/]*\$xx' ; " + + 'echo -n / ; ' + + "grep 'mod.*\\.load\$' '" + apache_conf_path + "' | " + + "sed -e 's/\\s*\$//' -e 's/^.*\\s//' " + + ') | ' + + 'grep php5 ' + + ') ' + + ') | ' + + "tr '\\000' '\\012' | " + + "grep '^/' " + + ') 2> /dev/null ; ' + + 'fi' + + +Facter.add("php_fact_web_ini_file_path") do + setcode do + result = nil + begin + result = Facter::Util::Resolution.exec(find_php_ini_path_shell_command) || nil + if result + result = (result + '/php.ini') + end + rescue + end + result + end +end \ No newline at end of file diff --git a/manifests/ini.pp b/manifests/ini.pp index 2851aa4..9908015 100644 --- a/manifests/ini.pp +++ b/manifests/ini.pp @@ -1,16 +1,17 @@ # = Define: php::ini # define php::ini ( - $value = '', - $template = 'extra-ini.erb', - $target = 'extra.ini', - $service = $php::service, - $config_dir = $php::config_dir + $value = '', + $template = 'extra-ini.erb', + $target = 'extra.ini', + $service = $php::service, + $config_dir = $php::config_dir, + $web_config_dir = $php::web_config_dir ) { include php - file { "${config_dir}/conf.d/${target}": + file { "${web_config_dir}/conf.d/${target}": ensure => 'present', content => template("php/${template}"), require => Package['php'], diff --git a/manifests/params.pp b/manifests/params.pp index 8da0d51..e4f5905 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -56,10 +56,22 @@ /(?i:Ubuntu|Debian|Mint|SLES|OpenSuSE)/ => '/etc/php5', default => '/etc/php.d', } - - $config_file = $::operatingsystem ? { - /(?i:Ubuntu|Debian|Mint|SLES|OpenSuSE)/ => '/etc/php5/apache2/php.ini', - default => '/etc/php.ini', + + if $::php_fact_web_ini_file_path =~ /\/conf\.d\/php\.ini$/ { + $web_config_dir = regsubst($::php_fact_web_ini_file_path, '/conf\.d/php\.ini$', '') + } elsif $::operatingsystem =~ /(?i:Ubuntu)/ { + $web_config_dir = '/etc/php5/apache2' + } else { + $web_config_dir = $config_dir + } + + if $::php_fact_web_ini_file_path != '' { + $config_file = $::php_fact_web_ini_file_path + } else { + $config_file = $::operatingsystem ? { + /(?i:Ubuntu|Debian|Mint|SLES|OpenSuSE)/ => '/etc/php5/apache2/php.ini', + default => '/etc/php.ini', + } } $config_file_mode = $::operatingsystem ? {