diff --git a/.travis.yml b/.travis.yml index 12a73293..dc9062a6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -86,6 +86,7 @@ jobs: branches: only: - master + - module_rewrite - /^v\d/ notifications: email: false diff --git a/data/Archlinux/rolling.yaml b/data/Archlinux/rolling.yaml new file mode 100644 index 00000000..ed97d539 --- /dev/null +++ b/data/Archlinux/rolling.yaml @@ -0,0 +1 @@ +--- diff --git a/data/CentOS/6.yaml b/data/CentOS/6.yaml new file mode 100644 index 00000000..ed97d539 --- /dev/null +++ b/data/CentOS/6.yaml @@ -0,0 +1 @@ +--- diff --git a/data/CentOS/7.yaml b/data/CentOS/7.yaml new file mode 100644 index 00000000..ed97d539 --- /dev/null +++ b/data/CentOS/7.yaml @@ -0,0 +1 @@ +--- diff --git a/data/CentOS/8.yaml b/data/CentOS/8.yaml new file mode 100644 index 00000000..ed97d539 --- /dev/null +++ b/data/CentOS/8.yaml @@ -0,0 +1 @@ +--- diff --git a/data/Debian/10.yaml b/data/Debian/10.yaml new file mode 100644 index 00000000..a709a316 --- /dev/null +++ b/data/Debian/10.yaml @@ -0,0 +1,25 @@ +--- +php::external_repo: false +php::php_version: '7.3' +php::os_supported_php_versions: + - '7.3' + +php::external_repo_supported_php_versions: + - '5.6' + - '7.0' + - '7.1' + - '7.2' + - '7.3' + - '7.4' + +php::external_repo_details: + 'source_php_sury': + comment: 'the debian sury repo sury.org' + location: 'https://packages.sury.org/php/' + repos: 'main' + include: + src: true + deb: true + key: + id: '15058500A0235D97F5D10063B188E2B695BD4743' + source: 'https://packages.sury.org/php/apt.gpg' diff --git a/data/Debian/9.yaml b/data/Debian/9.yaml new file mode 100644 index 00000000..ed97d539 --- /dev/null +++ b/data/Debian/9.yaml @@ -0,0 +1 @@ +--- diff --git a/data/Fedora/31.yaml b/data/Fedora/31.yaml new file mode 100644 index 00000000..ed97d539 --- /dev/null +++ b/data/Fedora/31.yaml @@ -0,0 +1 @@ +--- diff --git a/data/Fedora/32.yaml b/data/Fedora/32.yaml new file mode 100644 index 00000000..ed97d539 --- /dev/null +++ b/data/Fedora/32.yaml @@ -0,0 +1 @@ +--- diff --git a/data/Fedora/33.yaml b/data/Fedora/33.yaml new file mode 100644 index 00000000..ed97d539 --- /dev/null +++ b/data/Fedora/33.yaml @@ -0,0 +1 @@ +--- diff --git a/data/FreeBSD/11.3.yaml b/data/FreeBSD/11.3.yaml new file mode 100644 index 00000000..ed97d539 --- /dev/null +++ b/data/FreeBSD/11.3.yaml @@ -0,0 +1 @@ +--- diff --git a/data/FreeBSD/11.4.yaml b/data/FreeBSD/11.4.yaml new file mode 100644 index 00000000..ed97d539 --- /dev/null +++ b/data/FreeBSD/11.4.yaml @@ -0,0 +1 @@ +--- diff --git a/data/FreeBSD/12.1.yaml b/data/FreeBSD/12.1.yaml new file mode 100644 index 00000000..ed97d539 --- /dev/null +++ b/data/FreeBSD/12.1.yaml @@ -0,0 +1 @@ +--- diff --git a/data/OpenSuSE/15.1.yaml b/data/OpenSuSE/15.1.yaml new file mode 100644 index 00000000..ed97d539 --- /dev/null +++ b/data/OpenSuSE/15.1.yaml @@ -0,0 +1 @@ +--- diff --git a/data/OpenSuSE/15.2.yaml b/data/OpenSuSE/15.2.yaml new file mode 100644 index 00000000..ed97d539 --- /dev/null +++ b/data/OpenSuSE/15.2.yaml @@ -0,0 +1 @@ +--- diff --git a/data/OpenSuSE/15.3.yaml b/data/OpenSuSE/15.3.yaml new file mode 100644 index 00000000..ed97d539 --- /dev/null +++ b/data/OpenSuSE/15.3.yaml @@ -0,0 +1 @@ +--- diff --git a/data/RedHat/6.yaml b/data/RedHat/6.yaml new file mode 100644 index 00000000..ed97d539 --- /dev/null +++ b/data/RedHat/6.yaml @@ -0,0 +1 @@ +--- diff --git a/data/RedHat/7.yaml b/data/RedHat/7.yaml new file mode 100644 index 00000000..ed97d539 --- /dev/null +++ b/data/RedHat/7.yaml @@ -0,0 +1 @@ +--- diff --git a/data/RedHat/8.yaml b/data/RedHat/8.yaml new file mode 100644 index 00000000..ed97d539 --- /dev/null +++ b/data/RedHat/8.yaml @@ -0,0 +1 @@ +--- diff --git a/data/SLES/11.yaml b/data/SLES/11.yaml new file mode 100644 index 00000000..ed97d539 --- /dev/null +++ b/data/SLES/11.yaml @@ -0,0 +1 @@ +--- diff --git a/data/SLES/12.yaml b/data/SLES/12.yaml new file mode 100644 index 00000000..ed97d539 --- /dev/null +++ b/data/SLES/12.yaml @@ -0,0 +1 @@ +--- diff --git a/data/SLES/15.yaml b/data/SLES/15.yaml new file mode 100644 index 00000000..ed97d539 --- /dev/null +++ b/data/SLES/15.yaml @@ -0,0 +1 @@ +--- diff --git a/data/Ubuntu/16.04.yaml b/data/Ubuntu/16.04.yaml new file mode 100644 index 00000000..ed97d539 --- /dev/null +++ b/data/Ubuntu/16.04.yaml @@ -0,0 +1 @@ +--- diff --git a/data/Ubuntu/18.04.yaml b/data/Ubuntu/18.04.yaml new file mode 100644 index 00000000..ed97d539 --- /dev/null +++ b/data/Ubuntu/18.04.yaml @@ -0,0 +1 @@ +--- diff --git a/data/Ubuntu/20.04.yaml b/data/Ubuntu/20.04.yaml new file mode 100644 index 00000000..ed97d539 --- /dev/null +++ b/data/Ubuntu/20.04.yaml @@ -0,0 +1 @@ +--- diff --git a/data/default.yaml b/data/common.yaml similarity index 96% rename from data/default.yaml rename to data/common.yaml index 5e9d4795..1afdd628 100644 --- a/data/default.yaml +++ b/data/common.yaml @@ -1,6 +1,4 @@ --- - lookup_options: php::fpm::pools: merge: first - diff --git a/hiera.yaml b/hiera.yaml index 7571ab3a..7c1161ea 100644 --- a/hiera.yaml +++ b/hiera.yaml @@ -1,6 +1,13 @@ --- version: 5 +defaults: + datadir: 'data' + data_hash: 'yaml_data' + hierarchy: - - name: default.yaml + - name: 'My Hierarchies' paths: - - 'default.yaml' + - '%{facts.os.name}/%{facts.os.distro.release.major}.yaml' + - '%{facts.os.name}/%{facts.os.release.full}.yaml' + - '%{facts.os.name}/%{facts.os.release.major}.yaml' + - 'common.yaml' diff --git a/manifests/init.pp b/manifests/init.pp index 7d2fc82d..500c1aef 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -133,6 +133,43 @@ # If set to false, a restart will be executed instead of a reload. # This default will be changed in a future release. # +######### +######### REWRITE +# +# @param [Boolean] manage_external_repo +# manage an external package repository or not +# @option external_repo [Boolean] :false +# default +# @option external_repo [Boolean] :true +# +# @param [Hash] external_repo_details +# The PHP versions the additional repositories support +# @option external_repo_details [Hash] :{} +# default: empty Hash, default for OS from Hiera Data in module +# +# @param [Array] external_repo_supported_php_versions +# The PHP versions the additional repositories support +# @option external_repo_supported_php_versions [Array] :[] +# default: empty array, default for OS from Hiera Data in module +# +# @param [Boolean] manage_internal_repo +# manage an internal package repository, parameter is to control +# app streams in CENTOS/RHEL/Fedora, Repos on FreeBSD or Archlinux +# @option external_repo [Boolean] :false +# true +# @option external_repo [Boolean] :true +# +# @param [Array] os_supported_php_versions +# The PHP versions the OS supports by default, without any additional repositories, +# on RHEL/CentOS and Fedora this includes app streams, on FreeBSD or Archlinux it manages Repos +# @option os_supported_php_versions [Array] :[] +# default: empty array, default for OS from Hiera Data in module +# +# @param [String] php_version +# Set the PHP version to install +# @option php_version [String] :'7.4' +# defaults: latest stable PHP Version available on php.net, default for OS from Hiera Data in module +# class php ( String $ensure = $php::params::ensure, Boolean $manage_repos = $php::params::manage_repos, @@ -169,6 +206,15 @@ String $log_group = $php::params::fpm_group, Boolean $pool_purge = $php::params::pool_purge, Boolean $reload_fpm_on_config_changes = true, + # added for refactoring + Boolean $manage_external_repo = false, + Array $external_repo_supported_php_versions = [], + Hash $external_repo_details = {}, + Boolean $manage_internal_repo = true, + Array $os_supported_php_versions = [], + String[1] $php_version = '7.4', # TODO: validate a version string here? + + ) inherits php::params { $real_fpm_package = pick($fpm_package, "${package_prefix}${php::params::fpm_package_suffix}") diff --git a/manifests/repo.pp b/manifests/repo.pp index 9cd217c3..d94de0ff 100644 --- a/manifests/repo.pp +++ b/manifests/repo.pp @@ -1,32 +1,55 @@ -# Configure package repository +# @api private +# @summary Configure package repository # -class php::repo { - $msg_no_repo = "No repo available for ${facts['os']['family']}/${facts['os']['name']}" +# @param [Boolean] manage_external_repo +# manage an external package repository or not +# @option external_repo [Boolean] :false +# default +# @option external_repo [Boolean] :true +# +# @param [Array] external_repo_supported_php_versions +# The PHP versions the additional repositories support +# @option external_repo_supported_php_versions [Array] :[] +# default: empty array, default for OS from Hiera Data in module +# +# @param [Boolean] manage_internal_repo +# manage an internal package repository, parameter is to control +# app streams in CENTOS/RHEL/Fedora, Repos on FreeBSD or Archlinux +# @option external_repo [Boolean] :false +# true +# @option external_repo [Boolean] :true +# +# @param [Array] os_supported_php_versions +# The PHP versions the OS supports by default, without any additional repositories, +# on RHEL/CentOS and Fedora this includes app streams, on FreeBSD or Archlinux it manages Repos +# @option os_supported_php_versions [Array] :[] +# default: empty array, default for OS from Hiera Data in module +# +# @param [String] php_version +# Set the PHP version to install +# @option php_version [String] :'7.4' +# defaults: latest stable PHP Version available on php.net, default for OS from Hiera Data in module +# +class php::repo ( + Boolean $manage_internal_repo = $php::manage_internal_repo, + Boolean $manage_external_repo = $php::manage_external_repo, + Optional[Array] $external_repo_supported_php_versions = $php::external_repo_supported_php_versions, + Array $os_supported_php_versions = $php::os_supported_php_versions, + Optional[String[1]] $php_version = $php::php_version, - case $facts['os']['family'] { - 'Debian': { - # no contain here because apt does that already - case $facts['os']['name'] { - 'Debian': { - include php::repo::debian - } - 'Ubuntu': { - include php::repo::ubuntu - } - default: { - fail($msg_no_repo) - } - } - } - 'FreeBSD': {} - 'Suse': { - contain php::repo::suse - } - 'RedHat': { - contain 'php::repo::redhat' - } - default: { - fail($msg_no_repo) +) { + assert_private() + $valid_external_php_version = $php_version in $external_repo_supported_php_versions + $valid_os_php_version = $php_version in $os_supported_php_versions + + if (($manage_internal_repo or $manage_external_repo) and ( $valid_os_php_version or $valid_external_php_version)) { + case $facts['os']['name'] { + 'Archlinux': { contain 'php::repo::archlinux' } + 'FreeBSD': { contain 'php::repo::freebsd' } + 'RedHat', 'CentOS', 'Fedora': { contain 'php::repo::redhat' } + 'Debian', 'Ubuntu': { contain 'php::repo::debian' } + 'OpenSuSE', 'SLES': { contain 'php::repo::suse' } + default: { contain 'php::repo::fallback' } } } } diff --git a/manifests/repo/archlinux.pp b/manifests/repo/archlinux.pp new file mode 100644 index 00000000..6160bbb4 --- /dev/null +++ b/manifests/repo/archlinux.pp @@ -0,0 +1,13 @@ +# @api private +# @summary Configure archlinux repo +# +# @param [Hash] external_repo_details +# The PHP versions the additional repositories support +# @option external_repo_details [Hash] :{} +# default: empty Hash, default for OS from Hiera Data in module +# +class php::repo::archlinux ( + Hash[String[1], Hash] $external_repo_details = $php::external_repo_details, +) { + assert_private() +} diff --git a/manifests/repo/debian.pp b/manifests/repo/debian.pp index 5dd4d507..a187aa24 100644 --- a/manifests/repo/debian.pp +++ b/manifests/repo/debian.pp @@ -1,67 +1,21 @@ -# Configure debian apt repo +# @api private +# @summary Configure debian apt repo # -# === Parameters -# -# [*location*] -# Location of the apt repository -# -# [*release*] -# Release of the apt repository -# -# [*repos*] -# Apt repository names -# -# [*include_src*] -# Add source source repository -# -# [*key*] -# Public key in apt::key format -# -# [*dotdeb*] -# Enable special dotdeb handling -# -# [*sury*] -# Enable special sury handling +# @param [Hash] external_repo_details +# The PHP versions the additional repositories support +# @option external_repo_details [Hash] :{} +# default: empty Hash, default for OS from Hiera Data in module # class php::repo::debian ( - $location = 'https://packages.dotdeb.org', - $release = 'wheezy-php56', - $repos = 'all', - $include_src = false, - $key = { - 'id' => '6572BBEF1B5FF28B28B706837E3F070089DF5277', - 'source' => 'http://www.dotdeb.org/dotdeb.gpg', - }, - $dotdeb = true, - $sury = true, + Hash[String[1], Hash] $external_repo_details = $php::external_repo_details, ) { assert_private() include 'apt' - apt::source { "source_php_${release}": - location => $location, - release => $release, - repos => $repos, - include => { - 'src' => $include_src, - 'deb' => true, - }, - key => $key, - } - - if ($sury and $php::globals::php_version in ['7.1','7.2']) { - apt::source { 'source_php_sury': - location => 'https://packages.sury.org/php/', - repos => 'main', - include => { - 'src' => $include_src, - 'deb' => true, - }, - key => { - id => '15058500A0235D97F5D10063B188E2B695BD4743', - source => 'https://packages.sury.org/php/apt.gpg', - }, + $external_repo_details.each |String $repository, Hash $repository_details| { + apt::source { $repository: + * => $repository_details, } } } diff --git a/manifests/repo/fallback.pp b/manifests/repo/fallback.pp new file mode 100644 index 00000000..4c015f73 --- /dev/null +++ b/manifests/repo/fallback.pp @@ -0,0 +1,8 @@ +# @api private +# @summary the fallback class, throws an error, if called +class php::repo::fallback () { + assert_private() + $msg_no_repo = "No repo available for ${facts['os']['family']}/${facts['os']['name']}" + + fail($msg_no_repo) +} diff --git a/manifests/repo/freebsd.pp b/manifests/repo/freebsd.pp new file mode 100644 index 00000000..167932c8 --- /dev/null +++ b/manifests/repo/freebsd.pp @@ -0,0 +1,12 @@ +# @api private +# @summary Configure Freebsd repos +# +# @param [Hash] external_repo_details +# The PHP versions the additional repositories support +# @option external_repo_details [Hash] :{} +# default: empty Hash, default for OS from Hiera Data in module +class php::repo::freebsd ( + Hash[String[1], Hash] $external_repo_details = $php::external_repo_details, +) { + assert_private() +} diff --git a/manifests/repo/redhat.pp b/manifests/repo/redhat.pp index 16cad240..43df04b6 100644 --- a/manifests/repo/redhat.pp +++ b/manifests/repo/redhat.pp @@ -1,34 +1,12 @@ -# Configure a yum repo for RedHat-based systems +# @api private +# @summary Configure RHEL/CENTOS/Fedora YUM repo # -# === Parameters -# -# [*yum_repo*] -# Class name of the repo under ::yum::repo -# - +# @param [Hash] external_repo_details +# The PHP versions the additional repositories support +# @option external_repo_details [Hash] :{} +# default: empty Hash, default for OS from Hiera Data in module class php::repo::redhat ( - $yum_repo = 'remi_php56', + Hash[String[1], Hash] $external_repo_details = $php::external_repo_details, ) { - $releasever = $facts['os']['name'] ? { - /(?i:Amazon)/ => '6', - default => '$releasever', # Yum var - } - - yumrepo { 'remi': - descr => 'Remi\'s RPM repository for Enterprise Linux $releasever - $basearch', - mirrorlist => "https://rpms.remirepo.net/enterprise/${releasever}/remi/mirror", - enabled => 1, - gpgcheck => 1, - gpgkey => 'https://rpms.remirepo.net/RPM-GPG-KEY-remi', - priority => 1, - } - - yumrepo { 'remi-php56': - descr => 'Remi\'s PHP 5.6 RPM repository for Enterprise Linux $releasever - $basearch', - mirrorlist => "https://rpms.remirepo.net/enterprise/${releasever}/php56/mirror", - enabled => 1, - gpgcheck => 1, - gpgkey => 'https://rpms.remirepo.net/RPM-GPG-KEY-remi', - priority => 1, - } + assert_private() } diff --git a/manifests/repo/suse.pp b/manifests/repo/suse.pp index 9c02f5bb..e43032c0 100644 --- a/manifests/repo/suse.pp +++ b/manifests/repo/suse.pp @@ -1,25 +1,13 @@ -# Configure suse repo +# @api private +# @summary Configure suse/sles zypper repo # -# === Parameters -# -# [*reponame*] -# Name of the Zypper repository -# -# [*baseurl*] -# Base URL of the Zypper repository +# @param [Hash] external_repo_details +# The PHP versions the additional repositories support +# @option external_repo_details [Hash] :{} +# default: empty Hash, default for OS from Hiera Data in module # class php::repo::suse ( - $reponame = 'mayflower-php56', - $baseurl = 'http://download.opensuse.org/repositories/home:/mayflower:/php5.6_based/SLE_11_SP3/', + Hash[String[1], Hash] $external_repo_details = $php::external_repo_details, ) { - zypprepo { $reponame: - baseurl => $baseurl, - enabled => 1, - autorefresh => 1, - } - ~> exec { 'zypprepo-accept-key': - command => 'zypper --gpg-auto-import-keys update -y', - path => '/usr/bin:/bin', - refreshonly => true, - } + assert_private() } diff --git a/manifests/repo/ubuntu.pp b/manifests/repo/ubuntu.pp deleted file mode 100644 index a8546f7b..00000000 --- a/manifests/repo/ubuntu.pp +++ /dev/null @@ -1,35 +0,0 @@ -# Configure ubuntu ppa -# -# === Parameters -# -# [*version*] -# PHP version to manage (e.g. 5.6) -# -class php::repo::ubuntu ( - $version = undef, -) { - if $facts['os']['name'] != 'Ubuntu' { - fail("class php::repo::ubuntu does not work on OS ${facts['os']['name']}") - } - include 'apt' - - if($version == undef) { - $version_real = '5.6' - } else { - $version_real = $version - } - - if ($version_real == '5.5') { - fail('PHP 5.5 is no longer available for download') - } - assert_type(Pattern[/^\d\.\d/], $version_real) - - $version_repo = $version_real ? { - '5.4' => 'ondrej/php5-oldstable', - default => 'ondrej/php' - } - - ::apt::ppa { "ppa:${version_repo}": - package_manage => true, - } -} diff --git a/metadata.json b/metadata.json index ac49eac4..0cee8d32 100644 --- a/metadata.json +++ b/metadata.json @@ -7,7 +7,6 @@ "source": "https://github.com/voxpupuli/puppet-php", "project_page": "https://github.com/voxpupuli/puppet-php", "issues_url": "https://github.com/voxpupuli/puppet-php/issues", - "description": "Puppet module that aims to manage PHP and extensions in a generic way on many platforms with sane defaults and easy configuration", "dependencies": [ { "name": "puppetlabs/stdlib", @@ -41,7 +40,8 @@ "operatingsystem": "Ubuntu", "operatingsystemrelease": [ "16.04", - "18.04" + "18.04", + "20.04" ] }, { @@ -55,33 +55,52 @@ "operatingsystem": "RedHat", "operatingsystemrelease": [ "6", - "7" + "7", + "8" ] }, { "operatingsystem": "CentOS", "operatingsystemrelease": [ "6", - "7" + "7", + "8" ] }, + { + "operatingsystem": "Fedora", + "operatingsystemrelease": [ + "31", + "32", + "24" + ] + }, { "operatingsystem": "FreeBSD", "operatingsystemrelease": [ - "11" + "11", + "12" ] }, { "operatingsystem": "SLES", "operatingsystemrelease": [ - "11" + "11", + "12", + "15" ] }, { - "operatingsystem": "OpenSUSE" + "operatingsystem": "OpenSUSE", + "operatingsystemrelease": [ + "15" + ] }, { - "operatingsystem": "Archlinux" + "operatingsystem": "Archlinux", + "operatingsystemrelease": [ + "rolling" + ] } ] }