Reputation: 7491
I am an absolute novice in puppet and I need to modify the existent puppet script
So, I have in the chain:
package { 'python-pip':
ensure => 'present',
} ->
In reality it should be
package { 'python2-pip':
ensure => 'present',
} ->
Can I add an OR condition, so it will work for both 'python2-pip' and 'python-pip'? So, if any of these packages is installed the result will be positive - is it possible?
Upvotes: 0
Views: 568
Reputation: 180093
Can I add an OR condition, so it will work for both 'python2-pip' and 'python-pip'? So, if any of these packages is installed the result will be positive - is it possible?
No, it is not possible as such. Every Package
resource manages exactly one package, and declaring such a resource means that Puppet should attempt to ensure the specified state -- in this case, that some version of the specified package is installed on the target node. If you declare two packages then Puppet will try to manage two packages.
If truly "in reality it should be" python2-pip, then you should simply change the manifest appropriately.
If your nodes under management are heterogeneous, however, you may actually mean that on a strict subset of your nodes, the package name should really be "python2-pip", whereas on others, the current "python-pip" is correct. This kind of situation is relatively common, and it is usually addressed by using node facts to modulate your declarations.
That could take the form of using if
blocks or other conditional statements to switch between alternative whole declarations, but often one can be more surgical. For example, a common approach is to choose just the package name conditionally, store the result in a variable, and just plug it in to your declaration. Maybe something like this:
$pip_package = $::operatingsystemmajrelease ? {
default => 'python-pip',
'7' => 'python2-pip'
}
package { $pip_package:
ensure => 'present',
}
Since you are a novice, it might be worth your while to have a look at how some existing modules approach such problems. Many modules are available on Github for you to browse, and anything you install from the Forge is at minimum available locally on your machine for you to examine.
Upvotes: 1