From f933660d3bb2f060c0047abea622be670b3e6a02 Mon Sep 17 00:00:00 2001 From: unkin-agent Date: Sun, 20 Sep 2026 23:08:20 +1000 Subject: [PATCH] Fetch agent ENC facts from encapi (#528) The enc_role and enc_env facts still resolve against Cobbler on every agent, the last Cobbler dependency in the classification path now that the master-side ENC runs encapic-enc. - Point the fact at https://encapi.k8s.syd1.au.unkin.net - Rename the module and its messages from Cobbler to encapi Cache file, TTL and fallback-to-cache failure behaviour are unchanged. Reviewed-on: https://git.unkin.net/unkin/puppet-prod/pulls/528 Co-authored-by: unkin-agent Co-committed-by: unkin-agent --- modules/libs/lib/facter/enc_direct_facts.rb | 22 ++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/modules/libs/lib/facter/enc_direct_facts.rb b/modules/libs/lib/facter/enc_direct_facts.rb index 3aec01b..bf0fed4 100644 --- a/modules/libs/lib/facter/enc_direct_facts.rb +++ b/modules/libs/lib/facter/enc_direct_facts.rb @@ -6,8 +6,8 @@ require 'net/http' require 'uri' require 'fileutils' -# CobblerENC module: Fetches ENC data from Cobbler, caches it, and provides structured facts. -module CobblerENC +# EncapiENC module: Fetches ENC data from encapi, caches it, and provides structured facts. +module EncapiENC CACHE_FILE = '/var/cache/puppet_enc.yaml' CACHE_TTL = 7 * 24 * 60 * 60 # 7 days in seconds @enc_data = nil # In-memory cache for the ENC response @@ -29,8 +29,8 @@ module CobblerENC File.write(CACHE_FILE, cache_data.to_yaml) end - def self.fetch_from_cobbler - uri = URI("http://cobbler.main.unkin.net/cblr/svc/op/puppet/hostname/#{Facter.value(:fqdn) || Facter.value(:hostname)}") + def self.fetch_from_encapi + uri = URI("https://encapi.k8s.syd1.au.unkin.net/cblr/svc/op/puppet/hostname/#{Facter.value(:fqdn) || Facter.value(:hostname)}") response = Net::HTTP.get_response(uri) raise "Failed to fetch ENC data. HTTP #{response.code}" unless response.is_a?(Net::HTTPSuccess) @@ -41,7 +41,7 @@ module CobblerENC def self.retrieve_enc_data return @enc_data if @enc_data - @enc_data = fetch_from_cobbler + @enc_data = fetch_from_encapi write_cache(@enc_data) @enc_data end @@ -49,26 +49,26 @@ module CobblerENC def self.fetch_enc_data retrieve_enc_data rescue StandardError => e - Facter.warn("Error retrieving Cobbler ENC data: #{e.message}") + Facter.warn("Error retrieving encapi ENC data: #{e.message}") @enc_data = read_cache return @enc_data unless @enc_data.empty? - raise 'No cached ENC data available and Cobbler is down.' + raise 'No cached ENC data available and encapi is unreachable.' end def self.enc_role - fetch_enc_data.fetch('classes', {}).keys.first || raise('ENC Role not found in Cobbler ENC response') + fetch_enc_data.fetch('classes', {}).keys.first || raise('ENC Role not found in encapi ENC response') end def self.enc_env - fetch_enc_data.fetch('environment', nil) || raise('ENC Environment not found in Cobbler ENC response') + fetch_enc_data.fetch('environment', nil) || raise('ENC Environment not found in encapi ENC response') end end Facter.add('enc_role') do - setcode { CobblerENC.enc_role } + setcode { EncapiENC.enc_role } end Facter.add('enc_env') do - setcode { CobblerENC.enc_env } + setcode { EncapiENC.enc_env } end