Wednesday, October 31, 2012

Puppet DNS lookup

From time to time NetworkManager breaks my /etc/resolv.conf. I normally turn that off using puppet but when /etc/resolv.conf is broken, puppet won't run so I have to fix it manually :-(

Well, not any more. Now I add a static /etc/hosts entry for the puppet server and puppet will run even when /etc/resolv.conf is broken.

The special part about this is that I look up the IP address using a template so I don't have to hard code the value in my manifest. Google said it could not be done without writing a custom function. As always, I did not believe it...

Assuming you have set $puppetserver to contain the fqdn of your puppet server:

host { 'hostsconf-puppet':
        ensure => present,
        ip => inline_template("<% _erbout.concat('$puppetserver').to_s) %>"),
        name => $puppetserver,
        target => '/etc/hosts',


  1. Hooray for no more manual fixes! And what a simple solution it was, too. This is definitely one of those things that you put up with for a long time until one day you're just like "enough!" and actually do something about it. And that something takes like two seconds and you should've done it months ago.

    Better late than never?

    Fred |

  2. This is also a very good post which I really enjoyed reading. It is not everyday that I have the possibility to see something like this.
    gun mayhem 2

  3. Wonderful goods from you, man. I have understand your stuff previous to and you’re just extremely magnificent. I actually like what you’ve acquired here, certainly like what you are saying and the way in which you say it. You make it entertaining and you still care for to keep it wise.
    I can’t wait to read much more from you. This is really a great web site.

    films altadefinizione

  4. Very interesting content. Thanks.

    Lucy Hennessy, for more info visit my Homepage