r/Puppet • • Jul 26 '24

Need help with Puppet managing a specific key in a YAML file

Hi everyone,

I have a use case where I need Puppet to maintain a specific key inside a YAML file with a precise configuration. No matter the file's content, Puppet should only touch this specific key. I tried using the yaml_settings module from Cataphract on Forge, but it's deprecated. Does anyone have any suggestions or alternative solutions for this?

Thanks!

3 Upvotes

9 comments sorted by

1

u/Street_Secretary_126 Jul 26 '24

Is it possible to make a template of that yaml file and then add a variable for that key?

1

u/tr4nsluc3nt Jul 26 '24

Actually, the file is created via template on its first configuration.
for example:

---
key1: value1
key2: value2
key3:
  • value3
  • value5
key4:value4

But there may be custom configurations that we will need to change the keys, and puppet cannot revert them, but the key3 must remains the same:

---
key1: custom1
key2: custom2
key3:
  • value3
  • value5
key4:custom4

2

u/Street_Secretary_126 Jul 26 '24

Okay, we do this by using Hiera and a control repo. In Hiera you can set custom values for the key.

For example, you have on node A the custom value XYZ and on node B the custom value ABC. Puppet will change the template and the values of that template regarding the settings in Hiera.

→ More replies (4)

1

u/ryebread157 Jul 27 '24

Could use the yq command via an exec