thx for the smart ;-)

but when I redeclare the list, I end up keeping two lists of packages. The guy 
who I am, I will definitely fuck this up regularly… and that’s back to the root 
of my problem… I would like to somehow reuse the $myPackages structure with 
different values for $php_version. 

Mhmm… as I write this this sounds like a use for a template…

Regards
Jochen

> Am 12.10.2020 um 13:46 schrieb A Manzer <aman...@gmail.com>:
> 
> 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 jochen....@gmail.com 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 
> <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 puppet-users+unsubscr...@googlegroups.com 
> <mailto:puppet-users+unsubscr...@googlegroups.com>.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/puppet-users/470cea3c-b64f-4666-827f-0bccfb101afcn%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/puppet-users/470cea3c-b64f-4666-827f-0bccfb101afcn%40googlegroups.com?utm_medium=email&utm_source=footer>.

-- 
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 puppet-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/63C45E2D-B9FD-49A6-96EC-1CD608A60F21%40gmail.com.

Reply via email to