Monthly Archives: November 2014

Creating A Custom OS X Puppet Installer

puppet_installer_icon

Getting puppet on OSX is getting better and simpler. You now have 3 packages to install, the puppet user is created for you and it just works … for the most part. In my environment, I have a couple extra steps. Like installing the Launch Daemon when I also install the packages, and adding my puppet master to the hosts file on each client. Instead of  touching each client 5 to 6 times to get puppet setup. I rolled it into a custom package.

I’m using PackageMaker but certainly you could use any flavor of package management (packages, iceberg, etc) and my client machines are on OSX 10.9.5.

01I downloaded Facter, Hiera, and Puppet from the puppetlabs website and pulled out the pkgs. Then added them to my PackageMaker project.

_ _ _ _

02
I created the com.puppetlabs.puppet.plist Launch Daemon and added the file to the project. Just make sure to change the “Destination” to “/Library/LaunchDaemons”

For good measure, here’s the com.puppetlabs.puppet.plist. Just copied from the website.

<!--?<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
        <key>Label</key>
        <string>com.puppetlabs.puppet</string>
        <key>OnDemand</key>
        <false/>
        <key>ProgramArguments</key>
        <array>
                <string>/usr/bin/puppet</string>
                <string>agent</string>
                <string>--no-daemonize</string>
                <string>--logdest</string>
                <string>syslog</string>
                <string>--color</string>
                <string>false</string>
        </array>
        <key>RunAtLoad</key>
        <true/>
        <key>ServiceDescription</key>
        <string>Puppet agent service</string>
        <key>ServiceIPC</key>
        <false/>
</dict>
</plist>

_ _ _ _

03I also added a Postinstall script to handle a few extra things like installing some dependencies, making root the owner of the Launch Daemon, setting the permission on the Launch Daemon, and then adding my puppet server to the hosts file.

#!/bin/sh

#need for property_list_key
gem install CFPropertyList -v 2.2.6

#need for managedmac
gem install sqlite3

#change owner and permissions of puppet launchdaemon
sudo chown root:wheel /Library/LaunchDaemons/com.puppetlabs.puppet.plist
sudo chmod 644 /Library/LaunchDaemons/com.puppetlabs.puppet.plist

#edit hosts file with puppet server IP. Change xxx to match your server IP.
echo "\nxxx.xxx.xxx.xxx    puppet" >> /etc/hosts

Next … build package and go forth and puppetize!

Check OSX Mavericks Powersettings With Shell Script

Instead of using puppet or profiles to check and set the OS X energy settings. I also wrote a simple script that checks the current status of “Computer Sleep”. If it’s set to anything other then “Never” go to sleep, it runs my pmset command and sets the machine to my desired settings.

#!/bin/sh
#version 1.0

#checks the curret status of "Computer Sleep", if it's not set to 0(never sleep), then it runs the pmset command
# sets display sleep to 30 minutes
# sets computer sleep = never
# sets hard drive sleep - never
# sets wake for network access = true
# sets autorestart after power failure = true


if [[ `pmset -g | grep -w sleep |awk '{print $2}'` -gt 0 ]]; then
    
    echo "Changing Power Settings"
    pmset -c displaysleep 30 sleep 0 disksleep 0 womp 1 autorestart 1

    else
        echo "Settings are correct"
    fi

Managing OSX Mavericks Power Settings With Puppet

One of the things I want Puppet to do for my lab of iMac’s is to make sure the computers never go to sleep. That way when I need remote access to them, I know I have it.

Ideally, I don’t want puppet to run the same command every time it runs. It would be much better if it checked for a “sleep” status and then ran on the out coming of the check.

I’ve been testing this back and forth for a day or so and the code I currently have … seems to be doing the trick.

exec { "set_power_settings":
        path   => ["/usr/bin", "/usr/sbin", "/bin", "/sbin"],
        command => "pmset -c displaysleep 30 sleep 0 disksleep 0 womp 1 autorestart 1",
        unless => "pmset -g | grep -w sleep | awk '{print $2}' | grep -w 0 >/dev/null",
        }

The gist of it is… run the “Command“, which set’s my desired power settings. “unless” the current state of “sleep” is already set to “0” (never sleep).