Skip to content

Instantly share code, notes, and snippets.

@ares
Created January 12, 2017 18:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ares/5435226ef0317613535101765404d3f5 to your computer and use it in GitHub Desktop.
Save ares/5435226ef0317613535101765404d3f5 to your computer and use it in GitHub Desktop.
Convert templates in files to use parameters macros
Dir.glob('./**/*.erb').each do |template|
puts "Found #{template}"
content = File.read(template)
content = content.gsub(/@host\.param_true\?\((.*?)\)/, 'host_param_true?(\1)')
content = content.gsub(/@host\.param_false\?\((.*?)\)/, 'host_param_false?(\1)')
content = content.gsub(/@host\.params\[(.*?)\]/, 'host_param(\1)')
content = content.gsub(/@host\.info/, 'host_enc')
File.write(template, content)
end
@erwstx
Copy link

erwstx commented Nov 8, 2019

hi, do you have a readme file with this script ? How should I use it ?
I want to convert my provisioning template syntax to the new one on my Satellite 6.6 (https://access.redhat.com/documentation/en-us/red_hat_satellite/6.6/html/upgrading_and_updating_red_hat_satellite/post_upgrade_tasks#post_upgrade-updating-templates-parameters)

@ares
Copy link
Author

ares commented Nov 12, 2019

you put it to the directory with templates, then you run it ruby migrate.rb. It will go over every *.erb file in that dir and update it. On existing installations, templates are in database, so you would need to export them, fix them, import them back. For that, foreman_templates plugin can be used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment