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