Skip to content

Instantly share code, notes, and snippets.

@palmertime
Last active October 20, 2015 21:16
Show Gist options
  • Save palmertime/8755d046f70d717fcc1f to your computer and use it in GitHub Desktop.
Save palmertime/8755d046f70d717fcc1f to your computer and use it in GitHub Desktop.
Fix for validation error when creating a CV version
User.current = User.first
Katello::ContentViewPuppetEnvironment.where(:puppet_environment_id => nil).where("environment_id is not null").each do |cvpe|
env = Environment.where(:name => cvpe.generate_puppet_env_name).first
if env.nil?
env = Environment.create(:name => 'foo', :locations => [Location.default_location], :organizations => [cvpe.content_view.organization])
end
env.organizations << cvpe.content_view.organization unless env.organizations.include?(cvpe.content_view.organization)
env.locations << Location.default_location unless env.locations.include?(Location.default_location)
cvpe.puppet_environment = env
cvpe.save!
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment