when publishing a content view if you get:
Validation failed: Puppet environment can't be blank
or
ActiveRecord::RecordInvalid: Validation failed: Name has already been taken
Run the following to recover:
# foreman-rake console
User.current = User.anonymous_api_admin
location = ::Location.find_by_title(::Setting[:default_location_puppet_content])
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 => cvpe.generate_puppet_env_name, :locations => [location], :organizations => [cvpe.content_view.organization])
end
env.organizations << cvpe.content_view.organization unless env.organizations.include?(cvpe.content_view.organization)
location = ::Location.find_by_title(::Setting[:default_location_puppet_content])
env.locations << location unless env.locations.include?(location)
cvpe.puppet_environment = env
cvpe.save!
end
For 6.5 and later: https://gist.github.com/mccun934/8cdeb1a2e23a95eef9b751a54959196c