[katello-devel] [PATCH] Add support for answer files.
Jan Pazdziora
jpazdziora at redhat.com
Fri Oct 7 10:17:05 UTC 2011
Hello,
please review a patch which is a start of moving default values from
the params.pp files to an answer file, to be able to then merge
default and custom answer files, plus command line options to
katello-configure. With the default values in this particular patch,
it's possible to do
PGPASSWORD=katellopw psql -h localhost -U katellouser katelloschema
so the values are properly processed and propagated.
I'll leave it up to you guys to decide which values should be
configurable via answer files / CLI options -- those should then be
specified in the default-answer-file. Please add comments (use hash
signs at start of lines) before each of the default value because
another patch will follow which will generate a man page from the
default-answer-file and the comments will be put into the man page.
Thank you.
---
puppet/README | 2 +-
puppet/bin/katello-configure | 2 +-
puppet/default-answer-file | 7 ++++
puppet/katello-configure.spec | 10 ++++--
.../parser/functions/katello_config_value.rb | 33 ++++++++++++++++++++
puppet/modules/katello/manifests/params.pp | 6 ++--
6 files changed, 52 insertions(+), 8 deletions(-)
create mode 100644 puppet/default-answer-file
create mode 100644 puppet/lib/puppet/parser/functions/katello_config_value.rb
diff --git a/puppet/README b/puppet/README
index a0a559f..59931e2 100644
--- a/puppet/README
+++ b/puppet/README
@@ -1 +1 @@
-echo include katello | puppet --modulepath katello/puppet/modules
+echo include katello | puppet --modulepath katello/puppet/modules --libdir katello/puppet/lib
diff --git a/puppet/bin/katello-configure b/puppet/bin/katello-configure
index 380106b..b9728d3 100644
--- a/puppet/bin/katello-configure
+++ b/puppet/bin/katello-configure
@@ -1,4 +1,4 @@
#!/bin/bash
-echo include katello | puppet --modulepath /usr/share/katello/install/puppet/modules
+echo include katello | puppet --modulepath /usr/share/katello/install/puppet/modules --libdir /usr/share/katello/install/puppet/lib
diff --git a/puppet/default-answer-file b/puppet/default-answer-file
new file mode 100644
index 0000000..c2d1c17
--- /dev/null
+++ b/puppet/default-answer-file
@@ -0,0 +1,7 @@
+
+db_name = katelloschema
+
+db_user = katellouser
+
+db_password = katellopw
+
diff --git a/puppet/katello-configure.spec b/puppet/katello-configure.spec
index b74518a..1d23fbc 100644
--- a/puppet/katello-configure.spec
+++ b/puppet/katello-configure.spec
@@ -1,5 +1,5 @@
-%global homedir %{_datarootdir}/katello/install/puppet/modules
+%global homedir %{_datarootdir}/katello/install
Name: katello-configure
Version: 0.1.4
@@ -27,10 +27,14 @@ Provides katello-configure script which configures Katello installation.
%install
rm -rf %{buildroot}
#prepare dir structure
-install -d -m 0755 %{buildroot}%{homedir}
install -d -m 0755 %{buildroot}%{_sbindir}
-cp -Rp modules/* %{buildroot}%{homedir}
install -m 0755 bin/katello-configure %{buildroot}%{_sbindir}
+install -d -m 0755 %{buildroot}%{homedir}
+install -d -m 0755 %{buildroot}%{homedir}/puppet/modules
+cp -Rp modules/* %{buildroot}%{homedir}/puppet/modules
+install -d -m 0755 %{buildroot}%{homedir}/puppet/lib
+cp -Rp lib/* %{buildroot}%{homedir}/puppet/lib
+install -m 0755 default-answer-file %{buildroot}%{homedir}
%clean
rm -rf %{buildroot}
diff --git a/puppet/lib/puppet/parser/functions/katello_config_value.rb b/puppet/lib/puppet/parser/functions/katello_config_value.rb
new file mode 100644
index 0000000..f0fc15d
--- /dev/null
+++ b/puppet/lib/puppet/parser/functions/katello_config_value.rb
@@ -0,0 +1,33 @@
+module Puppet::Parser::Functions
+ config_paths = Array.new()
+ default_path = __FILE__.gsub(/^(.+)\/[^\/]+\/lib\/.*$/, '\1') + '/default-answer-file'
+ if File.file?(default_path)
+ config_paths.push(default_path)
+ end
+ if ENV['KATELLO_ANSWER_FILE'] and File.file?(ENV['KATELLO_ANSWER_FILE'])
+ config_paths.push(ENV['KATELLO_ANSWER_FILE'])
+ end
+ data = Hash.new
+ config_paths.each do |filename|
+ file = File.new(filename, "r")
+ while (line = file.gets)
+ if line =~ /^\s*#/
+ next
+ end
+ line = line.gsub(/\s+$/, '')
+ if not line =~ /\S+/
+ next
+ end
+ if line =~ /^\s*(\w+)\s*=\s*(.*)/
+ data[$1] = $2
+ else
+ puts "Unsupported config line #{line} in file #{filename}"
+ end
+ end
+ file.close
+ end
+
+ newfunction(:katello_config_value, :type => :rvalue) do |args|
+ return data[args[0]]
+ end
+end
diff --git a/puppet/modules/katello/manifests/params.pp b/puppet/modules/katello/manifests/params.pp
index 1ac6149..203a4f7 100644
--- a/puppet/modules/katello/manifests/params.pp
+++ b/puppet/modules/katello/manifests/params.pp
@@ -1,8 +1,8 @@
class katello::params {
# database settings
- $db_user = "katello"
- $db_name = "katello"
- $db_pass = "katello"
+ $db_user = katello_config_value('db_user')
+ $db_name = katello_config_value('db_name')
+ $db_pass = katello_config_value('db_password')
# system settings
$user = "katello"
--
1.7.4.4
--
Jan Pazdziora | adelton at #satellite*, #brno
Principal Software Engineer, Satellite Engineering, Red Hat
More information about the katello-devel
mailing list