├── .fixtures.yml ├── .gemfile ├── .github ├── CONTRIBUTING.md ├── ISSUE_TEMPLATE.md └── PULL_REQUEST_TEMPLATE.md ├── .gitignore ├── .project ├── .travis.yml ├── LICENSE ├── README.md ├── Rakefile ├── lib └── facter │ ├── php_fact_extension_dir.rb │ └── php_fact_version.rb ├── manifests ├── augeas.pp ├── conf.pp ├── devel.pp ├── ini.pp ├── init.pp ├── mod.pp ├── module.pp ├── params.pp ├── pear.pp ├── pear │ ├── config.pp │ └── module.pp ├── pecl │ ├── config.pp │ └── module.pp └── spec.pp ├── metadata.json ├── spec ├── classes │ └── php_spec.rb ├── defines │ ├── php_ini_spec.rb │ ├── php_module_spec.rb │ └── php_pear_module_spec.rb └── spec_helper.rb └── templates ├── extra-ini.erb └── spec.erb /.fixtures.yml: -------------------------------------------------------------------------------- 1 | fixtures: 2 | repositories: 3 | "puppi": "git://github.com/example42/puppi.git" 4 | "monitor": "git://github.com/example42/puppet-monitor.git" 5 | "firewall": "git://github.com/example42/puppet-firewall.git" 6 | "iptables": "git://github.com/example42/puppet-iptables.git" 7 | "concat": "git://github.com/puppetlabs/puppetlabs-concat.git" 8 | "stdlib": "git://github.com/puppetlabs/puppetlabs-stdlib.git" 9 | symlinks: 10 | "php": "#{source_dir}" 11 | 12 | -------------------------------------------------------------------------------- /.gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | puppetversion = ENV['PUPPET_VERSION'] 4 | gem 'puppet', puppetversion, :require => false 5 | gem 'puppet-lint' 6 | gem 'rspec', '~> 3.1.0', :platforms => :ruby_18 7 | gem 'puppetlabs_spec_helper', '>= 0.1.0' 8 | gem 'json_pure', '2.0.1' 9 | gem 'rake', '~> 10.5.0' 10 | -------------------------------------------------------------------------------- /.github/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | ## How to Contribute to This Project 2 | 3 | #### **Did You Find a Bug?** 4 | 5 | * **Ensure the bug was not already reported** by searching on GitHub under **Issues**. 6 | * If you're unable to find an open issue addressing the problem, **open a new one**. Be sure to include a **title and clear description**, as much relevant information as possible, and a **code sample** or an **executable test case** demonstrating the expected behavior that is not occurring. 7 | 8 | #### **Did You Write a Patch That Fixes a Bug?** 9 | 10 | * Open a new GitHub pull request with the patch. 11 | 1. Fork this project 12 | 1. Create your feature branch: `git checkout -b my-new-feature` 13 | 1. Commit your changes: `git commit -am 'Add some feature'` 14 | 1. Push to the branch: `git push origin my-new-feature` 15 | 1. Submit a pull request via GitHub's web interface 16 | * Ensure the PR description clearly describes the problem and its solution. Include the relevant issue number if applicable. 17 | 18 | #### **Do You Intend to Add a New Feature or Change an Existing One?** 19 | 20 | * Suggest your change as a **new issue** using the label `enhancement` **BEFORE** you start writing code. 21 | 22 | #### **Do You Want to Sponsor Open Source Development?** 23 | 24 | If you need express resolution of a bug or new features you can consider the opportunity of **sponsoring** the relevant development. 25 | 26 | * Open an issue on GitHub (of type `bug` or `enhancement`) with the details of what you want 27 | * Contact [example42](http://www.example42.com/#contact) referring the issue you created 28 | * Tell us how you want to sponsor the development (sending money, gifts or offering services) 29 | * If we agree on the conditions we will place your [company] name in the module's Sponsors List 30 | 31 | Thanks for contributing! :heart: 32 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ## Expected Behavior 2 | 3 | 4 | ## Actual Behavior 5 | 6 | 7 | ## Steps to Reproduce the Problem 8 | 9 | 1. 10 | 1. 11 | 1. 12 | 13 | ## Specifications 14 | 15 | Please add this info: 16 | 17 | 1. Output of ```facter -p``` on the failing node (at least the OS related facts) 18 | 1. Version of Puppet and of the module 19 | 1. The relevant Puppet code and eventually Hiera data 20 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ## Before submitting your PR 2 | 3 | 1. Open an **issue** and refer to its number in your PR title 4 | 1. If it's a bug and you have the solution, go on with the PR! 5 | 1. If it's an enhancement, please wait for our feedback before starting to work on it 6 | 1. Please run ```puppet-lint``` on your code and ensure it's compliant 7 | 8 | ## After submitting your PR 9 | 10 | 1. Verify Travis checks and eventually fix the errors 11 | 1. Feel free to ping us if we don't reply promptly 12 | 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.gradle 2 | /.rvmrc 3 | build 4 | pkg/ 5 | Session.vim 6 | spec/fixtures 7 | .*.sw[a-z] 8 | *.un~ 9 | .gemfile.lock 10 | .bundle 11 | vendor 12 | 13 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | php 4 | 5 | 6 | 7 | 8 | 9 | com.puppetlabs.geppetto.pp.dsl.ui.modulefileBuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.xtext.ui.shared.xtextBuilder 15 | 16 | 17 | 18 | 19 | 20 | com.puppetlabs.geppetto.pp.dsl.ui.puppetNature 21 | org.eclipse.xtext.ui.shared.xtextNature 22 | 23 | 24 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: ruby 2 | rvm: 3 | - 1.8.7 4 | - 1.9.3 5 | script: 6 | - "bundle exec rake spec SPEC_OPTS='--format documentation'" 7 | env: 8 | - PUPPET_VERSION="~> 2.6.0" 9 | - PUPPET_VERSION="~> 2.7.0" 10 | - PUPPET_VERSION="~> 3.1.0" 11 | - PUPPET_VERSION="~> 3.6.0" 12 | matrix: 13 | exclude: 14 | - rvm: 1.9.3 15 | env: PUPPET_VERSION="~> 2.6.0" 16 | gemfile: .gemfile 17 | allow_failures: 18 | - rvm: 1.8.7 19 | env: PUPPET_VERSION="~> 2.6.0" 20 | gemfile: .gemfile 21 | 22 | gemfile: .gemfile 23 | notifications: 24 | email: 25 | - al@lab42.it 26 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (C) 2013 Alessandro Franceschi / Lab42 2 | 3 | for the relevant commits Copyright (C) by the respective authors. 4 | 5 | Contact Lab42 at: info@lab42.it 6 | 7 | Licensed under the Apache License, Version 2.0 (the "License"); 8 | you may not use this file except in compliance with the License. 9 | You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | 13 | Unless required by applicable law or agreed to in writing, software 14 | distributed under the License is distributed on an "AS IS" BASIS, 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | See the License for the specific language governing permissions and 17 | limitations under the License. 18 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Deprecation notice 2 | 3 | This module was designed for Puppet versions 2 and 3. It should work also on Puppet 4 but doesn't use any of its features. 4 | 5 | The current Puppet 3 compatible codebase is no longer actively maintained by example42. 6 | 7 | Still, Pull Requests that fix bugs or introduce backwards compatible features will be accepted. 8 | 9 | 10 | # Puppet module: php 11 | 12 | This is a Puppet module for php based on the second generation layout ("NextGen") of Example42 Puppet Modules. 13 | 14 | Made by ALessandro Franceschi / Lab42 15 | 16 | Official site: http://www.example42.com 17 | 18 | Official git repository: http://github.com/example42/puppet-php 19 | 20 | Released under the terms of Apache 2 License. 21 | 22 | This module requires functions provided by the Example42 Puppi module (you need it even if you don't use and install Puppi) 23 | 24 | For detailed info about the logic and usage patterns of Example42 modules check the DOCS directory on Example42 main modules set. 25 | 26 | ## USAGE - Basic management 27 | 28 | * Install php with default settings 29 | 30 | class { 'php': } 31 | 32 | * Install a specific version of php package 33 | 34 | class { 'php': 35 | version => '1.0.1', 36 | } 37 | 38 | * Remove php package 39 | 40 | class { 'php': 41 | absent => true 42 | } 43 | 44 | * Enable auditing without without making changes on existing php configuration files 45 | 46 | class { 'php': 47 | audit_only => true 48 | } 49 | 50 | * Define nginx service to be notified on changes 51 | 52 | class { 'php': 53 | service => 'nginx' 54 | } 55 | 56 | ## USAGE - Module installation 57 | 58 | * Install a new module 59 | 60 | php::module { "imagick": } 61 | 62 | * Install a specific version of a module: 63 | 64 | php::module { "imagick": 65 | version => '1.0.1'; 66 | } 67 | 68 | * Remove php module 69 | 70 | php::module { "imagick": 71 | absent => true, 72 | } 73 | 74 | * By default module package name is php-$title for RedHat and php5-$title . You can override this prefix. 75 | 76 | php::module { "apc": 77 | module_prefix => "php-" 78 | } 79 | 80 | ## USAGE - Module Configuration 81 | 82 | * Configure php module to all SAPI 83 | 84 | php::mod { "mcrypt": } 85 | 86 | *__Note:__ `[name]` is filename without `.ini` extension from `/etc/php5/mods-available/.ini`* 87 | 88 | * Configure multiple php module to all SAPI 89 | 90 | $mods = ["mcrypt", "mongo"] 91 | php::mod { "$mods": } 92 | 93 | * Unconfigure php module to all SAPI 94 | 95 | php::mod { "xdebug" 96 | disable => true, 97 | } 98 | 99 | * Installing and configuring a Module. This will guarantee correct execution order in your classes 100 | 101 | php::module { 'sqlite': } -> php::mod { 'sqlite3': } 102 | 103 | ## USAGE - Pear Management 104 | 105 | * Install a pear package 106 | 107 | php::pear::module { "XML_Util": } 108 | 109 | * Install a pear package from a remote repository 110 | 111 | php::pear::module { 'PHPUnit': 112 | repository => 'pear.phpunit.de', 113 | use_package => 'no', 114 | } 115 | 116 | * Install a pear package will all dependencies (--alldeps) 117 | 118 | php::pear::module { 'PHPUnit': 119 | repository => 'pear.phpunit.de', 120 | alldeps => 'true', 121 | } 122 | 123 | * Set a config option 124 | 125 | php::pear::config { http_proxy: value => "myproxy:8080" } 126 | 127 | 128 | ## USAGE - Pecl Management 129 | 130 | * Install a pecl package 131 | 132 | php::pecl::module { "XML_Util": } 133 | 134 | * Install a pecl package from source specifying the preferred state (note that you must have the package 'make' installed on your system) 135 | 136 | php::pecl::module { "xhprof": 137 | use_package => 'false', 138 | preferred_state => 'beta', 139 | } 140 | 141 | * Set a config option 142 | 143 | php::pecl::config { http_proxy: value => "myproxy:8080" } 144 | 145 | * Auto-answer prompts for unattended-installation (where configure might used used for instance) 146 | 147 | php::pecl::module { 'stomp': 148 | use_package => 'false', 149 | auto_answer => 'no\\n\\n', 150 | } 151 | 152 | ## USAGE - Overrides and Customizations 153 | * Use custom sources for main config file. 154 | 155 | class { 'php': 156 | source => [ "puppet:///modules/lab42/php/php.conf-${hostname}" , "puppet:///modules/lab42/php/php.conf" ], 157 | } 158 | 159 | * Manage php.ini files on Debian and Suse derivatives. Here the main config file path (managed with the source/template params) defaults to /etc/php5/apache2/php.ini. To manage other files, either set a different path in config_file or use the php::conf define. 160 | 161 | class { 'php': 162 | config_file => '/etc/php5/apache2/php.ini', # Default value on Ubuntu/Suse 163 | template => 'example42/php/php.ini-apache2.erb', 164 | } 165 | 166 | php::conf { 'php.ini-cli': 167 | path => '/etc/php5/cli/php.ini', 168 | template => 'example42/php/php.ini-cli.erb', 169 | } 170 | 171 | * Use custom source directory for the whole configuration dir 172 | 173 | class { 'php': 174 | source_dir => 'puppet:///modules/lab42/php/conf/', 175 | source_dir_purge => false, # Set to true to purge any existing file not present in $source_dir 176 | } 177 | 178 | * Use custom template for main config file. Note that template and source arguments are alternative. 179 | 180 | class { 'php': 181 | template => 'example42/php/php.conf.erb', 182 | } 183 | 184 | * Automatically include a custom subclass 185 | 186 | class { 'php': 187 | my_class => 'php::example42', 188 | } 189 | 190 | 191 | 192 | 193 | 194 | [![Build Status](https://travis-ci.org/example42/puppet-php.png?branch=master)](https://travis-ci.org/example42/puppet-php) 195 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require 'rubygems' 2 | require 'puppetlabs_spec_helper/rake_tasks' 3 | require 'puppet-lint' 4 | PuppetLint.configuration.send("disable_80chars") 5 | PuppetLint.configuration.send('disable_class_parameter_defaults') 6 | -------------------------------------------------------------------------------- /lib/facter/php_fact_extension_dir.rb: -------------------------------------------------------------------------------- 1 | Facter.add("php_fact_extension_dir") do 2 | setcode do 3 | Facter::Util::Resolution.exec('php -r "ini_alter(\'date.timezone\',\'UTC\'); phpinfo();"|grep \'^extension_dir\'|awk \'{ print $3 }\'') || nil 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /lib/facter/php_fact_version.rb: -------------------------------------------------------------------------------- 1 | Facter.add("php_fact_version") do 2 | setcode do 3 | Facter::Util::Resolution.exec('php -v|awk \'{ print $2 }\'|head -n1') || nil 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /manifests/augeas.pp: -------------------------------------------------------------------------------- 1 | # = Define: php::augeas 2 | # 3 | # Manage php.ini through augeas 4 | # 5 | # Here's an example how to find the augeas path to a variable: 6 | # 7 | # # augtool --noload 8 | # augtool> rm /augeas/load 9 | # rm : /augeas/load 781 10 | # augtool> set /augeas/load/myfile/lens @PHP 11 | # augtool> set /augeas/load/myfile/incl /usr/local/etc/php5/cgi/php.ini 12 | # augtool> load 13 | # augtool> print 14 | # ... 15 | # /files/usr/local/etc/php5/cgi/php.ini/soap/soap.wsdl_cache_limit = "5" 16 | # /files/usr/local/etc/php5/cgi/php.ini/ldap/ldap.max_links = "-1" 17 | # ... 18 | # augtool> exit 19 | # # 20 | # 21 | # The part after 'php.ini/' is what you need to use as 'entry'. 22 | # 23 | # == Parameters 24 | # 25 | # [*entry*] 26 | # Augeas path to entry to be modified. 27 | # 28 | # [*ensure*] 29 | # Standard puppet ensure variable 30 | # 31 | # [*target*] 32 | # Which php.ini to manipulate. Default is $php::config_file 33 | # 34 | # [*value*] 35 | # Value to set 36 | # 37 | # == Examples 38 | # 39 | # php::augeas { 40 | # 'php-memorylimit': 41 | # entry => 'PHP/memory_limit', 42 | # value => '128M'; 43 | # 'php-error_log': 44 | # entry => 'PHP/error_log', 45 | # ensure => absent; 46 | # 'php-sendmail_path': 47 | # entry => 'mail function/sendmail_path', 48 | # value => '/usr/sbin/sendmail -t -i -f info@example.com'; 49 | # 'php-date_timezone': 50 | # entry => 'Date/date.timezone', 51 | # value => 'Europe/Amsterdam'; 52 | # } 53 | # 54 | define php::augeas ( 55 | $entry, 56 | $ensure = present, 57 | $target = $php::config_file, 58 | $value = '', 59 | ) { 60 | 61 | include php 62 | 63 | $service = $php::service 64 | 65 | $changes = $ensure ? { 66 | present => [ "set '${entry}' '${value}'" ], 67 | absent => [ "rm '${entry}'" ], 68 | require => Package[$php::package], 69 | } 70 | 71 | augeas { "php_ini-${name}": 72 | incl => $target, 73 | lens => 'Php.lns', 74 | changes => $changes, 75 | require => Package[$php::package], 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /manifests/conf.pp: -------------------------------------------------------------------------------- 1 | # 2 | # = Define: php::conf 3 | # 4 | # With this define you can manage any php configuration file 5 | # You have 3 parameters to provide it: source, template and content. 6 | # 7 | # == Parameters 8 | # 9 | # [*template*] 10 | # String. Optional. Default: undef. Alternative to: source, content. 11 | # Sets the module path of a custom template to use as content of 12 | # the config file 13 | # When defined, config file has: content => content($template), 14 | # Example: template => 'site/php/my.conf.erb', 15 | # 16 | # [*content*] 17 | # String. Optional. Default: undef. Alternative to: template, source. 18 | # Sets directly the value of the file's content parameter 19 | # When defined, config file has: content => $content, 20 | # Example: content => "# File Managed by Puppet \n", 21 | # 22 | # [*source*] 23 | # String. Optional. Default: undef. Alternative to: template, content. 24 | # Sets the value of the file's source parameter 25 | # When defined, config file has: source => $source, 26 | # Example: source => 'puppet:///site/php/my.conf', 27 | # 28 | # [*ensure*] 29 | # String. Default: present 30 | # Manages config file presence. Possible values: 31 | # * 'present' - Create and manages the file. 32 | # * 'absent' - Remove the file. 33 | # 34 | # [*path*] 35 | # String. Optional. Default: $config_dir/$title 36 | # The path of the created config file. If not defined a file 37 | # name like the the name of the title a custom template to use as content of configfile 38 | # If defined, configfile file has: content => content("$template") 39 | # 40 | # [*mode*] [*owner*] [*group*] [*notify*] [*replace*] 41 | # String. Optional. Default: undef 42 | # All these parameters map directly to the created file attributes. 43 | # If not defined the module's defaults are used. 44 | # If defined, config file file has, for example: mode => $mode 45 | # 46 | # [*options_hash*] 47 | # Hash. Default undef. Needs: 'template'. 48 | # An hash of custom options to be used in templates to manage any key pairs of 49 | # arbitrary settings. 50 | # 51 | define php::conf ( 52 | 53 | $source = undef, 54 | $template = undef, 55 | $content = undef, 56 | 57 | $path = undef, 58 | $mode = undef, 59 | $owner = undef, 60 | $group = undef, 61 | $notify = undef, 62 | $replace = undef, 63 | 64 | $options_hash = undef, 65 | 66 | $ensure = present ) { 67 | 68 | validate_re($ensure, ['present','absent'], 'Valid values are: present, absent. WARNING: If set to absent the conf file is removed.') 69 | 70 | include php 71 | 72 | $managed_path = $path ? { 73 | undef => "${php::config_dir}/${name}", 74 | default => $path, 75 | } 76 | 77 | $managed_content = $content ? { 78 | undef => $template ? { 79 | undef => undef, 80 | default => template($template), 81 | }, 82 | default => $content, 83 | } 84 | 85 | $managed_mode = $mode ? { 86 | undef => $php::config_file_mode, 87 | default => $mode, 88 | } 89 | 90 | $managed_owner = $owner ? { 91 | undef => $php::config_file_owner, 92 | default => $owner, 93 | } 94 | 95 | $managed_group = $group ? { 96 | undef => $php::config_file_group, 97 | default => $group, 98 | } 99 | 100 | file { "php_conf_${name}": 101 | ensure => $ensure, 102 | source => $source, 103 | content => $managed_content, 104 | path => $managed_path, 105 | mode => $managed_mode, 106 | owner => $managed_owner, 107 | group => $managed_group, 108 | notify => $notify, 109 | replace => $replace, 110 | } 111 | 112 | } 113 | -------------------------------------------------------------------------------- /manifests/devel.pp: -------------------------------------------------------------------------------- 1 | # Class php::devel 2 | # 3 | # Installs php devel package 4 | # 5 | class php::devel { 6 | 7 | if $php::package_devel != '' 8 | and ! defined(Package[$php::package_devel]) { 9 | package { $php::package_devel : 10 | ensure => $php::manage_package, 11 | install_options => $php::install_options, 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /manifests/ini.pp: -------------------------------------------------------------------------------- 1 | # = Define: php::ini 2 | # 3 | # With this you can alter/add a php ini file for a specific sapi target 4 | # or for both cli and apache2 (default for Ubuntu|Debian|Mint|SLES|OpenSuSE) 5 | # 6 | # == Parameters 7 | # [*value*] 8 | # String. Optional. Default: '' 9 | # The value to be added to the ini file 10 | # 11 | # [*template*] 12 | # String. Optional. Default: 'extra-ini.erb' 13 | # Template to use 14 | # 15 | # [*target*] 16 | # String. Optional. Default: 'extra.ini' 17 | # The configuration filename 18 | # 19 | # [*sapi_target*] 20 | # String. Optional. Default: 'all' 21 | # The target sapi for the configuration file. 22 | # Bu default it will try to apply the configuration to both cli and http 23 | # 24 | define php::ini ( 25 | $value = '', 26 | $template = 'php/extra-ini.erb', 27 | $target = 'extra.ini', 28 | $sapi_target = 'all', 29 | $service = $php::service, 30 | $config_dir = $php::config_dir, 31 | $package = $php::package 32 | ) { 33 | 34 | include php 35 | 36 | $realservice_autorestart = $::php::realservice_autorestart 37 | 38 | $http_sapi = $::operatingsystem ? { 39 | /(?i:Ubuntu|Debian|Mint|SLES|OpenSuSE)/ => '/apache2/', 40 | default => '/', 41 | } 42 | 43 | case $::osfamily { 44 | 'RedHat' : { 45 | file { "${config_dir}/${target}": 46 | ensure => 'present', 47 | content => template($template), 48 | require => Package[$php::package], 49 | notify => $realservice_autorestart, 50 | } 51 | } 52 | default : { 53 | if ($sapi_target == 'all') { 54 | 55 | file { "${config_dir}${http_sapi}conf.d/${target}": 56 | ensure => 'present', 57 | content => template($template), 58 | require => Package[$package], 59 | before => File["${config_dir}/cli/conf.d/${target}"], 60 | notify => $realservice_autorestart, 61 | } 62 | 63 | file { "${config_dir}/cli/conf.d/${target}": 64 | ensure => 'present', 65 | content => template($template), 66 | require => Package[$package], 67 | } 68 | 69 | }else{ 70 | file { "${config_dir}/${sapi_target}/conf.d/${target}": 71 | ensure => 'present', 72 | content => template($template), 73 | require => Package[$package], 74 | notify => $realservice_autorestart, 75 | } 76 | 77 | } 78 | } 79 | } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /manifests/init.pp: -------------------------------------------------------------------------------- 1 | # = Class: php 2 | # 3 | # This is the main php class 4 | # 5 | # 6 | # == Parameters 7 | # 8 | # Module specific parameters 9 | # [*package_devel*] 10 | # Name of the php-devel package 11 | # 12 | # [*package_pear*] 13 | # Name of the php-pear package 14 | # 15 | # Standard class parameters 16 | # Define the general class behaviour and customizations 17 | # 18 | # [*my_class*] 19 | # Name of a custom class to autoload to manage module's customizations 20 | # If defined, php class will automatically "include $my_class" 21 | # Can be defined also by the (top scope) variable $php_myclass 22 | # 23 | # [*service*] 24 | # The service that runs the php interpreter. Defines what service gets 25 | # notified. Default: apache2|httpd. 26 | # 27 | # [*source*] 28 | # Sets the content of source parameter for main configuration file 29 | # If defined, php main config file will have the param: source => $source 30 | # Can be defined also by the (top scope) variable $php_source 31 | # 32 | # [*source_dir*] 33 | # If defined, the whole php configuration directory content is retrieved 34 | # recursively from the specified source 35 | # (source => $source_dir , recurse => true) 36 | # Can be defined also by the (top scope) variable $php_source_dir 37 | # 38 | # [*source_dir_purge*] 39 | # If set to true (default false) the existing configuration directory is 40 | # mirrored with the content retrieved from source_dir 41 | # (source => $source_dir , recurse => true , purge => true, force => true) 42 | # Can be defined also by the (top scope) variable $php_source_dir_purge 43 | # 44 | # [*template*] 45 | # Sets the path to the template to use as content for main configuration file 46 | # If defined, php main config file has: content => content("$template") 47 | # Note source and template parameters are mutually exclusive: don't use both 48 | # Can be defined also by the (top scope) variable $php_template 49 | # 50 | # [*augeas*] 51 | # If set to true (default false), the php.ini will be managed through 52 | # augeas. This will make php::pecl automatically add extensions to the 53 | # php.ini. 54 | # Can be defined also by the (top scope) variable $php_augeas 55 | # 56 | # [*options*] 57 | # An hash of custom options to be used in templates for arbitrary settings. 58 | # Can be defined also by the (top scope) variable $php_options 59 | # 60 | # [*version*] 61 | # The package version, used in the ensure parameter of package type. 62 | # Default: present. Can be 'latest' or a specific version number. 63 | # Note that if the argument absent (see below) is set to true, the 64 | # package is removed, whatever the value of version parameter. 65 | # 66 | # [*install_options*] 67 | # The package install options to be passed to the package manager. Useful for 68 | # setting advanced/custom options during package install/update. 69 | # For example, adding a `--enablerepo` option to Yum or specifying a 70 | # `--no-install-recommends` option during an Apt install. 71 | # NOTE: The `install_options` package class parameter was added for Yum/Apt 72 | # in Puppet 3.6. Its format of the option is an array, where each option in 73 | # the array is either a string or a hash. 74 | # Example: `install_options => ['-y', {'--enablerepo' => 'remi-php55'}]` 75 | # 76 | # [*absent*] 77 | # Set to 'true' to remove package(s) installed by module 78 | # Can be defined also by the (top scope) variable $php_absent 79 | # 80 | # [*puppi*] 81 | # Set to 'true' to enable creation of module data files that are used by puppi 82 | # Can be defined also by the (top scope) variables $php_puppi and $puppi 83 | # 84 | # [*puppi_helper*] 85 | # Specify the helper to use for puppi commands. The default for this module 86 | # is specified in params.pp and is generally a good choice. 87 | # You can customize the output of puppi commands for this module using another 88 | # puppi helper. Use the define puppi::helper to create a new custom helper 89 | # Can be defined also by the (top scope) variables $php_puppi_helper 90 | # and $puppi_helper 91 | # 92 | # [*debug*] 93 | # Set to 'true' to enable modules debugging 94 | # Can be defined also by the (top scope) variables $php_debug and $debug 95 | # 96 | # [*audit_only*] 97 | # Set to 'true' if you don't intend to override existing configuration files 98 | # and want to audit the difference between existing files and the ones 99 | # managed by Puppet. 100 | # Can be defined also by the (top scope) variables $php_audit_only 101 | # and $audit_only 102 | # 103 | # Default class params - As defined in php::params. 104 | # Note that these variables are mostly defined and used in the module itself, 105 | # overriding the default values might not affected all the involved components. 106 | # Set and override them only if you know what you're doing. 107 | # Note also that you can't override/set them via top scope variables. 108 | # 109 | # [*package*] 110 | # The name of php package 111 | # 112 | # [*config_dir*] 113 | # Main configuration directory. Used by puppi 114 | # 115 | # [*config_file*] 116 | # Main configuration file path 117 | # 118 | # [*config_file_mode*] 119 | # Main configuration file path mode 120 | # 121 | # [*config_file_owner*] 122 | # Main configuration file path owner 123 | # 124 | # [*config_file_group*] 125 | # Main configuration file path group 126 | # 127 | # [*config_file_init*] 128 | # Path of configuration file sourced by init script 129 | # 130 | # [*pid_file*] 131 | # Path of pid file. Used by monitor 132 | # 133 | # [*data_dir*] 134 | # Path of application data directory. Used by puppi 135 | # 136 | # [*log_dir*] 137 | # Base logs directory. Used by puppi 138 | # 139 | # [*log_file*] 140 | # Log file(s). Used by puppi 141 | # 142 | # == Examples 143 | # 144 | # You can use this class in 2 ways: 145 | # - Set variables (at top scope level on in a ENC) and "include php" 146 | # - Call php as a parametrized class 147 | # 148 | # See README for details. 149 | # 150 | # 151 | class php ( 152 | $package_devel = params_lookup( 'package_devel' ), 153 | $package_pear = params_lookup( 'package_pear' ), 154 | $my_class = params_lookup( 'my_class' ), 155 | $service = params_lookup( 'service' ), 156 | $service_autorestart = params_lookup( 'service_autorestart' ), 157 | $source = params_lookup( 'source' ), 158 | $source_dir = params_lookup( 'source_dir' ), 159 | $source_dir_purge = params_lookup( 'source_dir_purge' ), 160 | $template = params_lookup( 'template' ), 161 | $augeas = params_lookup( 'augeas' ), 162 | $options = params_lookup( 'options' ), 163 | $version = params_lookup( 'version' ), 164 | $install_options = params_lookup( 'install_options' ), 165 | $absent = params_lookup( 'absent' ), 166 | $monitor = params_lookup( 'monitor' , 'global' ), 167 | $monitor_tool = params_lookup( 'monitor_tool' , 'global' ), 168 | $monitor_target = params_lookup( 'monitor_target' , 'global' ), 169 | $puppi = params_lookup( 'puppi' , 'global' ), 170 | $puppi_helper = params_lookup( 'puppi_helper' , 'global' ), 171 | $debug = params_lookup( 'debug' , 'global' ), 172 | $audit_only = params_lookup( 'audit_only' , 'global' ), 173 | $package = params_lookup( 'package' ), 174 | $module_prefix = params_lookup( 'module_prefix' ), 175 | $config_dir = params_lookup( 'config_dir' ), 176 | $config_file = params_lookup( 'config_file' ), 177 | $config_file_mode = params_lookup( 'config_file_mode' ), 178 | $config_file_owner = params_lookup( 'config_file_owner' ), 179 | $config_file_group = params_lookup( 'config_file_group' ), 180 | $config_file_init = params_lookup( 'config_file_init' ), 181 | $pid_file = params_lookup( 'pid_file' ), 182 | $data_dir = params_lookup( 'data_dir' ), 183 | $log_dir = params_lookup( 'log_dir' ), 184 | $log_file = params_lookup( 'log_file' ), 185 | $port = params_lookup( 'port' ), 186 | $protocol = params_lookup( 'protocol' ) 187 | ) inherits php::params { 188 | 189 | $bool_service_autorestart=any2bool($service_autorestart) 190 | $bool_source_dir_purge=any2bool($source_dir_purge) 191 | $bool_augeas=any2bool($augeas) 192 | $bool_absent=any2bool($absent) 193 | $bool_monitor=any2bool($monitor) 194 | $bool_puppi=any2bool($puppi) 195 | $bool_debug=any2bool($debug) 196 | $bool_audit_only=any2bool($audit_only) 197 | 198 | ### Definition of some variables used in the module 199 | $manage_package = $php::bool_absent ? { 200 | true => 'absent', 201 | false => $php::version, 202 | } 203 | 204 | $manage_file = $php::bool_absent ? { 205 | true => 'absent', 206 | default => 'present', 207 | } 208 | 209 | if $php::bool_absent == true { 210 | $manage_monitor = false 211 | } else { 212 | $manage_monitor = true 213 | } 214 | 215 | $manage_audit = $php::bool_audit_only ? { 216 | true => 'all', 217 | false => undef, 218 | } 219 | 220 | $manage_file_replace = $php::bool_audit_only ? { 221 | true => false, 222 | false => true, 223 | } 224 | 225 | if ($php::source != '' and $php::source != false and $php::template != '' and 226 | $php::template != false) { 227 | fail ('PHP: cannot set both source and template') 228 | } 229 | if ($php::source != '' and $php::source != false and $php::bool_augeas) { 230 | fail ('PHP: cannot set both source and augeas') 231 | } 232 | if ($php::template != '' and $php::template != false and $php::bool_augeas) { 233 | fail ('PHP: cannot set both template and augeas') 234 | } 235 | 236 | $manage_file_source = $php::source ? { 237 | '' => undef, 238 | default => $php::source, 239 | } 240 | 241 | $manage_file_content = $php::template ? { 242 | '' => undef, 243 | default => template($php::template), 244 | } 245 | 246 | $realservice_autorestart = $bool_service_autorestart ? { 247 | true => Service[$php::service], 248 | false => undef, 249 | } 250 | 251 | ### Managed resources 252 | package { $php::package: 253 | ensure => $php::manage_package, 254 | install_options => $php::install_options, 255 | } 256 | 257 | file { 'php.conf': 258 | ensure => $php::manage_file, 259 | path => $php::config_file, 260 | mode => $php::config_file_mode, 261 | owner => $php::config_file_owner, 262 | group => $php::config_file_group, 263 | require => Package[$php::package], 264 | source => $php::manage_file_source, 265 | content => $php::manage_file_content, 266 | replace => $php::manage_file_replace, 267 | audit => $php::manage_audit, 268 | notify => $realservice_autorestart, 269 | } 270 | 271 | # The whole php configuration directory can be recursively overriden 272 | if $php::source_dir != '' and $php::source_dir != false { 273 | file { 'php.dir': 274 | ensure => directory, 275 | path => $php::config_dir, 276 | require => Package[$php::package], 277 | source => $php::source_dir, 278 | recurse => true, 279 | links => follow, 280 | purge => $php::bool_source_dir_purge, 281 | force => $php::bool_source_dir_purge, 282 | replace => $php::manage_file_replace, 283 | audit => $php::manage_audit, 284 | } 285 | } 286 | 287 | 288 | ### Include custom class if $my_class is set 289 | if $php::my_class != '' and $php::my_class != false { 290 | include $php::my_class 291 | } 292 | 293 | 294 | ### Provide puppi data, if enabled ( puppi => true ) 295 | if $php::bool_puppi == true { 296 | $classvars=get_class_args() 297 | puppi::ze { 'php': 298 | ensure => $php::manage_file, 299 | variables => $classvars, 300 | helper => $php::puppi_helper, 301 | } 302 | } 303 | 304 | 305 | ### Debugging, if enabled ( debug => true ) 306 | if $php::bool_debug == true { 307 | file { 'debug_php': 308 | ensure => $php::manage_file, 309 | path => "${settings::vardir}/debug-php", 310 | mode => '0640', 311 | owner => 'root', 312 | group => 'root', 313 | content => inline_template('<%= scope.to_hash.reject { |k,v| k.to_s =~ /(uptime.*|path|timestamp|free|.*password.*|.*psk.*|.*key)/ }.to_yaml %>'), 314 | } 315 | } 316 | 317 | } 318 | -------------------------------------------------------------------------------- /manifests/mod.pp: -------------------------------------------------------------------------------- 1 | # Define: php::mod 2 | # 3 | # This define configures php mods-available to all SAPI using php5{en,dis}mod 4 | # 5 | # == Parameters 6 | # 7 | # [*disable*] 8 | # Set to 'true' to disable the php mod-availables to all SAPI using php5{dis}mod 9 | # Default: false, i.e, Set the php mod-availables to all SAPI using php5{en}mod. 10 | # 11 | # [*service_autorestart*] 12 | # whatever we want a module installation notify a service to restart. 13 | # 14 | # == Usage 15 | # 16 | # [name] is filename without .ini extension from /etc/php5/mods-available/.ini 17 | # 18 | # php::mod { "": } 19 | # 20 | # == Example 21 | # 22 | # This will configure php5-mcrypt module to all SAPI 23 | # 24 | # php::mod { "mcrypt": } 25 | # 26 | # $mods = ["mcrypt", "mongo"] 27 | # php::mod { "$mods": } 28 | # 29 | # This will unconfigure php5-xdebug module to all SAPI 30 | # 31 | # php::mod { "xdebug": 32 | # disable => true, 33 | # } 34 | # 35 | # Note that you may include or declare the php class when using 36 | # the php::module define 37 | # 38 | define php::mod ( 39 | $disable = false, 40 | $service_autorestart = '', 41 | $path = '/usr/bin:/bin:/usr/sbin:/sbin', 42 | $package = $php::package 43 | ) { 44 | 45 | include php 46 | 47 | $real_service_autorestart = $service_autorestart ? { 48 | true => "Service[${php::service}]", 49 | false => undef, 50 | '' => $php::service_autorestart ? { 51 | true => "Service[${php::service}]", 52 | false => undef, 53 | } 54 | } 55 | 56 | if $disable { 57 | exec { "php_mod_tool_disable_${name}": 58 | command => "php5dismod ${name}", 59 | path => $path, 60 | notify => $real_service_autorestart, 61 | require => Package[$package], 62 | onlyif => "php5query -M | grep -q '^${name}$'", 63 | } 64 | } else { 65 | exec { "php_mod_tool_enable_${name}": 66 | command => "php5enmod ${name}", 67 | path => $path, 68 | notify => $real_service_autorestart, 69 | require => Package[$package], 70 | unless => "php5query -M | grep -q '^${name}$'", 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /manifests/module.pp: -------------------------------------------------------------------------------- 1 | # = Define: php::module 2 | # 3 | # This define installs and configures php modules 4 | # On Debian and derivatives it install module named php5-${name} 5 | # On RedHat and derivatives it install module named php-${name} 6 | # If you need a custom prefix you can overload default $module_prefix parameter 7 | # 8 | # == Parameters 9 | # 10 | # [*version*] 11 | # Version to install. 12 | # 13 | # [*absent*] 14 | # true to ensure package isn't installed. 15 | # 16 | # [*notify_service*] 17 | # If you want to restart a service automatically when 18 | # the module is applied. Default: true 19 | # 20 | # [*service_autorestart*] 21 | # whatever we want a module installation notify a service to restart. 22 | # 23 | # [*service*] 24 | # Service to restart. 25 | # 26 | # [*module_prefix*] 27 | # If package name prefix isn't standard. 28 | # 29 | # [*install_options*] 30 | # An array of package manager install options. See $php::install_options 31 | # 32 | # == Examples 33 | # php::module { 'gd': } 34 | # 35 | # php::module { 'gd': 36 | # ensure => absent, 37 | # } 38 | # 39 | # This will install php-apc on debian instead of php5-apc 40 | # 41 | # php::module { 'apc': 42 | # module_prefix => "php-", 43 | # } 44 | # 45 | # Note that you may include or declare the php class when using 46 | # the php::module define 47 | # 48 | define php::module ( 49 | $version = 'present', 50 | $install_options = [], 51 | $service_autorestart = '', 52 | $module_prefix = '', 53 | $absent = '', 54 | $package = $php::package 55 | ) { 56 | 57 | include php 58 | 59 | if $absent != '' and $absent != false { 60 | $real_version = 'absent' 61 | } else { 62 | $real_version = $version 63 | } 64 | 65 | $real_service_autorestart = $service_autorestart ? { 66 | true => "Service[${php::service}]", 67 | false => undef, 68 | '' => $php::service_autorestart ? { 69 | true => "Service[${php::service}]", 70 | false => undef, 71 | } 72 | } 73 | 74 | $real_module_prefix = $module_prefix ? { 75 | '' => $php::module_prefix, 76 | default => $module_prefix, 77 | } 78 | 79 | $real_install_options = $install_options ? { 80 | '' => $php::install_options, 81 | default => $install_options, 82 | } 83 | 84 | $real_install_package = "${real_module_prefix}${name}" 85 | 86 | if defined(Package[$real_install_package]) == false { 87 | package { "PhpModule_${name}": 88 | ensure => $real_version, 89 | name => $real_install_package, 90 | notify => $real_service_autorestart, 91 | install_options => $real_install_options, 92 | require => Package[$package], 93 | } 94 | } 95 | 96 | } 97 | -------------------------------------------------------------------------------- /manifests/params.pp: -------------------------------------------------------------------------------- 1 | # Class: php::params 2 | # 3 | # This class defines default parameters used by the main module class php 4 | # Operating Systems differences in names and paths are addressed here 5 | # 6 | # == Variables 7 | # 8 | # Refer to php class for the variables defined here. 9 | # 10 | # == Usage 11 | # 12 | # This class is not intended to be used directly. 13 | # It may be imported or inherited by other classes 14 | # 15 | class php::params { 16 | 17 | $package_devel = $::operatingsystem ? { 18 | /(?i:Ubuntu|Debian|Mint)/ => 'php5-dev', 19 | /(?i:SLES|OpenSuSe)/ => 'php5-devel', 20 | default => 'php-devel', 21 | } 22 | 23 | $package_pear = $::operatingsystem ? { 24 | /(?i:Ubuntu|Debian|Mint)/ => 'php-pear', 25 | /(?i:SLES|OpenSuSe)/ => 'php5-pear', 26 | default => 'php-pear', 27 | } 28 | 29 | ### Application related parameters 30 | $module_prefix = $::operatingsystem ? { 31 | /(?i:Ubuntu|Debian|Mint|SLES|OpenSuSE)/ => 'php5-', 32 | default => 'php-', 33 | } 34 | 35 | $pear_module_prefix = $::operatingsystem ? { 36 | /(?i:Ubuntu|Debian|Mint)/ => 'php-', 37 | /(?i:SLES|OpenSuSe)/ => 'php5-pear-', 38 | /(?i:CentOS|RedHat|Scientific|Linux)/ => 'php-pear-', 39 | default => 'pear-', 40 | } 41 | 42 | $package = $::operatingsystem ? { 43 | /(?i:Ubuntu|Debian|Mint)/ => 'php5', 44 | /(?i:SLES|OpenSuSE)/ => [ 'php5','apache2-mod_php5'], 45 | default => 'php', 46 | } 47 | 48 | # Here it's not the php service script name but 49 | # web service name like apache2, nginx, etc. 50 | $service = $::operatingsystem ? { 51 | /(?i:Ubuntu|Debian|Mint|SLES|OpenSuSE)/ => 'apache2', 52 | default => 'httpd', 53 | } 54 | 55 | $config_dir = $::operatingsystem ? { 56 | /(?i:Ubuntu|Debian|Mint|SLES|OpenSuSE)/ => '/etc/php5', 57 | default => '/etc/php.d', 58 | } 59 | 60 | $config_file = $::operatingsystem ? { 61 | /(?i:Ubuntu|Debian|Mint|SLES|OpenSuSE)/ => '/etc/php5/apache2/php.ini', 62 | default => '/etc/php.ini', 63 | } 64 | 65 | $config_file_mode = $::operatingsystem ? { 66 | default => '0644', 67 | } 68 | 69 | $config_file_owner = $::operatingsystem ? { 70 | default => 'root', 71 | } 72 | 73 | $config_file_group = $::operatingsystem ? { 74 | default => 'root', 75 | } 76 | 77 | $data_dir = $::operatingsystem ? { 78 | default => '', 79 | } 80 | 81 | $log_dir = $::operatingsystem ? { 82 | default => '', 83 | } 84 | 85 | $log_file = $::operatingsystem ? { 86 | default => '', 87 | } 88 | 89 | # General Settings 90 | $my_class = '' 91 | $source = '' 92 | $source_dir = '' 93 | $source_dir_purge = false 94 | $augeas = false 95 | $template = '' 96 | $options = '' 97 | $version = 'present' 98 | $service_autorestart = true 99 | $absent = false 100 | $install_options = [] 101 | 102 | ### General module variables that can have a site or per module default 103 | $puppi = false 104 | $puppi_helper = 'standard' 105 | $debug = false 106 | $audit_only = false 107 | 108 | } 109 | -------------------------------------------------------------------------------- /manifests/pear.pp: -------------------------------------------------------------------------------- 1 | # Class: php::pear 2 | # 3 | # Installs Pear for PHP module 4 | # 5 | # Usage: 6 | # include php::pear 7 | # 8 | # == Parameters 9 | # 10 | # Standard class parameters 11 | # Define the general class behaviour and customizations 12 | # 13 | # [*package*] 14 | # Name of the package to install. Defaults to 'php-pear' 15 | # 16 | # [*version*] 17 | # Version to install. Defaults to 'present' 18 | # 19 | # [*install_package*] 20 | # Boolean. Determines if any package should be installed to support the PEAR functionality. 21 | # Can be false if PEAR was already provided by another package or module. 22 | # Default: true 23 | # 24 | # [*install_options*] 25 | # An array of package manager install options. See $php::install_options 26 | # 27 | class php::pear ( 28 | $package = $php::package_pear, 29 | $install_package = true, 30 | $install_options = [], 31 | $version = 'present', 32 | $path = '/usr/bin:/usr/sbin:/bin:/sbin' 33 | ) inherits php { 34 | 35 | $real_install_options = $install_options ? { 36 | '' => $php::install_options, 37 | default => $install_options, 38 | } 39 | 40 | if ( $install_package ) { 41 | package { 'php-pear': 42 | ensure => $version, 43 | name => $package, 44 | install_options => $real_install_options, 45 | } 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /manifests/pear/config.pp: -------------------------------------------------------------------------------- 1 | # Define: php::pear::config 2 | # 3 | # Configures pear 4 | # 5 | # Usage: 6 | # php::pear::config { http_proxy: value => "myproxy:8080" } 7 | # 8 | define php::pear::config ($value) { 9 | 10 | include php::pear 11 | 12 | exec { "pear-config-set-${name}": 13 | command => "pear config-set ${name} ${value}", 14 | path => $php::pear::path, 15 | unless => "pear config-get ${name} | grep ${value}", 16 | require => Package['php-pear'], 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /manifests/pear/module.pp: -------------------------------------------------------------------------------- 1 | # Define: php::pear::module 2 | # 3 | # Installs the defined php pear component 4 | # 5 | # Variables: 6 | # [*use_package*] 7 | # (default=true) - Tries to install pear module with the relevant OS package 8 | # If set to "no" it installs the module via pear command 9 | # 10 | # [*install_options*] 11 | # An array of package manager install options. See $php::install_options 12 | # 13 | # [*preferred_state*] 14 | # (default="stable") - Define which preferred state to use when installing 15 | # Pear modules via pear via command line (when use_package=false) 16 | # 17 | # [*alldeps*] 18 | # (default="false") - Define if all the available (optional) modules should 19 | # be installed. (when use_package=false) 20 | # 21 | # Usage: 22 | # php::pear::module { packagename: } 23 | # Example: 24 | # php::pear::module { Crypt-CHAP: } 25 | # 26 | define php::pear::module ( 27 | $service = '', 28 | $use_package = true, 29 | $install_options = [], 30 | $preferred_state = 'stable', 31 | $alldeps = false, 32 | $version = 'present', 33 | $repository = 'pear.php.net', 34 | $service_autorestart = '', 35 | $module_prefix = '', 36 | $path = '/usr/bin:/usr/sbin:/bin:/sbin', 37 | $ensure = 'present', 38 | $timeout = 300 39 | ) { 40 | 41 | include php::pear 42 | 43 | $bool_use_package = any2bool($use_package) 44 | $bool_alldeps = any2bool($alldeps) 45 | $manage_alldeps = $bool_alldeps ? { 46 | true => '--alldeps', 47 | false => '', 48 | } 49 | 50 | $pear_source = $version ? { 51 | 'present' => "${repository}/${name}", 52 | default => "${repository}/${name}-${version}", 53 | } 54 | 55 | $pear_exec_command = $ensure ? { 56 | present => "pear -d preferred_state=${preferred_state} install ${manage_alldeps} ${pear_source}", 57 | absent => "pear uninstall -n ${pear_source}", 58 | } 59 | 60 | $pear_exec_require = $repository ? { 61 | 'pear.php.net' => Package['php-pear'], 62 | default => [ Package['php-pear'],Php::Pear::Config['auto_discover'] ], 63 | } 64 | 65 | $pear_exec_unless = $ensure ? { 66 | present => "pear shell-test ${pear_source} > 0", 67 | absent => undef 68 | } 69 | 70 | $pear_exec_onlyif = $ensure ? { 71 | present => undef, 72 | absent => "pear shell-test ${pear_source} > 0", 73 | } 74 | 75 | $real_service = $service ? { 76 | '' => $php::service, 77 | default => $service, 78 | } 79 | 80 | $real_service_autorestart = $service_autorestart ? { 81 | true => "Service[${real_service}]", 82 | false => undef, 83 | '' => $php::service_autorestart ? { 84 | true => "Service[${real_service}]", 85 | false => undef, 86 | } 87 | } 88 | 89 | $real_module_prefix = $module_prefix ? { 90 | '' => $php::pear_module_prefix, 91 | default => $module_prefix, 92 | } 93 | $package_name = "${real_module_prefix}${name}" 94 | 95 | $real_install_options = $install_options ? { 96 | '' => $php::install_options, 97 | default => $install_options, 98 | } 99 | 100 | 101 | case $bool_use_package { 102 | true: { 103 | package { "pear-${name}": 104 | ensure => $ensure, 105 | name => $package_name, 106 | install_options => $real_install_options, 107 | notify => $real_service_autorestart, 108 | } 109 | } 110 | default: { 111 | if $repository != 'pear.php.net' { 112 | if !defined (Php::Pear::Config['auto_discover']) { 113 | php::pear::config { 'auto_discover': 114 | value => '1', 115 | } 116 | } 117 | } 118 | exec { "pear-${name}": 119 | command => $pear_exec_command, 120 | path => $path, 121 | unless => $pear_exec_unless, 122 | onlyif => $pear_exec_onlyif, 123 | require => $pear_exec_require, 124 | timeout => $timeout, 125 | } 126 | } 127 | } # End Case 128 | 129 | } 130 | -------------------------------------------------------------------------------- /manifests/pecl/config.pp: -------------------------------------------------------------------------------- 1 | # Define: php::pecl::config 2 | # 3 | # Configures pecl 4 | # 5 | # Usage: 6 | # php::pecl::config { http_proxy: value => "myproxy:8080" } 7 | # 8 | define php::pecl::config ( 9 | $value, 10 | $layer = 'user', 11 | $path = '/usr/bin:/bin:/usr/sbin:/sbin' 12 | ) { 13 | 14 | include php::pear 15 | 16 | exec { "pecl-config-set-${name}": 17 | command => "pecl config-set ${name} ${value} ${layer}", 18 | path => $path, 19 | unless => "pecl config-get ${name} | grep ${value}", 20 | require => Package['php-pear'], 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /manifests/pecl/module.pp: -------------------------------------------------------------------------------- 1 | # Define: php::pecl::module 2 | # 3 | # Installs the defined php pecl component 4 | # 5 | # == Parameters 6 | # 7 | # [*service_autorestart*] 8 | # wathever we want a module installation notify a service to restart. 9 | # 10 | # [*service*] 11 | # Service to restart. 12 | # 13 | # [*use_package*] 14 | # Tries to install pecl module with the relevant package. 15 | # If set to "no" it installs the module via pecl command. Default: true 16 | # 17 | # [*install_options*] 18 | # An array of package manager install options. See $php::install_options 19 | # 20 | # [*preferred_state*] 21 | # Define which preferred state to use when installing Pear modules via pecl 22 | # command line (when use_package=no). Default: true 23 | # 24 | # [*auto_answer*] 25 | # The answer(s) to give to pecl prompts for unattended install 26 | # 27 | # [*verbose*] 28 | # (Optional) - If you want to see verbose pecl output during installation. 29 | # This can help to debug installation problems (missing packages) during 30 | # installation process. Default: false 31 | # 32 | # == Examples 33 | # php::pecl::module { 'intl': } 34 | # 35 | # This will install xdebug from pecl source instead of using the package 36 | # 37 | # php::pecl::module { 'xdebug':. 38 | # use_package => "no", 39 | # } 40 | # 41 | define php::pecl::module ( 42 | $service_autorestart = $php::bool_service_autorestart, 43 | $service = $php::service, 44 | $use_package = 'yes', 45 | $install_options = [], 46 | $preferred_state = 'stable', 47 | $auto_answer = '\\n', 48 | $ensure = present, 49 | $path = '/usr/bin:/usr/sbin:/bin:/sbin', 50 | $verbose = false, 51 | $version = '', 52 | $prefix = false, 53 | $config_file = $php::config_file) { 54 | 55 | include php 56 | include php::pear 57 | include php::devel 58 | 59 | $manage_service_autorestart = $service_autorestart ? { 60 | true => $service ? { 61 | '' => undef, 62 | default => "Service[${service}]", 63 | }, 64 | false => undef, 65 | undef => undef, 66 | } 67 | 68 | $real_install_options = $install_options ? { 69 | '' => $php::install_options, 70 | default => $install_options, 71 | } 72 | 73 | case $prefix { 74 | false: { 75 | $real_package_name = $::operatingsystem ? { 76 | ubuntu => "php5-${name}", 77 | debian => "php5-${name}", 78 | default => "php-${name}", 79 | } 80 | } 81 | default: { 82 | $real_package_name = "${prefix}${name}" 83 | } 84 | } 85 | 86 | case $use_package { 87 | yes: { 88 | package { "php-${name}": 89 | ensure => $ensure, 90 | name => $real_package_name, 91 | install_options => $real_install_options, 92 | notify => $manage_service_autorestart, 93 | } 94 | } 95 | default: { 96 | $pcre_dev_package_name = $::osfamily ? { 97 | 'Debian' => 'libpcre3-dev', 98 | 'RedHat' => 'pcre-devel', 99 | default => 'pcre3-devel', 100 | } 101 | if $ensure and !defined(Package[$pcre_dev_package_name]) { 102 | package { $pcre_dev_package_name : } 103 | } 104 | 105 | $bool_verbose = any2bool($verbose) 106 | 107 | $pecl_exec_logoutput = $bool_verbose ? { 108 | true => true, 109 | false => undef, 110 | } 111 | 112 | if $version != '' { 113 | $new_version = "-${version}" 114 | } else { 115 | $new_version = '' 116 | } 117 | 118 | $pecl_exec_command = $ensure ? { 119 | present => "printf \"${auto_answer}\" | pecl -d preferred_state=${preferred_state} install ${name}${new_version} && pecl info ${name}", 120 | absent => "pecl uninstall -n ${name}", 121 | } 122 | 123 | $pecl_exec_unless = $ensure ? { 124 | present => "pecl info ${name}", 125 | absent => undef 126 | } 127 | 128 | $pecl_exec_require = $ensure ? { 129 | present => [ Class['php::pear'], Class['php::devel'], Package[$pcre_dev_package_name]], 130 | absent => [ Class['php::pear'], Class['php::devel']] 131 | } 132 | 133 | $pecl_exec_onlyif = $ensure ? { 134 | present => undef, 135 | absent => "pecl info ${name}", 136 | } 137 | 138 | exec { "pecl-${name}": 139 | command => $pecl_exec_command, 140 | unless => $pecl_exec_unless, 141 | onlyif => $pecl_exec_onlyif, 142 | logoutput => $pecl_exec_logoutput, 143 | path => $path, 144 | require => $pecl_exec_require, 145 | notify => $manage_service_autorestart, 146 | } 147 | if $php::bool_augeas == true { 148 | php::augeas { "augeas-${name}": 149 | ensure => $ensure, 150 | entry => "PHP/extension[. = \"${name}.so\"]", 151 | value => "${name}.so", 152 | notify => $manage_service_autorestart, 153 | target => $config_file, 154 | } 155 | } 156 | } 157 | } # End Case 158 | } 159 | -------------------------------------------------------------------------------- /manifests/spec.pp: -------------------------------------------------------------------------------- 1 | # Class: php::spec 2 | # 3 | # This class is used only for rpsec-puppet tests 4 | # Can be taken as an example on how to do custom classes but should not 5 | # be modified. 6 | # 7 | # == Usage 8 | # 9 | # This class is not intended to be used directly. 10 | # Use it as reference 11 | # 12 | class php::spec inherits php { 13 | 14 | # This just a test to override the arguments of an existing resource 15 | # Note that you can achieve this same result with just: 16 | # class { "php": template => "php/spec.erb" } 17 | 18 | File['php.conf'] { 19 | content => template('php/spec.erb'), 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /metadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "example42-php", 3 | "version": "2.0.27", 4 | "summary": "Puppet module for php", 5 | "author": "Alessandro Franceschi", 6 | "description": "This module installs and manages php. Check README.rdoc for details. Puppi is required for some common functions: you can install them without using the whole module. Monitor and firewall dependencies are needed only if the relevant features are enabled", 7 | "dependencies": [ 8 | { 9 | "name": "example42/puppi", 10 | "version_requirement": ">= 2.0.0" 11 | } 12 | ], 13 | "types": [ 14 | 15 | ], 16 | "checksums": { 17 | }, 18 | "source": "https://github.com/example42/puppet-php", 19 | "project_page": "http://www.example42.com", 20 | "license": "Apache2" 21 | } 22 | -------------------------------------------------------------------------------- /spec/classes/php_spec.rb: -------------------------------------------------------------------------------- 1 | require "#{File.join(File.dirname(__FILE__),'..','spec_helper.rb')}" 2 | 3 | describe 'php' do 4 | 5 | let(:title) { 'php' } 6 | let(:node) { 'rspec.example42.com' } 7 | let(:facts) { { :ipaddress => '10.42.42.42' } } 8 | 9 | describe 'Test standard installation' do 10 | it { should contain_package('php').with_ensure('present') } 11 | it { should contain_file('php.conf').with_ensure('present') } 12 | end 13 | 14 | describe 'Test installation of a specific version' do 15 | let(:params) { {:version => '1.0.42' } } 16 | it { should contain_package('php').with_ensure('1.0.42') } 17 | end 18 | 19 | describe 'Test decommissioning - absent' do 20 | let(:params) { {:absent => true, :monitor => true } } 21 | 22 | it 'should remove Package[php]' do should contain_package('php').with_ensure('absent') end 23 | it 'should remove php configuration file' do should contain_file('php.conf').with_ensure('absent') end 24 | end 25 | 26 | describe 'Test customizations - template' do 27 | let(:params) { {:template => "php/spec.erb" , :options => { 'opt_a' => 'value_a' } } } 28 | it { should contain_file('php.conf').with_content(/fqdn: rspec.example42.com/) } 29 | it { should contain_file('php.conf').with_content(/value_a/) } 30 | end 31 | 32 | describe 'Test customizations - source' do 33 | let(:params) { {:source => "puppet://modules/php/spec" , :source_dir => "puppet://modules/php/dir/spec" , :source_dir_purge => true } } 34 | it { should contain_file('php.conf').with_source('puppet://modules/php/spec') } 35 | it { should contain_file('php.dir').with_source('puppet://modules/php/dir/spec') } 36 | it { should contain_file('php.dir').with_purge('true') } 37 | end 38 | 39 | describe 'Test customizations - custom class' do 40 | let(:params) { {:my_class => "php::spec" } } 41 | it { should contain_file('php.conf').with_content(/fqdn: rspec.example42.com/) } 42 | end 43 | 44 | describe 'Test Puppi Integration' do 45 | let(:params) { {:puppi => true, :puppi_helper => "myhelper"} } 46 | 47 | it { should contain_puppi__ze('php').with_helper('myhelper') } 48 | end 49 | 50 | 51 | end 52 | 53 | -------------------------------------------------------------------------------- /spec/defines/php_ini_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe 'php::ini' do 4 | 5 | let(:title) { 'php::ini' } 6 | let(:node) { 'rspec.example42.com' } 7 | 8 | context 'Test with restart' do 9 | context 'On a Debian OS' do 10 | let :facts do 11 | { 12 | :operatingsystem => 'Debian', 13 | :osfamily => 'Debian', 14 | } 15 | end 16 | 17 | let :pre_condition do 18 | [ 19 | 'service { "apache2": }', 20 | 'class { "php": }', 21 | ] 22 | end 23 | 24 | context 'with sapi_target all' do 25 | let :params do 26 | { 27 | :name => 'dynatrace', 28 | :target => 'dynatrace.ini', 29 | } 30 | end 31 | 32 | it { is_expected.to compile.with_all_deps } 33 | it { is_expected.to contain_file('/etc/php5/apache2/conf.d/dynatrace.ini') } 34 | it { is_expected.to contain_file('/etc/php5/cli/conf.d/dynatrace.ini') } 35 | 36 | it { should contain_file('/etc/php5/apache2/conf.d/dynatrace.ini').that_notifies('Service[apache2]') } 37 | end 38 | 39 | context 'with sapi_target customsapi' do 40 | let :params do 41 | { 42 | :name => 'dynatrace', 43 | :target => 'dynatrace.ini', 44 | :sapi_target => 'customsapi', 45 | } 46 | end 47 | 48 | it { is_expected.to compile.with_all_deps } 49 | it { is_expected.to contain_file('/etc/php5/customsapi/conf.d/dynatrace.ini') } 50 | 51 | it { should contain_file('/etc/php5/customsapi/conf.d/dynatrace.ini').that_notifies('Service[apache2]') } 52 | end 53 | end 54 | 55 | context 'On a RedHat OS' do 56 | let :facts do 57 | { 58 | :operatingsystem => 'Redhat', 59 | :osfamily => 'RedHat', 60 | } 61 | end 62 | 63 | let :pre_condition do 64 | [ 65 | 'service { "httpd": }', 66 | 'class { "php": }', 67 | ] 68 | end 69 | 70 | context 'with defaults' do 71 | let :params do 72 | { 73 | :name => 'dynatrace', 74 | :target => 'dynatrace.ini', 75 | } 76 | end 77 | 78 | it { is_expected.to compile.with_all_deps } 79 | it { is_expected.to contain_file('/etc/php.d/dynatrace.ini') } 80 | 81 | it { should contain_file('/etc/php.d/dynatrace.ini').that_notifies('Service[httpd]') } 82 | end 83 | 84 | end 85 | end 86 | 87 | context 'Test without restart' do 88 | context 'On a Debian OS' do 89 | let :facts do 90 | { 91 | :operatingsystem => 'Debian', 92 | :osfamily => 'Debian', 93 | } 94 | end 95 | 96 | let :pre_condition do 97 | [ 98 | 'service { "apache2": }', 99 | 'class { "php": service_autorestart => false, }', 100 | ] 101 | end 102 | 103 | context 'with sapi_target all' do 104 | let :params do 105 | { 106 | :name => 'dynatrace', 107 | :target => 'dynatrace.ini', 108 | } 109 | end 110 | 111 | it { is_expected.to compile.with_all_deps } 112 | it { is_expected.to contain_file('/etc/php5/apache2/conf.d/dynatrace.ini') } 113 | it { is_expected.to contain_file('/etc/php5/cli/conf.d/dynatrace.ini') } 114 | 115 | it { should_not contain_file('/etc/php5/apache2/conf.d/dynatrace.ini').that_notifies('Service[apache2]') } 116 | end 117 | 118 | context 'with sapi_target customsapi' do 119 | let :params do 120 | { 121 | :name => 'dynatrace', 122 | :target => 'dynatrace.ini', 123 | :sapi_target => 'customsapi', 124 | } 125 | end 126 | 127 | it { is_expected.to compile.with_all_deps } 128 | it { is_expected.to contain_file('/etc/php5/customsapi/conf.d/dynatrace.ini') } 129 | 130 | it { should_not contain_file('/etc/php5/customsapi/conf.d/dynatrace.ini').that_notifies('Service[apache2]') } 131 | 132 | end 133 | end 134 | 135 | context 'On a RedHat OS' do 136 | let :facts do 137 | { 138 | :operatingsystem => 'Redhat', 139 | :osfamily => 'RedHat', 140 | } 141 | end 142 | 143 | let :pre_condition do 144 | [ 145 | 'service { "httpd": }', 146 | 'class { "php": service_autorestart => false, }', 147 | ] 148 | end 149 | 150 | context 'with defaults' do 151 | let :params do 152 | { 153 | :name => 'dynatrace', 154 | :target => 'dynatrace.ini', 155 | } 156 | end 157 | 158 | it { is_expected.to compile.with_all_deps } 159 | it { is_expected.to contain_file('/etc/php.d/dynatrace.ini') } 160 | 161 | it { should_not contain_file('/etc/php.d/dynatrace.ini').that_notifies('Service[httpd]') } 162 | end 163 | 164 | end 165 | end 166 | 167 | end 168 | -------------------------------------------------------------------------------- /spec/defines/php_module_spec.rb: -------------------------------------------------------------------------------- 1 | require "#{File.join(File.dirname(__FILE__),'..','spec_helper.rb')}" 2 | 3 | describe 'php::module' do 4 | 5 | let(:title) { 'php::module' } 6 | let(:node) { 'rspec.example42.com' } 7 | let(:facts) { { 'operatingsystem' => 'Ubuntu' } } 8 | 9 | describe 'Test standard installation' do 10 | let(:params) { { 'name' => 'ps', } } 11 | it 'should create a package with the default OS prefix' do 12 | should contain_package('PhpModule_ps').with_name('php5-ps') 13 | end 14 | it 'should notify the default service' do 15 | should contain_package('PhpModule_ps').with_notify('Service[apache2]') 16 | end 17 | end 18 | 19 | describe 'Test custom params' do 20 | let(:params) { { 'name' => 'ps', 'module_prefix' => 'my-' , 'service_autorestart' => false } } 21 | it 'should create a package with custom prefix' do 22 | should contain_package('PhpModule_ps').with( 23 | 'ensure' => 'present', 24 | 'name' => 'my-ps' 25 | ) 26 | should contain_package('PhpModule_ps').without('notify') 27 | end 28 | end 29 | 30 | describe 'Test uninstallation' do 31 | let(:params) { { 'name' => 'ps', 'absent' => 'true' } } 32 | it 'should remove the package' do 33 | should contain_package('PhpModule_ps').with_ensure('absent') 34 | end 35 | end 36 | 37 | end 38 | 39 | -------------------------------------------------------------------------------- /spec/defines/php_pear_module_spec.rb: -------------------------------------------------------------------------------- 1 | require "#{File.join(File.dirname(__FILE__),'..','spec_helper.rb')}" 2 | 3 | describe 'php::pear::module' do 4 | 5 | let(:title) { 'php::pear::module' } 6 | let(:node) { 'rspec.example42.com' } 7 | let(:facts) { { 'operatingsystem' => 'Ubuntu' } } 8 | 9 | describe 'Test standard installation' do 10 | let(:params) { { 'name' => 'Crypt-CHAP', } } 11 | it 'should install pear module with default OS package' do 12 | should contain_package('pear-Crypt-CHAP').with_name('php-Crypt-CHAP') 13 | end 14 | it 'should notify the default service' do 15 | should contain_package('pear-Crypt-CHAP').with_notify('Service[apache2]') 16 | end 17 | end 18 | 19 | describe 'Test custom params' do 20 | let(:params) { { 'name' => 'Crypt-CHAP', 'module_prefix' => 'my-' , 'service_autorestart' => false } } 21 | it 'should create a package with custom prefix' do 22 | should contain_package('pear-Crypt-CHAP').with( 23 | 'ensure' => 'present', 24 | 'name' => 'my-Crypt-CHAP' 25 | ) 26 | should contain_package('pear-Crypt-CHAP').without('notify') 27 | end 28 | end 29 | 30 | describe 'Test uninstallation' do 31 | let(:params) { { 'name' => 'Crypt-CHAP', 'ensure' => 'absent' } } 32 | it 'should remove the package' do 33 | should contain_package('pear-Crypt-CHAP').with_ensure('absent') 34 | end 35 | end 36 | 37 | describe 'Test installation via exec' do 38 | let(:params) { { 'name' => 'Crypt-CHAP', 'use_package' => 'false' } } 39 | it 'should install pear module with exec commands' do 40 | should contain_exec('pear-Crypt-CHAP').with( 41 | 'command' => 'pear -d preferred_state=stable install pear.php.net/Crypt-CHAP', 42 | 'unless' => 'pear shell-test pear.php.net/Crypt-CHAP > 0' 43 | ) 44 | end 45 | end 46 | 47 | 48 | end 49 | 50 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | require 'puppetlabs_spec_helper/module_spec_helper' 2 | -------------------------------------------------------------------------------- /templates/extra-ini.erb: -------------------------------------------------------------------------------- 1 | ; File Managed by Puppet 2 | 3 | <% if @value != "" -%> 4 | <% if @value.is_a? Array -%> 5 | <% @value.each do |name| -%> 6 | <%= name %> 7 | <% end %> 8 | <% else -%> 9 | <%= value %> 10 | <% end -%> 11 | <% end -%> 12 | -------------------------------------------------------------------------------- /templates/spec.erb: -------------------------------------------------------------------------------- 1 | # This is a template used only for rspec tests 2 | 3 | # Yaml of the whole scope 4 | <%= scope.to_hash.reject { |k,v| !( k.is_a?(String) && v.is_a?(String) ) }.to_yaml %> 5 | 6 | # Custom Options 7 | <%= options['opt_a'] %> 8 | <%= options['opt_b'] %> 9 | --------------------------------------------------------------------------------