Seems pretty smart to me, tbh.

The only problem is that $myPackages is constant, so already includes the 
"7.4" values from $php_version.  You'll need to declare a new list (because 
you can't change variables) inside your .each block.

$php_remove.each | String $php_str_remove | { 
     $myRemovePackages = [
         "php${php_str_remove}-xml",
         "php${php_str_remove}-zip",
         "php${php_str_remove}-curl",
         "php${php_str_remove}-mbstring",
         "libapache2-mod-php${php_str_remove}",
    ] 
     ensure_packages($myRemovePackages,
         { 
              'ensure' => 'absent', 
         }  )
     }
 }

On Monday, October 12, 2020 at 5:10:34 AM UTC-4 [email protected] wrote:

> Hi all,
>
> I posted a question on Stackoverflow before the weekend, but no responses 
> and not many views yet, unfortunately. So please forgive me asking this 
> again here. refactor ensure_packages to switch version of installed 
> packages https://stackoverflow.com/q/64284862/13088564?sem=2
>
>
> I am successfully installing several PHP modules by version with puppet on 
> Debian linux like this:
> $php_version = '7.3' 
> ensure_packages([ 
>     "php$php_version-xml", 
>      "php$php_version-zip", 
>      "php$php_version-curl", 
>      "php$php_version-mbstring", 
>      "libapache2-mod-php$php_version",
>  ], 
>  { 'ensure' => 'present', } ) 
>
> now I want to prepare for an update from PHP 7.3 to 7.4. This basically 
> works, but the 7.3 packages stay installed. I would like to adapt the code 
> to remove the old packages. I am looking for a way to reuse the list of 
> packages of modules for uninstalling.
>
> I am thinking of a signature like this
> class profile::software::apache (
>      $php_version = '7.4',
>      $php_remove = ['7.0‘, ‘7.3']
>     , #... 
> ) {
>
> $myPackages = [
>      "php$php_version-xml",
>      "php$php_version-zip",
>      "php$php_version-curl",
>      "php$php_version-mbstring",
>      "libapache2-mod-php$php_version",
>  ] 
>  
> ensure_packages($myPackages, {
>      'ensure' => 'present', 
>  } ) 
>
>  $php_remove.each | String $php_version | { 
>      ensure_packages($myPackages,
>      { 
>           'ensure' => 'absent', 
>      }  )
>  }
>  }
>
> Is there a way to solve this?
>
> thx
>

-- 
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/470cea3c-b64f-4666-827f-0bccfb101afcn%40googlegroups.com.

Reply via email to