My second Puppet module has just been released on the Forge. It’s called dirtree and you can download it from the Puppet Forge project page or check out the source code in the repo on GitHub.
The reason I created this module was so I could ensure an entire directory path was created by puppet. For example, if I wanted to create the folder /opt/foobar/fizzbuzz, I’d have to use the following Puppet manifest:
file { ['/opt', '/opt/foobar', '/opt/foobar/fizzbuzz']:
ensure => present,
}
If any of those directories were declared in another manifest, it would throw an error about the conflict. With the dirtree module I can ensure the entire tree is created like so:
$dirtree = dirtree('/opt/foobar/fizzbuzz')
ensure_resource('file', $dirtree, {'ensure' => 'present'})
As of the 4.1.0 release of puppetlabs-stdlib, ensure_resource accepts an array of resources and will check to see if they already exist and create them if they don’t. This will be a really great improvement for the DRYness of manifests that have to create directory structures.
Feel free to fork the repo on GitHub and contribute back to the project!
Puppet’s Exported Resources are a wonderful feature of the tool. In my environment, I’m using them to collect Munin configuration files for the Munin master server.
Each munin client gets the class munin-node with the following partial configuration:
class munin_node {
@@file { "/etc/munin/munin.conf.d/${::fqdn}.node":
content => "[Example.com;${::fqdn}]
address ${::ipaddress}
use_node_name yes",
tag => 'munin-node',
}
}
Then, the munin master node collects all the munin configuration files.
node 'munin-master' {
File <<| tag == 'munin-node' |>>
}
This is a really useful feature of puppet and it makes adding new nodes to Munin incredibly easy. It also makes it difficult to remove nodes from Munin that may have been shutdown permanently.
When I retire a system, I don’t want it to show up in Munin anymore, but because Puppet will collect resources for all the nodes its ever known about even if they’ve stopped reporting, removing the file by hand will cause it to be recreated by puppet. There is an easy fix for this though — deactivating and cleaning the node on the puppet master.
puppet node deactivate someoldnode.example.com
puppet node clean someoldnode.example.com
rm /etc/munin/munin.conf.d/someoldnode.example.com.node
The first two commands will effectively retire an old node from Puppet. The first will deactivate it (and stop the master from collecting resources for it) and the second will clean its certificate. The last one is obviously to remove the file created by the collected exported resource.
I’ve just released my first Puppet module to the forge. It’s called disk_stats and you can download it from the Puppet Forge project page or check out the source code in the repo on GitHub.
I’ve been using Puppet at work for about a year and have developed some pretty advanced modules for use at work. This module I developed for my own personal use with my website. I wanted to be able to see disk usage in the Puppet Dashboard, but the default facts don’t expose disk statistics, only swap info.
Feel free to fork the repo on GitHub and contribute back to the project!
The default installation of RHEL 6 and CentOS 6 will create separate LVM volumes for /home. This means much of your disk is allocated to /home when it could be used for something else. Keeping /home on a separate partition is a good idea for multi-user systems, but for machines that act as a service box, it may be wasted disk space. For example, here’s a system that has 50G partitioned for /home when it’s really not needed.
$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_repo-lv_root 148G 113G 29G 80% /
tmpfs 499M 0 499M 0% /dev/shm
/dev/sda1 485M 156M 304M 34% /boot
/dev/mapper/vg_repo-lv_home 47G 181M 45G 1% /home
To remove the logical volume that stores /home and add the free space to the root partition, follow these steps:
Note: Make sure you’re logged into the system at the console as a user whose homedir isn’t in /home. Logging in as root usually works.
cd /
cp -Ra /home /home.bak # Make a backup of home
umount /home
lvm lvremove /dev/vg_<hostname>/lv_home # Remove the logical volume for home
lvm lvresize -l+100%FREE /dev/vg_<hostname>/lv_root # Resize the root logical volume so it uses 100% of the now free space
resize2fs /dev/vg_<hostname>/lv_root # Resize the filesystem to use the whole logical volume
mv /home.bak /home # Restore the backup.
More Notes:
- This can be done on a live system as long as /home is not in use when you try to unmount it.
- You can also follow these steps to resize another logical volume if it has another name and isn’t in use.
- This may work with some adjustments on a RHEL/CentOS 5 system, I haven’t tried it though.
Made me chuckle.
I’m not inclined to make grand pronouncements about the future of software, but if anything kills off commercial software, let me tell you, it won’t be open source software. They needn’t bother. Commercial software will gleefully strangle itself to death on its own licensing terms.
Jeff Atwood, Coding Horror
Snowboarding with friends at Peek’n Peek in New York.
Shot on a GoPro HD Hero2 at 720p and edited with Apple iMovie.
Music: