On Wednesday, January 14, 2015 at 11:34:58 AM UTC-6, puppetstan wrote: > > Hi, > > I would like to update the package facter on all of my servers. (I can not > use INSTALL_OPTIONS because my puppet version is too old) > > I added a condition--> if the package facter is installed AND if facter > version is not facter-1.7.6-1.el6.x86_64.rpm I install the package but I > think > I have an error in my onlyif condition because it does not work. > > Can you have an idea please? >
[...] > exec {'rpm updates': > command => '/bin/rpm -Uvh /tmp/facter-1.7.6-1.el6.x86_64.rpm', > onlyif => "/bin/rpm -q facter and ('/usr/bin/facter -v' != > facter-1.7.6)", > } > > Your 'onlyif' command has several problems, some of which mask others. The topmost problem is that the shell's logical conjunction operator is spelled '&&', not 'and'. As the command is written now, it's just /bin/rpm with six arguments: "-q", "facter", "and", "('/usr/bin/facter -v'", "!=", and "facter-1.7.6)". It turns out that rpm is happy to accept that (most of the arguments are interpreted as package names about which you are inquiring). Next, you are using parentheses where you want either square brackets ([...]) or the 'test' program. Also, if you were using square brackets then they would need to be separated from their contents by whitespace ('[' is an alternative name for the 'test' command, to which the argument ']' is significant; neither is a shell reserved word). Also, you are using the wrong quotes for command substitution. You want to enclose the inner 'facter' command in backticks (`), not single quotes ('), to run it and have the standard output substituted in. Additionally, "facter -v" on my systems returns just the Facter version number (e.g. 1.6.18), not (package)-(version) as your command seems to anticipate. Overall, because of its reliance on shell features (conjunction operator and command substitution) you only have a hope of this working if it runs via Exec's 'shell' provider (which is not the default) or if you explicitly wrap it in a shell invocation. Putting it all together, then, that would look something like this: onlyif => "/bin/bash -c '/bin/rpm -q facter && [ `/usr/bin/facter -v` != 1.7.6 ]'" Personally, though, I'd go about it a bit more directly: unless => "/bin/bash -c '[ `/bin/rpm -q --qf %{VERSION} facter` = 1.7.6 ]'" John -- 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/a1c5bf34-3777-46cd-bfd7-312966a12e2f%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.