execute a command if a package isn't installed, then install the package

5,253 views
Skip to first unread message

loki77

unread,
Jul 14, 2012, 5:19:06 PM7/14/12
to Puppet Users
Hi, I'm trying to install the 'unbound' dns resolver in ubuntu via
puppet and I'm running into some issues. The issue isn't that the
package doesn't install, but rather that apt automatically starts the
daemon - and when the daemon starts, it updates resolv.conf in a way
that breaks DNS.

There's a command, 'resolvconf --disable-updates' that will stop
unbound from making the change it wants to. What I'd like to do is:

- If unbound isn't installed, then execute --disable-updates
- Then install unbound
- Then --enable-updates

Is there anyway to do this? Thanks.

Peter Bukowinski

unread,
Jul 14, 2012, 6:30:35 PM7/14/12
to puppet...@googlegroups.com
You can either write a custom fact that gets set when unbound is installed/active and use that in an if block around the stop-install-start procedure, or use the 'resolvconf --disable-updates' exec resource's 'unless' parameter to test for a running unbound daemon prior to installing the package.

--
Peter Bukowinski

loki77

unread,
Jul 15, 2012, 11:13:47 PM7/15/12
to Puppet Users
The only downside to that is that resolvconf could be left disabled
for longer than just the installation of the package. While I don't
think this will be a problem in most cases I'm hoping there's another
way to handle this. Thanks!

Martin Alfke

unread,
Jul 16, 2012, 4:12:38 AM7/16/12
to puppet...@googlegroups.com
Hi
You can use require and notify within the package resource to run exec statements.

e.g. (untested)

exec { 'disable':
command => '/path/to/resolvconf --disable-updates',
onlyif => 'dpkg -l | grep -c unbound | wc -l',
}
exec { 'enable':
command => '/path/tp/resolvconf --enable-updates',
unless => 'dpkg -l | grep -c unbound | wc -l',
}
package { 'unbound':
requires => Exec['disable'],
notify => Exec['enable'],
}

- Martin

Reply all
Reply to author
Forward
0 new messages