Yuvipanda has submitted this change and it was merged.

Change subject: Labs: Allow per-host Hiera overrides via wikitech
......................................................................


Labs: Allow per-host Hiera overrides via wikitech

Currently for Labs projects it is possible to override Hiera keys for
example at https://wikitech.wikimedia.org/wiki/Hiera:Tools for the
Tools project.  Unfortunately, these overrides are project-wide and
thus cannot be used to provide different data for only one host.

The existing logic in the mwyaml Hiera backend maps the hierarchy
defined in /etc/puppet/hiera.yaml:

| :hierarchy:
|   - "labs/%{::labsproject}/host/%{::hostname}"
|   - "labs/%{::labsproject}/common"
|   - "labs"
|   - "private/%{::labsproject}"
|   - common
|   - "private/common"

by ignoring entries not starting with "labs/" and mapping both the
remaining two ones to "Hiera:$labsproject".

This change maps the entries to their verbatim "Hiera:" counterparts,
except chopping off "/common",
i. e. "labs/%{::labsproject}/host/%{::hostname}" gets mapped to
"Hiera:$labsproject/host/$hostname" and "labs/%{::labsproject}/common"
to "Hiera:$labsproject".  It still ignores entries not starting with
"labs/".

Bug: T104202
Change-Id: I36cde8122d26301c6dcb61d0f16f06f7f9dd81d8
---
M modules/wmflib/lib/hiera/backend/mwyaml_backend.rb
1 file changed, 11 insertions(+), 6 deletions(-)

Approvals:
  Yuvipanda: Verified; Looks good to me, approved



diff --git a/modules/wmflib/lib/hiera/backend/mwyaml_backend.rb 
b/modules/wmflib/lib/hiera/backend/mwyaml_backend.rb
index 74384ca..216d5a3 100644
--- a/modules/wmflib/lib/hiera/backend/mwyaml_backend.rb
+++ b/modules/wmflib/lib/hiera/backend/mwyaml_backend.rb
@@ -11,13 +11,18 @@
         Hiera.debug("Looking up #{key}")
 
         Backend.datasources(scope, order_override) do |source|
-          # Small hack: - we don't want to search any datasource but the
+          # Small hack: We don't want to search any datasource but the
           # labs/%{::labsproject} hierarchy here; so we plainly exit
-          # in any other case
-          next unless source[0,5] == 'labs/'
-          source_arr = source.split('/')
-          next if source_arr[1].nil?
-          source = source_arr[1].capitalize
+          # in any other case.
+          next unless source.start_with?('labs/') and source.length > 
'labs/'.length
+
+          # For hieradata/, the hierarchy is defined as
+          # "labs/%{::labsproject}/host/%{::hostname}" and
+          # "labs/%{::labsproject}/common".  We map the former
+          # verbatim to "Hiera:$labsproject/host/$hostname", while the
+          # latter gets simplified to "Hiera:$labsproject".  In both
+          # cases, we capitalize $labsproject.
+          source = source['labs/'.length..-1].chomp('/common').capitalize
 
           data = @cache.read(source, Hash, {}) do |content|
             YAML.load(content)

-- 
To view, visit https://gerrit.wikimedia.org/r/233184
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I36cde8122d26301c6dcb61d0f16f06f7f9dd81d8
Gerrit-PatchSet: 2
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: Tim Landscheidt <[email protected]>
Gerrit-Reviewer: Giuseppe Lavagetto <[email protected]>
Gerrit-Reviewer: Merlijn van Deen <[email protected]>
Gerrit-Reviewer: Tim Landscheidt <[email protected]>
Gerrit-Reviewer: Yuvipanda <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to