That looks like what I need, I will test it all later. Thanks João and 
Andreas!


On Tuesday, October 6, 2015 at 8:29:16 PM UTC-4, Andreas Ntaflos wrote:
>
> On 2015-10-05 17:51, Fabien Delpierre wrote: 
> > Hey folks, 
> > I have something like this in a manifest: 
> > 
> > class foo( 
> >   $python_pips   = { 
> >     pbr => { ensure => '1.3.0', install_args => ['-I'] }, 
> >     linecache2 => { ensure => '1.0.0', install_args => ['-I'] }, 
> >     elasticsearch => { ensure => '1.6.0', install_args => ['-I'] }, 
> >   }, 
> >   ) { 
> >   require python 
> >   create_resources('python::pip', $python_pips) 
> > } 
> > 
> > I'm using this module: https://github.com/stankevich/puppet-python 
> > 
> > I'm wondering if there's a more elegant way of telling the python::pip 
> > resource to use the -I flag when installing those three pip packages. 
>
> The create_resources function supports a third argument for just this 
> use case: a hash with defaults for each created resource 
> (
> https://docs.puppetlabs.com/references/3.stable/function.html#createresources).
>  
>
> This works just fine in Puppet 3.x. 
>
> In your case you would do: 
>
> ``` 
> $python_pips = { 
>   pbr => { ensure => '1.3.0' }, 
>   linecache2 => { ensure => '1.0.0' }, 
>   elasticsearch => { ensure => '1.6.0' }, 
> } 
>
> $python_pip_defaults = { 
>   install_args => [ '-I' ], 
> } 
>
> require python 
>
> create_resources('::python::pip', $python_pips, $python_pip_defaults) 
> ``` 
>
> You can define that defaults hash in Hiera as well: 
>
> ``` 
> foo::python_pip_defaults: 
>   install_args: [ '-I' ] 
>   proxy: 'http://proxy.example.com:3128' 
>
> foo::python_pips: 
>   "pbr": 
>     ensure: 1.3.0 
>   "linecache2": 
>     ensure: 1.0.0 
>   "elasticsearch": 
>     ensure: 1.6.0 
> ``` 
>
> Then in your profile (or whatever kind of wrapper class you use): 
>
> ``` 
> $pips = hiera_hash('foo::python_pips', {}) 
> $pip_defaults = hiera_hash('foo::python_pip_defaults', {}) 
>
> create_resources('::python::pip', $pips, $pip_defaults) 
> ``` 
>
> We make use of this pattern extensively in our profile classes whenever 
> there are resources to create (usually defined or native types). 
>
> HTH Andreas 
>
>

-- 
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/ce324f05-ef69-4587-9d39-89a4d338de95%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to