How to have puppet install package only if one file doesn't exist?

6,621 views
Skip to first unread message

staceyt...@gmail.com

unread,
Jun 10, 2015, 9:27:14 AM6/10/15
to puppet...@googlegroups.com
Hi all,

I am trying to use puppet to push package "flex-devel-2.5.35-9.el6.i686" only if the file /usr/lib/libl.a doesn't exist.

I tried several ways, but still can't get it work.

Any suggestions?

Thanks,
Stacey

kaustubh chaudhari

unread,
Jun 10, 2015, 1:08:46 PM6/10/15
to puppet...@googlegroups.com
You can create a custom fact to check for that file if the file dose not exist then install else do nothing.

==
Facter.add(:bigfix) do
  confine :kernel => "Linux"
  setcode do
    if File.exist? "/etc/init.d/besclient"
        "true"
    else "false"
    end
  end
end
==

if this file exist i ignore it else i install bigfix.

Hope this help.

-Kaustubh

staceyt...@gmail.com

unread,
Jun 10, 2015, 2:09:05 PM6/10/15
to puppet...@googlegroups.com
Hi Kaustubh,

Thank you very much! I will give it a try!

Thanks,
Stacey

jcbollinger

unread,
Jun 11, 2015, 9:22:55 AM6/11/15
to puppet...@googlegroups.com


Yes: declare the package unconditionally.

File /usr/lib/libl.a belongs to the package you're considering installing.  Any locally-built, system-wide Flex should be in /usr/local, not in /usr, so you're basically saying that you always want the flex-devel package to be present on the system.  This goes straight to Puppet's core behavior: it manages machine state, performing those state changes needed to put target machines into a specified state.  As such, it tests the current state to determine what to do.  You don't need to do anything special to achieve that, just

package { "flex-devel":
 
ensure => 'present'
 
# or, ensure => 'latest'
}

If the package is already present (alternatively, if the latest available version is already present) then Puppet will not attempt to install / update.


John

Toky

unread,
Jun 19, 2015, 2:20:23 PM6/19/15
to puppet...@googlegroups.com
I think the cleanest way would be to check on the package resource like so:

package { "flex-devel":
 
ensure => 'present',
  unless => '/usr/bin/test -f /usr/lib/libl.a',
}

Docs => https://docs.puppetlabs.com/puppet/latest/reference/lang_conditional.html#unless-statements

Cheers,



On Wednesday, June 10, 2015 at 9:27:14 AM UTC-4, staceyt...@gmail.com wrote:

Haani Niyaz

unread,
Jun 21, 2015, 11:37:31 PM6/21/15
to puppet...@googlegroups.com
I don't think your proposed solution will work since the catalogue is compiled on the master. 

jcbollinger

unread,
Jun 22, 2015, 9:27:56 AM6/22/15
to puppet...@googlegroups.com


On Friday, June 19, 2015 at 1:20:23 PM UTC-5, Toky wrote:
I think the cleanest way would be to check on the package resource like so:

package { "flex-devel":
 
ensure => 'present',
  unless => '/usr/bin/test -f /usr/lib/libl.a',
}

Docs => https://docs.puppetlabs.com/puppet/latest/reference/lang_conditional.html#unless-statements



This will not work because the Package resource type does not have an 'unless' parameter -- that's a feature specific to Exec resources.  The documentation referenced is about something different: the 'unless' statement.  An 'unless' statement could be used to avoid declaring the package at all in the event that a custom fact communicated that file /usr/lib/libfl.a was present on the target machine, but that would require writing that custom fact.

I still claim that the best approach is to let the provider handle it.  This case does not require any kind of conditionality at the manifest level.


John

Reply all
Reply to author
Forward
0 new messages