summaryrefslogtreecommitdiff
path: root/bin/puppet_command
diff options
context:
space:
mode:
authorChristoph <chris@inferno.nadir.org>2014-09-23 16:59:53 +0200
committerChristoph <chris@inferno.nadir.org>2014-09-23 16:59:53 +0200
commit33ba61914bd0a7bc5d2f86d13d8bdb35318694c5 (patch)
tree0c59bb028fb962de18d70d40331e56b25037eba4 /bin/puppet_command
parent63783c1dc0a1e1749810162af169f0ffc0a237d5 (diff)
parentee575176530b3091cc0a6dda0f9c321d3ef06c87 (diff)
Merge branch 'develop' of github.com:leapcode/leap_platform into develop
Diffstat (limited to 'bin/puppet_command')
-rwxr-xr-xbin/puppet_command35
1 files changed, 24 insertions, 11 deletions
diff --git a/bin/puppet_command b/bin/puppet_command
index a9d39066..5e690bef 100755
--- a/bin/puppet_command
+++ b/bin/puppet_command
@@ -57,13 +57,9 @@ def apply
end
def set_hostname
- unless File.exists?(HIERA_FILE)
- puts("ERROR: Cannot set hostname without #{HIERA_FILE}")
- exit(1)
- end
- hostname = YAML.load_file(HIERA_FILE)['name']
+ hostname = hiera_file['name']
if hostname.nil? || hostname.empty?
- puts('ERROR: NAME argument required')
+ puts('ERROR: "name" missing from hiera file')
exit(1)
end
current_hostname_file = File.read('/etc/hostname') rescue nil
@@ -75,7 +71,7 @@ def set_hostname
f.write hostname
end
if File.read('/etc/hostname') == hostname
- puts "Set /etc/hostname to #{hostname}"
+ puts "Changed /etc/hostname to #{hostname}"
else
puts "ERROR: failed to update /etc/hostname"
end
@@ -84,9 +80,9 @@ def set_hostname
# call /bin/hostname
if current_hostname != hostname
if run("/bin/hostname #{hostname}") == 0
- puts "Set hostname to #{hostname}"
+ puts "Changed hostname to #{hostname}"
else
- puts "ERROR: failed to call `/bin/hostname #{hostname}`"
+ puts "ERROR: call to `/bin/hostname #{hostname}` returned an error."
end
end
end
@@ -97,9 +93,26 @@ end
def puppet_apply(options={}, &block)
options = {:verbosity => @verbosity, :tags => @tags}.merge(options)
manifest = options[:manifest] || SITE_MANIFEST
+ fqdn = hiera_file['domain']['name']
+ domain = hiera_file['domain']['full_suffix']
Dir.chdir(PUPPET_DIRECTORY) do
- return run("#{PUPPET_BIN} apply #{custom_parameters(options)} #{PUPPET_PARAMETERS} #{manifest}", &block)
+ return run("FACTER_fqdn='#{fqdn}' FACTER_domain='#{domain}' #{PUPPET_BIN} apply #{custom_parameters(options)} #{PUPPET_PARAMETERS} #{manifest}", &block)
+ end
+end
+
+#
+# Return a ruby object representing the contents of the hiera yaml file.
+#
+def hiera_file
+ unless File.exists?(HIERA_FILE)
+ puts("ERROR: hiera file '#{HIERA_FILE}' does not exist.")
+ exit(1)
end
+ $hiera_contents ||= YAML.load_file(HIERA_FILE)
+ return $hiera_contents
+rescue Exception => exc
+ puts("ERROR: problem reading hiera file '#{HIERA_FILE}' (#{exc})")
+ exit(1)
end
def custom_parameters(options)
@@ -201,4 +214,4 @@ Signal.trap("EXIT") do
# but only after the child puppet process is also dead (I think).
end
-main() \ No newline at end of file
+main()