Puppet Host File Configuration Example


1) Add a new host entry

node “UT-9c8e99e3959e”{
host { ‘ntp.my.lab’:
ip => ‘1.1.1.1’,
host_aliases => ‘time’,}
}

Example:

generic@UT-9c8e99e3959e:~$ cat /etc/hosts
127.0.0.1 localhost
127.0.0.1 UT-9c8e99e3959e

generic@UT-9c8e99e3959e:~$ sudo puppet agent –test
info: Caching catalog for ut-9c8e99e3959e
info: Applying configuration version ‘1361667399’
notice: /Stage[main]//Node[ut-9c8e99e3959e]/Host[ntp.my.lab]/ensure: created
info: FileBucket adding {md5}4a09e9bcef41c5b11f2f9cd84d4226df
notice: Finished catalog run in 0.02 seconds

generic@UT-9c8e99e3959e:~$ cat /etc/hosts
# HEADER: This file was autogenerated at Sun Feb 24 11:56:35 +1100 2013
# HEADER: by puppet.  While it can still be managed manually, it
# HEADER: is definitely not recommended.
127.0.0.1       localhost
127.0.0.1       UT-9c8e99e3959e
1.1.1.1 ntp.my.lab      time

generic@UT-9c8e99e3959e:~$ ping time
PING ntp.my.lab (1.1.1.1) 56(84) bytes of data.

2) Remove a host entry

node “UT-9c8e99e3959e”{
host { ‘ntp.my.lab’:
ensure => “absent”}
}

Example:

generic@UT-9c8e99e3959e:~$ sudo puppet agent –test
info: Caching catalog for ut-9c8e99e3959e
info: Applying configuration version ‘1361667917’
notice: /Stage[main]//Node[ut-9c8e99e3959e]/Host[ntp.my.lab]/ensure: removed
info: FileBucket adding {md5}9592837d023ef3eabd5e64f9db03d5dd
notice: Finished catalog run in 0.02 seconds

generic@UT-9c8e99e3959e:~$ cat /etc/hosts
# HEADER: This file was autogenerated at Sun Feb 24 12:05:13 +1100 2013
# HEADER: by puppet.  While it can still be managed manually, it
# HEADER: is definitely not recommended.
127.0.0.1       localhost
127.0.0.1       UT-9c8e99e3959e

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s