Glad you managed to figure it out, and thanks for posting your solution for 
posterity!

On Tuesday, October 13, 2020 at 12:26:35 PM UTC-4 [email protected] 
wrote:

> Hi all,
>
> I solved this with the use of puppet iteration functions:
>
> class profile::software::apache (
>   $php_version    = '7.4',
>   $php_remove     = ['7.0‘, ‘7.3'],
>   #...
> ) {
>   # build a hash of PHP Versions with a value of either present or absent
>   # and iterate over it with each
>   $phpInstallHash = { $php_version => 'present' }
>   #notify { "Value of phpRemove: ${php_remove}": }
>   if $php_remove {
>     # We have the array, use the map function to build remove hash
>     $phpRemoveHash = $php_remove.map |$version| {
>       { $version => 'absent' }
>     }
>     $phpFullHash = $phpInstallHash + $phpRemoveHash
>   } else {
>     $phpFullHash = $phpInstallHash
>   }
>   #notify { "phpHash to iterate over to install/uninstall: ${phpFullHash}": }
>
>   #iterate over the result installing/uninstalling
>   $phpFullHash.each | $php_version, $ensure_value | {
>     ensure_packages([
>       "php$php_version-xml",
>       "php$php_version-zip",
>       "php$php_version-curl",
>       "php$php_version-mbstring",
>       "libapache2-mod-php$php_version",
>     ],
>       {
>         'ensure' => $ensure_value,
>         require  => [Class['apt::update'],
>           Apt::Source['source_php_sury'],
>         ],
>         notify   => Class['apache::service'],
>       }
>     )
>
>   }
> }
>
>
> It works for me. I answered my StackOverflow question as well. Any 
> thoughts?
>
> As Garret pointed out, this for sure is not a recommended or usual way to 
> do things. The need for this stems from my use of the Sury PHP repository, 
> which offers several versions of PHP. I chose to use with 7.3 or 7.4 and 
> get all important and security related from that tree, so it’s not like 
> pinning a package to a fixed version.
>
> regards,
> Jochen
>  
>

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/8824a2b2-fa3e-4a16-a99b-ad9026477204n%40googlegroups.com.

Reply via email to