From 814d7489a61d5c98a4bad72dcbd9beb3610c51cc Mon Sep 17 00:00:00 2001
From: Greg Swift <gregswift@gmail.com>
Date: Fri, 28 Jan 2011 08:23:15 -0600
Subject: [PATCH] Setup to create a separate cobbler-puppet package for enabling cobbler as a puppet external node.
 - Added cobbler-puppet.conf config file for cobbler-ext-nodes script
 - Adjusted cobbler-ext-nodes to check several spots for its configuration
 - Added cobbler-puppet sub-package to the spec file

---
 cobbler.spec               |   24 +++++++++++++++++++++++-
 config/cobbler-puppet.conf |   11 +++++++++++
 scripts/cobbler-ext-nodes  |   16 ++++++++++++----
 3 files changed, 46 insertions(+), 5 deletions(-)
 create mode 100644 config/cobbler-puppet.conf

diff --git a/cobbler.spec b/cobbler.spec
index 187e525..a38a0e5 100644
--- a/cobbler.spec
+++ b/cobbler.spec
@@ -73,6 +73,8 @@ test "x$RPM_BUILD_ROOT" != "x" && rm -rf $RPM_BUILD_ROOT
 mkdir -p $RPM_BUILD_ROOT/etc/httpd/conf.d
 install -p -m 644 config/cobbler.conf $RPM_BUILD_ROOT/etc/httpd/conf.d/
 install -p -m 644 config/cobbler_web.conf $RPM_BUILD_ROOT/etc/httpd/conf.d/
+mkdir -p $RPM_BUILD_ROOT/etc/puppet
+install -p -m 644 config/cobbler-puppet.conf $RPM_BUILD_ROOT/etc/puppet/cobbler.conf
 
 mkdir -p $RPM_BUILD_ROOT/var/spool/koan
 
@@ -147,7 +149,6 @@ fi
 %defattr(-,root,root,-)
 
 %{_bindir}/cobbler
-%{_bindir}/cobbler-ext-nodes
 %{_bindir}/cobblerd
 %{_sbindir}/tftpd.py*
 
@@ -237,6 +238,27 @@ http://server/cobbler_web to configure the install server.
 %dir /var/lib/cobbler/webui_sessions
 /var/www/cobbler_webui_content/
 
+%package -n cobbler-puppet
+
+Summary: Cobbler external node configuration for Puppet
+Group: Applications/System
+Requires: puppet
+Requires: PyYAML
+%if 0%{?fedora} >= 11 || 0%{?rhel} >= 6
+Requires: python(abi) >= %{pyver}
+%endif
+
+%description -n cobbler-puppet
+
+Cobbler external node script and configuration that allows
+Puppet to get its information from the install server.
+
+%files -n cobbler-puppet
+%defattr(-,root,root,-)
+%doc AUTHORS COPYING CHANGELOG README
+%config(noreplace) /etc/puppet/cobbler.conf
+%{_bindir}/cobbler-ext-nodes
+
 %changelog
 * Thu Jun 17 2010 Scott Henson <shenson@redhat.com> - 2.1.0-1
 - Bump upstream release
diff --git a/config/cobbler-puppet.conf b/config/cobbler-puppet.conf
new file mode 100644
index 0000000..e7f8796
--- /dev/null
+++ b/config/cobbler-puppet.conf
@@ -0,0 +1,11 @@
+# this is the address of the cobbler server -- as it is used
+# by systems during the install process, it must be the address
+# or hostname of the system as those systems can see the server.
+# if you have a server that appears differently to different subnets
+# (dual homed, etc), you need to read the --server-override section
+# of the manpage for how that works.
+server: 127.0.0.1
+
+# change this port if Apache is not running plaintext on port
+# 80.  Most people can leave this alone.
+http_port: 80
diff --git a/scripts/cobbler-ext-nodes b/scripts/cobbler-ext-nodes
index 1e90125..fcde46f 100644
--- a/scripts/cobbler-ext-nodes
+++ b/scripts/cobbler-ext-nodes
@@ -1,9 +1,16 @@
 #!/usr/bin/python
 
+import os
 import yaml # PyYAML version
 import urlgrabber
 import sys
 
+# These are in order of precedence.
+# If puppet and cobbler are on the same system, use cobbler's settings file
+# If the file was installed manually from cobbler tarball are likely to end up in the second
+# If installed with cobbler-puppet rpm it would be the last entry
+CONFIG_FILES = ("/etc/cobbler/settings", "/etc/cobbler/cobbler-puppet.conf", "/etc/puppet/cobbler.conf")
+
 if __name__ == "__main__":
    hostname = None
    try:
@@ -12,10 +19,11 @@ if __name__ == "__main__":
       print "usage: cobbler-ext-nodes <hostname>"
 
    if hostname is not None:
-       conf = open("/etc/cobbler/settings")
+       for config_file in CONFIG_FILES:
+         if os.access(config_file, os.R_OK):
+           break
+       conf = open(config_file)
        config = yaml.load(conf.read());
        conf.close()
        url = "http://%s:%s/cblr/svc/op/puppet/hostname/%s" % (config["server"], config["http_port"], hostname)
-       print urlgrabber.urlread(url)
-
-
+       print urlgrabber.urlread(url)
\ No newline at end of file
-- 
1.7.3.4

