-
Notifications
You must be signed in to change notification settings - Fork 183
Add external facts of top scope vars #319
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| version: 5 | ||
| defaults: | ||
| datadir: modules/hieradata/data | ||
| hierarchy: | ||
| - name: Eyaml hierarchy | ||
| lookup_key: eyaml_lookup_key | ||
| paths: | ||
| - "nodes/%{trusted.certname}.yaml" | ||
| - "role/%{fact_role}-%{fact_env}.yaml" | ||
| - "role/%{fact_role}.yaml" | ||
| - "zone/%{fact_zone}.yaml" | ||
| - common.yaml | ||
| options: | ||
| pkcs7_private_key: /etc/puppetlabs/puppet/keys/private_key.pkcs7.pem | ||
| pkcs7_public_key: /etc/puppetlabs/puppet/keys/public_key.pkcs7.pem | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -11,33 +11,52 @@ | |||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| ### SETTING TOP SCOPE VARIABLES USED IN HIERA.YAML | ||||||||||||||||||||||||||||||||||||
| # The following lines are used to assign to top-scope variables (used in | ||||||||||||||||||||||||||||||||||||
| # hiera.yaml) the values of eventual trusted facts. | ||||||||||||||||||||||||||||||||||||
| # More info: https://docs.puppet.com/puppet/latest/reference/ssl_attributes_extensions.html | ||||||||||||||||||||||||||||||||||||
| # hiera.yaml) the values of eventual trusted facts or relevant Hiera keys | ||||||||||||||||||||||||||||||||||||
| # if a fact for them is not already set. | ||||||||||||||||||||||||||||||||||||
| # You may need to change and adapt them according to your hiera.yaml | ||||||||||||||||||||||||||||||||||||
| # You can keep them also if you don't set extended trusted facts. | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| if defined('$facts') and defined('$trusted') { | ||||||||||||||||||||||||||||||||||||
| if $trusted['extensions']['pp_role'] and ! getvar('facts.role') { | ||||||||||||||||||||||||||||||||||||
| $role = $trusted['extensions']['pp_role'] | ||||||||||||||||||||||||||||||||||||
| if ! getvar('facts.role') { | ||||||||||||||||||||||||||||||||||||
| $role = pick_default(getvar('trusted.extensions.pp_role'), lookup('role', Optional[String], 'first', undef)) | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| if $trusted['extensions']['pp_environment'] and ! getvar('facts.env') { | ||||||||||||||||||||||||||||||||||||
| $env = $trusted['extensions']['pp_environment'] | ||||||||||||||||||||||||||||||||||||
| if ! getvar('facts.env') { | ||||||||||||||||||||||||||||||||||||
| $env = pick_default(getvar('trusted.extensions.pp_environment'), lookup('env', Optional[String], 'first', undef)) | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| if $trusted['extensions']['pp_datacenter'] and ! getvar('facts.datacenter') { | ||||||||||||||||||||||||||||||||||||
| $datacenter = $trusted['extensions']['pp_datacenter'] | ||||||||||||||||||||||||||||||||||||
| if ! getvar('facts.datacenter') { | ||||||||||||||||||||||||||||||||||||
| $datacenter = pick_default(getvar('trusted.extensions.pp_datacenter'), lookup('datacenter', Optional[String], 'first', undef)) | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| if $trusted['extensions']['pp_zone'] and ! getvar('facts.zone') { | ||||||||||||||||||||||||||||||||||||
| $zone = $trusted['extensions']['pp_zone'] | ||||||||||||||||||||||||||||||||||||
| if ! getvar('facts.zone') { | ||||||||||||||||||||||||||||||||||||
| $zone = pick_default(getvar('trusted.extensions.pp_zone'), lookup('zone', Optional[String], 'first', undef)) | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| if $trusted['extensions']['pp_application'] and ! getvar('facts.application') { | ||||||||||||||||||||||||||||||||||||
| $application = $trusted['extensions']['pp_application'] | ||||||||||||||||||||||||||||||||||||
| if ! getvar('facts.application') { | ||||||||||||||||||||||||||||||||||||
| $application = pick_default(getvar('trusted.extensions.pp_application'), lookup('application', Optional[String], 'first', undef)) | ||||||||||||||||||||||||||||||||||||
|
Comment on lines
+20
to
+33
|
||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| # Note: with the above settings we allow overriding of our trusted facts by normal facts. | ||||||||||||||||||||||||||||||||||||
| # This is done here to adapt to different approaches, if you use trusted facts | ||||||||||||||||||||||||||||||||||||
| # you will probably want to change the above into something like: | ||||||||||||||||||||||||||||||||||||
| # if $trusted['extensions']['pp_role'] { | ||||||||||||||||||||||||||||||||||||
| # if getvar('trusted.extensions.pp_role') { | ||||||||||||||||||||||||||||||||||||
| # $role = $trusted['extensions']['pp_role'] | ||||||||||||||||||||||||||||||||||||
| # } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| # Creation of external facts with the values of the TopScope variables set here and used in hiera.yaml | ||||||||||||||||||||||||||||||||||||
| # Useful for custom hiera_pabawi.yaml file to allow Hiera resolution without catalog compilation (in Pabawi or HDM) | ||||||||||||||||||||||||||||||||||||
| psick::puppet::set_external_fact { 'fact_role': | ||||||||||||||||||||||||||||||||||||
| value => $role, | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| psick::puppet::set_external_fact { 'fact_env': | ||||||||||||||||||||||||||||||||||||
| value => $env, | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| psick::puppet::set_external_fact { 'fact_datacenter': | ||||||||||||||||||||||||||||||||||||
| value => $datacenter, | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| psick::puppet::set_external_fact { 'fact_zone': | ||||||||||||||||||||||||||||||||||||
| value => $zone, | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| psick::puppet::set_external_fact { 'fact_application': | ||||||||||||||||||||||||||||||||||||
| value => $application, | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
Comment on lines
+44
to
+58
|
||||||||||||||||||||||||||||||||||||
| psick::puppet::set_external_fact { 'fact_role': | |
| value => $role, | |
| } | |
| psick::puppet::set_external_fact { 'fact_env': | |
| value => $env, | |
| } | |
| psick::puppet::set_external_fact { 'fact_datacenter': | |
| value => $datacenter, | |
| } | |
| psick::puppet::set_external_fact { 'fact_zone': | |
| value => $zone, | |
| } | |
| psick::puppet::set_external_fact { 'fact_application': | |
| value => $application, | |
| } | |
| # Note: the helper defined type `psick::puppet::set_external_fact` is not available in this repository, | |
| # so the external fact creation resources have been disabled here to allow catalog compilation. |
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,2 @@ | ||||||||
| #!/bin/bash | ||||||||
| podman run --rm -v $(pwd):/repo --userns=keep-id puppet/puppet-dev-tools:4.x onceover "$@" | ||||||||
|
||||||||
| podman run --rm -v $(pwd):/repo --userns=keep-id puppet/puppet-dev-tools:4.x onceover "$@" | |
| set -euo pipefail | |
| podman run --rm -v "$(pwd)":/repo --userns=keep-id puppet/puppet-dev-tools:4.x onceover "$@" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The hierarchy paths use
%{fact_role},%{fact_env}, and%{fact_zone}interpolation, but this repo's existinghiera.yamluses explicit top-scope (%{::role}) and other dotted forms (%{trusted.certname}). To avoid relying on legacy fact-variable behavior (and to be consistent), prefer%{facts.fact_role}/%{facts.fact_env}/%{facts.fact_zone}(or%{::fact_role}etc.) so interpolation reliably resolves from facts.