[Satellite6] Publishing a content view fails with "Validation failed: Puppet environment can't be blank" error
Environment
Red Hat Satellite 6.1 - 6.6 (where Puppet Environment (PE) is mandatory for a CV)
Red Hat Satellite 6.7+ (where Puppet Environment is optional for a CV and the solution applies only to CVs that had accidentally deleted their PE)
Issue
- an attempt to create or publish a content view fails with error "
Validation failed: Puppet environment can't be blank"
Resolution
Create missing puppet environments for affected content views. Connect to foreman-rake console:
# foreman-rake console
and then execute this script:
User.current = User.anonymous_api_admin
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.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
Ensure no content view has empty / undefined puppet environment - below check within the console should return no content view:
::Katello::ContentViewPuppetEnvironment.where('puppet_environment_id is NULL AND environment_id is NOT NULL')
- Solution applicable for Red Hat Satellite 6.5 and 6.6:
# 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|
ename = Environment.construct_name(cvpe.organization,
cvpe.environment,
cvpe.content_view)
env = Environment.where(:name => ename).first
if env.nil?
env = Environment.create(:name => ename, :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 more KB articles/solutions related to Red Hat Satellite 6.x Content View Issues, please refer to the Red Hat Satellite Consolidated Troubleshooting Article for Red Hat Satellite 6.x Content View Issues
Root Cause
Every content view has to have it's puppet environment in order to apply potential puppet classes associated with this content view - this has been made optional even since Sat6.7.
The puppet environments should be created automatically for every content view and Satellite relies on their presence.
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.