Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

foreman-config - dry run

Allow running without affecting the actual configuration. Useful in
puppet manifest unless statement: exits with 1 if some change is
needed, otherwise 0.
  • Loading branch information...
commit dbda7ad5344061e023c7a99e2845dd6e10019ef0 1 parent 69be164
Ivan Necas iNecas authored ohadlevy committed
Showing with 22 additions and 3 deletions.
  1. +22 −3 script/foreman-config
25 script/foreman-config
View
@@ -8,6 +8,7 @@ defaults = {:foreman_path => File.expand_path("../..", __FILE__),
:key_values => {}}
options.merge!(defaults)
+changed_settings = []
def set_options_key_value(options, value)
unless options.has_key?(:key)
@@ -59,6 +60,12 @@ BANNER
"Runtime environment (default #{defaults[:environment]})") do |val|
options[:environment] = val
end
+
+ opt.on("-n",
+ "--dry-run",
+ "Don't change thd configuration. Success if no change is needed.") do
+ options[:dry] = true
+ end
end
parser.parse!
@@ -112,13 +119,17 @@ elsif options[:key_values].any?
options[:keys].each do |key|
value = options[:key_values][key]
setting = Setting.find_by_name(key)
+ old_value = setting.value
if value == :unset
- setting.value = nil
+ value = nil
else
value = typecast_value(setting.settings_type, value)
- setting.value = value
end
- setting.save! if setting.changed?
+ setting.value = value
+ if setting.valid? && old_value != setting.value
+ setting.save! unless options[:dry]
+ changed_settings << setting
+ end
puts format_value(setting.settings_type, setting.value)
end
else
@@ -126,3 +137,11 @@ else
puts "#{setting.name}: #{format_value(setting.settings_type, setting.value)}"
end
end
+
+if options[:dry]
+ if changed_settings.empty?
+ exit 0
+ else
+ exit 1
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.