update package with condition

65 views
Skip to first unread message

puppetstan

unread,
Jan 14, 2015, 12:34:58 PM1/14/15
to puppet...@googlegroups.com
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?
Thanks in advance

regards


class paquet::redhat6-64 {

        package {'facter':
                  provider => 'rpm',
        #          install_options => ['-Uvh'],
                  source => "/tmp/facter-1.7.6-1.el6.x86_64.rpm",
                  require => File["/tmp/facter-1.7.6-1.el6.x86_64.rpm"],
                  notify => Service["puppet"],
              }

       file { "/tmp/facter-1.7.6-1.el6.x86_64.rpm":
       source => "puppet:///modules/paquet/facter-1.7.6-1.el6.x86_64.rpm"
       }

        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)",
}

Martin Alfke

unread,
Jan 15, 2015, 3:09:45 AM1/15/15
to puppet...@googlegroups.com
Hi,

with RH6 you can use yum provider and set ensure to latest.
(Maybe you need to create a yum repo for your factor package).

hth,

Martin
> --
> 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...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/d4289154-27d7-489d-adea-c452b4d6c767%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

puppetstan

unread,
Jan 15, 2015, 3:36:44 AM1/15/15
to puppet...@googlegroups.com
Hi

Yes it's a solution but for the moment i would like to use a condition ;) but i have a problem with it ;)

Regards

simon.o...@gmail.com

unread,
Jan 15, 2015, 5:24:27 AM1/15/15
to puppet...@googlegroups.com

        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)",
}


I think the problem lies in the onlyif rule, have you tried running that command on a machine? It should be a valid command and result in an exit code 0 to be true and nonzero to be false...

/Simon

puppetstan

unread,
Jan 15, 2015, 8:14:59 AM1/15/15
to puppet...@googlegroups.com

yes it's my problem my onlyif rule but i not understand where is the problem ...

regards
/Simon

jcbollinger

unread,
Jan 15, 2015, 9:16:43 AM1/15/15
to puppet...@googlegroups.com


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

puppetstan

unread,
Jan 15, 2015, 2:50:27 PM1/15/15
to puppet...@googlegroups.com

Hi John,

It's ok with unless => "/bin/bash -c '[ `/bin/rpm -q --qf %{VERSION} facter` = 1.7.6 ]'"

thanks a lot




Le mercredi 14 janvier 2015 18:34:58 UTC+1, puppetstan a écrit :
Reply all
Reply to author
Forward
0 new messages