From cb304e47f12ae15c0fb127818b2be2c992195c97 Mon Sep 17 00:00:00 2001 From: flepoutre <84913246+flepoutre@users.noreply.github.com> Date: Thu, 21 Dec 2023 16:20:03 +0000 Subject: [PATCH 1/9] Add Puppet8x support --- {tests => examples}/init.pp | 0 manifests/alias.pp | 57 ++++++++++++++++++++--------------- manifests/aliasng.pp | 51 +++++++++++++++++++------------ manifests/cacheclear.pp | 5 +-- manifests/config.pp | 13 ++------ manifests/extension.pp | 6 ++-- manifests/init.pp | 37 +++++++++++------------ manifests/install.pp | 14 +++------ manifests/install/composer.pp | 19 ++++++------ manifests/params.pp | 5 ++- manifests/setup.pp | 14 +++------ metadata.json | 4 +-- 12 files changed, 111 insertions(+), 114 deletions(-) rename {tests => examples}/init.pp (100%) diff --git a/tests/init.pp b/examples/init.pp similarity index 100% rename from tests/init.pp rename to examples/init.pp diff --git a/manifests/alias.pp b/manifests/alias.pp index 3f2c343..4ebf149 100644 --- a/manifests/alias.pp +++ b/manifests/alias.pp @@ -1,40 +1,49 @@ # == Define Resource Type: drush::alias # +# @param ensure +# @param alias_name +# @param group +# @param parent +# @param root +# @param uri +# @param db_url +# @param path_aliases +# @param ssh_options +# @param remote_host +# @param remote_user +# @param custom_options +# @param command_specific +# @param source_command_specific +# @param target_command_specific +# define drush::alias ( - String $ensure = present, - String $alias_name = $name, - Optional[String] $group = undef, - Optional[String] $parent = undef, - Optional[Stdlib::Absolutepath] $root = undef, - Optional[String] $uri = undef, - Optional[String] $db_url = undef, - Optional[Hash] $path_aliases = undef, - Optional[String] $ssh_options = undef, - Optional[String] $remote_host = undef, - Optional[String] $remote_user = undef, - Optional[Hash] $custom_options = undef, - Optional[Hash] $command_specific = undef, - Optional[Hash] $source_command_specific = undef, - Optional[Hash] $target_command_specific = undef, + String $ensure = present, + String $alias_name = $name, + Optional[String] $group = undef, + Optional[String] $parent = undef, + Optional[String] $root = undef, + Optional[String] $uri = undef, + Optional[String] $db_url = undef, + Optional[Variant[Hash, String]] $path_aliases = undef, + Optional[String] $ssh_options = undef, + Optional[String] $remote_host = undef, + Optional[String] $remote_user = undef, + Optional[String] $custom_options = undef, + Optional[Variant[Hash, String]] $command_specific = undef, + Optional[Variant[Hash, String]] $source_command_specific = undef, + Optional[Variant[Hash, String]] $target_command_specific = undef, ) { - if (!defined(Class['drush'])) { fail('You must include class drush before declaring aliases') } - if $parent { - if $parent !~ /^@/ { - fail("Invalid parent alias '${parent}'. Parent aliases must start with @.") - } - } - $aliasfile = $group ? { undef => '/etc/drush/aliases.drushrc.php', default => "/etc/drush/${group}.aliases.drushrc.php", } if !defined(Concat[$aliasfile]) { - concat{ $aliasfile: + concat { $aliasfile: ensure => $ensure, } concat::fragment { "${aliasfile}-header": @@ -49,6 +58,4 @@ content => template('drush/alias.erb'), order => 1, } - } - diff --git a/manifests/aliasng.pp b/manifests/aliasng.pp index 46fea44..3079c01 100644 --- a/manifests/aliasng.pp +++ b/manifests/aliasng.pp @@ -1,23 +1,38 @@ # == Define Resource Type: drush::aliasng # +# @param ensure +# @param alias_name +# @param group +# @param root +# @param parent +# @param uri +# @param db_url +# @param path_aliases +# @param ssh_options +# @param remote_host +# @param remote_user +# @param custom_options +# @param command_specific +# @param source_command_specific +# @param target_command_specific +# define drush::aliasng ( - String $ensure = present, - String $alias_name = $name, - Optional[String] $group = undef, - Optional[String] $parent = undef, - Optional[Stdlib::Absolutepath] $root = undef, - Optional[String] $uri = undef, - Optional[String] $db_url = undef, - Optional[Hash] $path_aliases = undef, - Optional[String] $ssh_options = undef, - Optional[String] $remote_host = undef, - Optional[String] $remote_user = undef, - Optional[Hash] $custom_options = undef, - Optional[Hash] $command_specific = undef, - Optional[Hash] $source_command_specific = undef, - Optional[Hash] $target_command_specific = undef, + String $ensure = present, + String $alias_name = $name, + Optional[String] $group = undef, + Optional[String] $parent = undef, + Optional[String] $root = undef, + Optional[String] $uri = undef, + Optional[String] $db_url = undef, + Optional[Variant[Hash, String]] $path_aliases = undef, + Optional[String] $ssh_options = undef, + Optional[String] $remote_host = undef, + Optional[String] $remote_user = undef, + Optional[String] $custom_options = undef, + Optional[Variant[Hash, String]] $command_specific = undef, + Optional[Variant[Hash, String]] $source_command_specific = undef, + Optional[Variant[Hash, String]] $target_command_specific = undef, ) { - if (!defined(Class['drush'])) { fail('You must include class drush before declaring aliases') } @@ -41,7 +56,7 @@ } if !defined(Concat[$aliasfile]) { - concat{ $aliasfile: + concat { $aliasfile: ensure => $ensure, } concat::fragment { "${aliasfile}-header": @@ -56,6 +71,4 @@ content => template('drush/aliasng.erb'), order => 1, } - } - diff --git a/manifests/cacheclear.pp b/manifests/cacheclear.pp index a590ec4..1ea22ae 100644 --- a/manifests/cacheclear.pp +++ b/manifests/cacheclear.pp @@ -3,10 +3,9 @@ # Private class. # class drush::cacheclear { - #private() if $caller_module_name != $module_name { - warning("${name} is not part of the public API of the ${module_name} \ + warning("${name} is not part of the public API of the ${module_name} \ module and should not be directly included in the manifest.") } @@ -17,6 +16,4 @@ require => File[$drush::drush_exe_default], refreshonly => true, } - } - diff --git a/manifests/config.pp b/manifests/config.pp index bc82bf9..257f225 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -3,10 +3,9 @@ # Private class. # class drush::config { - #private() if $caller_module_name != $module_name { - warning("${name} is not part of the public API of the ${module_name} \ + warning("${name} is not part of the public API of the ${module_name} \ module and should not be directly included in the manifest.") } @@ -32,19 +31,15 @@ alias-path => [ '/etc/drush/sites', ], - include => [ - '/usr/share/drush/commands', - ], }, }, } file { '/etc/drush/drush.yml': - ensure => present, + ensure => file, content => to_yaml($drush_modern_config), } } - # Create aliases. if $drush::legacy { create_resources(drush::alias, $drush::aliases) @@ -55,8 +50,6 @@ # Install extensions. if $drush::legacy { - drush::extension{ $drush::extensions: } + drush::extension { $drush::extensions: } } - } - diff --git a/manifests/extension.pp b/manifests/extension.pp index 43a69d3..a585cf0 100644 --- a/manifests/extension.pp +++ b/manifests/extension.pp @@ -1,7 +1,6 @@ # == Define Resource Type: drush::extension # -define drush::extension() { - +define drush::extension () { if (!defined(Class['drush'])) { fail('You must include class drush before declaring aliases') } @@ -11,10 +10,9 @@ $extension_name = $parts[0] # TODO ensure using a drush legacy version here. - exec {"${drush::drush_exe_default} dl ${name}": + exec { "${drush::drush_exe_default} dl ${name}": command => "su - -c '${drush::drush_exe_default} dl ${name} && [[ -e /usr/share/drush/commands/${extension_name}/composer.json ]] && cd /usr/share/drush/commands/${extension_name} && ${drush::composer_path} install'", creates => "/usr/share/drush/commands/${extension_name}", notify => Class['drush::cacheclear'], } - } diff --git a/manifests/init.pp b/manifests/init.pp index 6da7417..3019714 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -51,22 +51,21 @@ # Path to a ini file with php overrides. If provided, it will set DRUSH_INI # environment variable system-wide. See `docs-ini-files` for details. # -class drush( - Array[String] $versions = ['10',], - String $default_version = '10', - String $install_type = 'dist', - Boolean $ensure_extra_packages = false, - Array[String] $extra_packages = $drush::params::extra_packages, - Boolean $bash_integration = false, - Boolean $bash_autocompletion = true, - Array $extensions = [], - Hash $aliases = {}, - Stdlib::Absolutepath $composer_path = '/usr/local/bin/composer', - Optional[Stdlib::Absolutepath] $php_path = undef, - Optional[Stdlib::Absolutepath] $php_ini_path = undef, - Optional[Stdlib::Absolutepath] $drush_ini_path = undef, +class drush ( + Array[String] $versions = ['7',], + String $default_version = '7', + String $install_type = 'dist', + Boolean $ensure_extra_packages = false, + Array $extra_packages = $drush::params::extra_packages, + Boolean $bash_integration = false, + Boolean $bash_autocompletion = true, + Array $extensions = [], + Hash $aliases = {}, + String $composer_path = '/usr/local/bin/composer', + Optional[String] $php_path = undef, + Optional[String] $php_ini_path = undef, + Optional[String] $drush_ini_path = undef, ) inherits drush::params { - # Identify legacy and/or modern drush installation. $legacy_versions = $drush::versions.filter |$version| { versioncmp($version, '9') < 0 @@ -84,10 +83,8 @@ $install_base_path = '/opt/drush' $drush_exe_default = '/usr/local/bin/drush' - class{'drush::setup': } - -> class{'drush::config': } - ~> class{'drush::cacheclear': } + class { 'drush::setup': } + -> class { 'drush::config': } + ~> class { 'drush::cacheclear': } -> Class['drush'] - } - diff --git a/manifests/install.pp b/manifests/install.pp index 89b3442..ebe8403 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -14,18 +14,16 @@ # [*method*] # Installation method. It only accepts composer at present. # -define drush::install( - $version, - $install_type = 'dist', - $method = 'composer', +define drush::install ( + String $version, + String $install_type = 'dist', + String $method = 'composer', ) { - - $install_types = [ 'dist', 'source' ] + $install_types = ['dist', 'source'] if ! ($install_type in $install_types) { fail("'${install_type}' is not a valid value for creation_mode. Valid values: ${install_types}.") } - # Pick major version. $parts = split($version, '[.]') $version_major = $parts[0] @@ -59,6 +57,4 @@ require => File[$drush_exe], refreshonly => true, } - } - diff --git a/manifests/install/composer.pp b/manifests/install/composer.pp index 836f248..c438e4e 100644 --- a/manifests/install/composer.pp +++ b/manifests/install/composer.pp @@ -1,14 +1,17 @@ # == Define Resource Type: drush::install::composer # -define drush::install::composer( - $version, - $install_path, - $install_type, +# @param version +# @param install_path +# @param install_type +# +define drush::install::composer ( + String $version, + String $install_path, + String $install_type, ) { - #private() if $caller_module_name != $module_name { - warning("${name} is not part of the public API of the ${module_name} \ + warning("${name} is not part of the public API of the ${module_name} \ module and should not be directly included in the manifest.") } @@ -32,8 +35,6 @@ cwd => $install_path, environment => ["COMPOSER_HOME=${composer_home}"], require => File[$install_path], - onlyif => "test ! -f composer.json || test \"$(grep drush/drush composer.json | cut -d\\\" -f 4)\" != '${real_version}'" + onlyif => "test ! -f composer.json || test \"$(grep drush/drush composer.json | cut -d\\\" -f 4)\" != '${real_version}'", } - } - diff --git a/manifests/params.pp b/manifests/params.pp index 82bb156..5c1b901 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -3,7 +3,7 @@ # This class manages drush parameters. # class drush::params { - case $::osfamily { + case $facts['os']['family'] { 'Debian': { $extra_packages = [ 'bzip2', @@ -27,8 +27,7 @@ ] } default: { - fail("Unsupported operatingsystem: ${::osfamily}/${::operatingsystem}.") + fail("Unsupported operatingsystem: ${facts['os']['family']}/${facts['os']['name']}.") } } } - diff --git a/manifests/setup.pp b/manifests/setup.pp index 3f614ed..ccf8dea 100644 --- a/manifests/setup.pp +++ b/manifests/setup.pp @@ -3,10 +3,9 @@ # Private class. # class drush::setup { - #private() if $caller_module_name != $module_name { - warning("${name} is not part of the public API of the ${module_name} \ + warning("${name} is not part of the public API of the ${module_name} \ module and should not be directly included in the manifest.") } @@ -17,7 +16,7 @@ } } - concat{ 'drush-sh-profile': + concat { 'drush-sh-profile': ensure => present, path => '/etc/profile.d/drush.sh', } @@ -54,14 +53,12 @@ } # Drush directories. - file { ['/etc/drush', '/usr/share/drush', '/usr/share/drush/commands', '/usr/share/drush/commands/Commands']: + file { ['/etc/drush', '/usr/share/drush', '/usr/share/drush/commands']: ensure => directory, } if $drush::modern { file { '/etc/drush/sites': - ensure => directory, - purge => true, - recurse => true, + ensure => directory, } } @@ -77,7 +74,7 @@ $versions = parseyaml(template('drush/install-versions-hash.erb')) $defaults = { install_type => $drush::install_type, - method => 'composer' + method => 'composer', } create_resources('drush::install', $versions, $defaults) @@ -89,5 +86,4 @@ ensure => link, target => "${default_path}/vendor/drush/drush", } - } diff --git a/metadata.json b/metadata.json index 992880f..6e33691 100644 --- a/metadata.json +++ b/metadata.json @@ -10,7 +10,7 @@ "dependencies": [ { "name": "puppetlabs/stdlib", - "version_requirement": ">= 4.14.0 < 7.0.0" + "version_requirement": ">= 4.14.0 < 10.0.0" }, { "name": "puppetlabs/concat", @@ -50,7 +50,7 @@ "requirements": [ { "name": "puppet", - "version_requirement": ">= 5.5.0 < 8.0.0" + "version_requirement": ">= 5.5.0 < 9.0.0" } ], "tags": [ From fabf3abaf3c9dc16609fc7b756370d6f9694cdec Mon Sep 17 00:00:00 2001 From: flepoutre <84913246+flepoutre@users.noreply.github.com> Date: Fri, 22 Dec 2023 09:17:26 +0100 Subject: [PATCH 2/9] Update alias.pp --- manifests/alias.pp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/manifests/alias.pp b/manifests/alias.pp index 4ebf149..11ceac3 100644 --- a/manifests/alias.pp +++ b/manifests/alias.pp @@ -21,17 +21,17 @@ String $alias_name = $name, Optional[String] $group = undef, Optional[String] $parent = undef, - Optional[String] $root = undef, + Optional[Stdlib::Absolutepath] $root = undef, Optional[String] $uri = undef, Optional[String] $db_url = undef, - Optional[Variant[Hash, String]] $path_aliases = undef, + Optional[Hash] $path_aliases = undef, Optional[String] $ssh_options = undef, Optional[String] $remote_host = undef, Optional[String] $remote_user = undef, - Optional[String] $custom_options = undef, - Optional[Variant[Hash, String]] $command_specific = undef, - Optional[Variant[Hash, String]] $source_command_specific = undef, - Optional[Variant[Hash, String]] $target_command_specific = undef, + Optional[Hash] $custom_options = undef, + Optional[Hash] $command_specific = undef, + Optional[Hash] $source_command_specific = undef, + Optional[Hash] $target_command_specific = undef, ) { if (!defined(Class['drush'])) { fail('You must include class drush before declaring aliases') From 7ce5fe62fd05e81974b0ba83147feea5782a3953 Mon Sep 17 00:00:00 2001 From: flepoutre <84913246+flepoutre@users.noreply.github.com> Date: Fri, 22 Dec 2023 09:18:30 +0100 Subject: [PATCH 3/9] Update alias.pp --- manifests/alias.pp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/manifests/alias.pp b/manifests/alias.pp index 11ceac3..d862bda 100644 --- a/manifests/alias.pp +++ b/manifests/alias.pp @@ -37,6 +37,12 @@ fail('You must include class drush before declaring aliases') } + if $parent { + if $parent !~ /^@/ { + fail("Invalid parent alias '${parent}'. Parent aliases must start with @.") + } + } + $aliasfile = $group ? { undef => '/etc/drush/aliases.drushrc.php', default => "/etc/drush/${group}.aliases.drushrc.php", From 77f318bcab73b2b04af87e85d9f0e8e225037139 Mon Sep 17 00:00:00 2001 From: flepoutre <84913246+flepoutre@users.noreply.github.com> Date: Fri, 22 Dec 2023 09:20:59 +0100 Subject: [PATCH 4/9] Update aliasng.pp --- manifests/aliasng.pp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/manifests/aliasng.pp b/manifests/aliasng.pp index 3079c01..a7d91e0 100644 --- a/manifests/aliasng.pp +++ b/manifests/aliasng.pp @@ -21,17 +21,17 @@ String $alias_name = $name, Optional[String] $group = undef, Optional[String] $parent = undef, - Optional[String] $root = undef, + Optional[Stdlib::Absolutepath] $root = undef, Optional[String] $uri = undef, Optional[String] $db_url = undef, - Optional[Variant[Hash, String]] $path_aliases = undef, + Optional[Hash] $path_aliases = undef, Optional[String] $ssh_options = undef, Optional[String] $remote_host = undef, Optional[String] $remote_user = undef, - Optional[String] $custom_options = undef, - Optional[Variant[Hash, String]] $command_specific = undef, - Optional[Variant[Hash, String]] $source_command_specific = undef, - Optional[Variant[Hash, String]] $target_command_specific = undef, + Optional[Hash] $custom_options = undef, + Optional[Hash] $command_specific = undef, + Optional[Hash] $source_command_specific = undef, + Optional[Hash] $target_command_specific = undef, ) { if (!defined(Class['drush'])) { fail('You must include class drush before declaring aliases') From 217ea3cd40516280042a63464d4c2bc6c549f928 Mon Sep 17 00:00:00 2001 From: flepoutre <84913246+flepoutre@users.noreply.github.com> Date: Fri, 22 Dec 2023 09:23:42 +0100 Subject: [PATCH 5/9] Update config.pp --- manifests/config.pp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/manifests/config.pp b/manifests/config.pp index 257f225..96c69d7 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -31,11 +31,14 @@ alias-path => [ '/etc/drush/sites', ], + include => [ + '/usr/share/drush/commands', + ], }, }, } file { '/etc/drush/drush.yml': - ensure => file, + ensure => present, content => to_yaml($drush_modern_config), } } From d609ae8489897452de718fb89a0a18fc2dbd7563 Mon Sep 17 00:00:00 2001 From: flepoutre <84913246+flepoutre@users.noreply.github.com> Date: Fri, 22 Dec 2023 09:27:00 +0100 Subject: [PATCH 6/9] Update init.pp --- manifests/init.pp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/manifests/init.pp b/manifests/init.pp index 3019714..52705a7 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -52,19 +52,19 @@ # environment variable system-wide. See `docs-ini-files` for details. # class drush ( - Array[String] $versions = ['7',], - String $default_version = '7', - String $install_type = 'dist', - Boolean $ensure_extra_packages = false, - Array $extra_packages = $drush::params::extra_packages, - Boolean $bash_integration = false, - Boolean $bash_autocompletion = true, - Array $extensions = [], - Hash $aliases = {}, - String $composer_path = '/usr/local/bin/composer', - Optional[String] $php_path = undef, - Optional[String] $php_ini_path = undef, - Optional[String] $drush_ini_path = undef, + Array[String] $versions = ['10',], + String $default_version = '10', + String $install_type = 'dist', + Boolean $ensure_extra_packages = false, + Array[String] $extra_packages = $drush::params::extra_packages, + Boolean $bash_integration = false, + Boolean $bash_autocompletion = true, + Array $extensions = [], + Hash $aliases = {}, + Stdlib::Absolutepath $composer_path = '/usr/local/bin/composer', + Optional[Stdlib::Absolutepath] $php_path = undef, + Optional[Stdlib::Absolutepath] $php_ini_path = undef, + Optional[Stdlib::Absolutepath] $drush_ini_path = undef, ) inherits drush::params { # Identify legacy and/or modern drush installation. $legacy_versions = $drush::versions.filter |$version| { From aead140297f68f5deab2c3e61aae78cf725dd547 Mon Sep 17 00:00:00 2001 From: flepoutre <84913246+flepoutre@users.noreply.github.com> Date: Fri, 22 Dec 2023 09:28:34 +0100 Subject: [PATCH 7/9] Update setup.pp --- manifests/setup.pp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/manifests/setup.pp b/manifests/setup.pp index ccf8dea..f54c81b 100644 --- a/manifests/setup.pp +++ b/manifests/setup.pp @@ -53,12 +53,14 @@ } # Drush directories. - file { ['/etc/drush', '/usr/share/drush', '/usr/share/drush/commands']: + file { ['/etc/drush', '/usr/share/drush', '/usr/share/drush/commands', '/usr/share/drush/commands/Commands']: ensure => directory, } if $drush::modern { file { '/etc/drush/sites': - ensure => directory, + ensure => directory, + purge => true, + recurse => true, } } From df3a2895f62d3650075ea63bbacd3a3fff72324a Mon Sep 17 00:00:00 2001 From: flepoutre <84913246+flepoutre@users.noreply.github.com> Date: Fri, 22 Dec 2023 09:36:07 +0100 Subject: [PATCH 8/9] Update config.pp --- manifests/config.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/config.pp b/manifests/config.pp index 96c69d7..a405811 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -38,7 +38,7 @@ }, } file { '/etc/drush/drush.yml': - ensure => present, + ensure => file, content => to_yaml($drush_modern_config), } } From b711e71eac8a2c82899a41d113d5bbd773e6be16 Mon Sep 17 00:00:00 2001 From: flepoutre <84913246+flepoutre@users.noreply.github.com> Date: Tue, 24 Jun 2025 10:09:11 +0000 Subject: [PATCH 9/9] add exec path --- manifests/install.pp | 1 + 1 file changed, 1 insertion(+) diff --git a/manifests/install.pp b/manifests/install.pp index ebe8403..780de5b 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -56,5 +56,6 @@ command => "su - -c '${drush_exe} status'", require => File[$drush_exe], refreshonly => true, + path => '/usr/bin:/usr/sbin:/bin:/sbin', } }