Oleksandr Lytvyn
09/09/2025, 3:00 PM---
version: 5
defaults:
datadir: hieradata
data_hash: yaml_data
hierarchy:
- name: "Per-node data"
path: "node/%{trusted.certname}.yaml"
- name: "OS major version-based data"
path: "os/%{facts.os.family}/version/%{facts.os.release.major}.yaml"
- name: "OS family-based data"
path: "os/%{facts.os.family}.yaml"
- name: "[ENCRYPTED] AWS Secrets Manager lookup - Dev"
lookup_key: hiera_aws_sm
options:
continue_if_not_found: false
aws_access_key: "%{lookup('hiera_aws_sm::dev::aws_access_key')}"
aws_secret_key: "%{lookup('hiera_aws_sm::dev::aws_secret_key')}"
region: us-east-1
delimiter: /
prefixes:
- puppet/dev/common/
confine_to_keys:
- '^dev_.*'
- name: "[ENCRYPTED] AWS Secrets Manager lookup - Prod"
lookup_key: hiera_aws_sm
options:
continue_if_not_found: false
aws_access_key: "%{lookup('hiera_aws_sm::prod::aws_access_key')}"
aws_secret_key: "%{lookup('hiera_aws_sm::prod::aws_secret_key')}"
region: us-east-1
delimiter: /
prefixes:
- puppet/prod/common/
confine_to_keys:
- '^prod_.*'
- name: "[ENCRYPTED] Global default data"
path: "defaults.eyaml"
lookup_key: eyaml_lookup_key
options:
pkcs7_private_key: /etc/puppetlabs/puppet/eyaml/private_key.pkcs7.pem
pkcs7_public_key: /etc/puppetlabs/puppet/eyaml/public_key.pkcs7.pem
- name: "Global default data"
path: "defaults.yaml"
What i did - i generated eyaml keys, encrypted aws secrets via eyaml and added encrypted values into "defaults.eyaml" and then in this file hiera.yaml "reference" those secrets.
But when i try to run "puppet agent -t" i get an error:
# puppet agent -tv --noop
Info: Using environment 'main'
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Loading facts
Notice: Requesting catalog from puppet.server.fqdn:8140 (X.X.X.X)
Notice: Catalog compiled by puppet.server.fqdn
Error: Could not retrieve catalog from remote server: Error 500 on SERVER: Server Error: Interpolation using method syntax is not allowed in this context (file: /etc/puppetlabs/code/environments/main/hiera.yaml) on node puppet.server.fqdn
Warning: Not using cache on failed catalog
Error: Could not retrieve catalog; skipping run
My goals:
1/ Store in git encrypted AWS credentials
2/ Populate/fill-out/put correct credentials into /etc/puppetlabs/code/environments/My_Environment/hiera.yaml
Could you please help my to understand how to fix contents of hiera.yaml file to make Puppet happy? 🙂csharpsteen
09/09/2025, 3:30 PMlookup() function cannot be used in hiera.yaml. lookup() returns values by traversing the entries defined in the hierarchy section of hiera.yaml.
So, allowing the use of lookup() within the hierarchy section would create a circular dependency.Oleksandr Lytvyn
09/09/2025, 3:30 PMOleksandr Lytvyn
09/09/2025, 3:31 PMcsharpsteen
09/09/2025, 3:39 PMREADME, it looks like plaintext, directly in the hiera.yaml is the only option the module authors provided.
I don't see a method for reading from Environment variables, or other sources.
Is the Puppet Server running in AWS?Oleksandr Lytvyn
09/09/2025, 3:39 PMIs the Puppet Server running in AWS?
No, in DC on-premcsharpsteen
09/09/2025, 3:40 PMcsharpsteen
09/09/2025, 3:44 PMhiera.yaml content with puppet as a break in that management tends to break catalog compilation for every node and you have to go in and manually fix it. Circular dependencies may work fine, but when they go bad, they go really bad.Oleksandr Lytvyn
09/09/2025, 4:19 PMcsharpsteen
09/09/2025, 4:20 PMOleksandr Lytvyn
09/10/2025, 9:15 AMaws_access_key and aws_secret_key in "hiera_aws_sm" so Ruby will try to use default workflow:
https://github.com/aws/aws-sdk-ruby/blob/version-3/gems/aws-sdk-secretsmanager/lib/aws-sdk-secretsmanager/client.rb#L127-L144
# When `:credentials` are not configured directly, the following locations will be searched for credentials:
#
# * `Aws.config[:credentials]`
#
# * The `:access_key_id`, `:secret_access_key`, `:session_token`, and
# `:account_id` options.
#
# * `ENV['AWS_ACCESS_KEY_ID']`, `ENV['AWS_SECRET_ACCESS_KEY']`,
# `ENV['AWS_SESSION_TOKEN']`, and `ENV['AWS_ACCOUNT_ID']`.
#
# * `~/.aws/credentials`
#
# * `~/.aws/config`
So i was wondering how can i pass/set/expose ENV variables "AWS_ACCESS_KEY_ID" and "AWS_SECRET_ACCESS_KEY" inside Puppet?
I did some initial googling and did some testing to add env variable in /etc/sysconfig/puppetserver
AWS_ACCESS_KEY_ID=111
AWS_SECRET_ACCESS_KEY=11111
(i'm not sure if it is supported to add ENV variable in this file in the forst place)
And tried to see if it will work, but it didn't worked (i checked by doing daemon reload / reexec and restating puppetserver systemd service and tried yo tun puppet agent -t to see if hiera backend will do lookup of secrets in AW Secrets Manager but it returned error:
Error: Could not retrieve catalog from remote server: Error 500 on SERVER: Server Error: Evaluation Error: Error while evaluating a Function Call, unable to sign request without credentials set (file: /etc/puppetlabs/code/environments/main/manifests/site.pp, line: 3, column: 18) on node XXX
(basically saying that https://forge.puppet.com/modules/accenture/hiera_aws_sm didn't get proper aws credentials to run)
Also i did like this:
/opt/puppetlabs/bin/puppetserver ruby -e 'puts ENV["AWS_ACCESS_KEY_ID"]' but it returned empty result. From what i understood it means that Puppetserver (or its JRuby?) does not see those ENV varialbesYury Bushmelev
09/10/2025, 10:06 AMcsharpsteen
09/10/2025, 2:37 PMpuppetserver files under /etc/default or /etc/sysconfig (Debian vs. RedHat).
SystemD config has the advantage that it only needs to be readable by init.Oleksandr Lytvyn
09/10/2025, 5:39 PMpuppetserver files under /etc/default or /etc/sysconfig (Debian vs. RedHat).
Thanks. i found out about it too late 🙂
In the end i forked repo https://github.com/Accenture/hiera-aws-sm and with help of AI/ChatGPT was able to adjust Ruby code in a way what works with AWS profiles and now i no longer need to hardcode secrets in hiera.yaml
- name: "[ENCRYPTED] AWS Secrets Manager lookup - Stage"
lookup_key: hiera_aws_sm
options:
continue_if_not_found: false
aws_profile: stage
region: us-east-1
delimiter: /
prefixes:
- puppet/stage/common/
confine_to_keys:
- '^stage_.*'
- name: "[ENCRYPTED] AWS Secrets Manager lookup - Prod"
lookup_key: hiera_aws_sm
options:
continue_if_not_found: false
aws_profile: prod
region: us-east-1
delimiter: /
prefixes:
- puppet/prod/common/
confine_to_keys:
- '^prod_.*'
(and in the process i found out that i can pass env variables via /etc/sysconfig/puppetserver to pass properly puppet systemd user home folder )
PS. Why i initially started working on ENV vars? Because colleague with more senior title said "it should work" and insisted on it. Turned out it was not right approach from the start. Learning experience for me to say "*No*" sometimes to other peoples opinions
Thank you everyone for assistance 👍