Quantcast
Channel: Ask Puppet: Puppet DevOps Q&A Community - RSS feed
Viewing all articles
Browse latest Browse all 6104

How to avoid wetness in class inheritance?

$
0
0
Here is a contrived boiled down example analogous to a real more complex problem I am trying to solve. I want to use class inheritance to create a new role I have. On one node I set a fact `role=role_base` and on second node I set the role fact to `role=role_a`. Then in my hiera.yaml I make use of the role fact like so: `- %{role}` in my hierarchy. My hiera.yaml looks like this: --- :backends: - yaml :yaml: :datadir: /etc/puppetlabs/puppet/hieradata :hierarchy: - common - "%{role}" Here is my base role: class role_base ( $files_hash, ) { create_resources(file,$files_hash) } Here is its hieradata, role_base.yaml: --- role_base::files_hash: '/tmp/base_role_1.txt': ensure: file content: 'this is base role 1' '/tmp/base_role_2.txt': ensure: file content: 'this is base role 2' Here is a class that is inherits from role_base: class role_a ( $files_hash, ) inherits role_base { create_resources(file,$files_hash) } and its hieradata, role_a.yaml: --- role_base::files_hash: '/tmp/base_role_1.txt': ensure: file content: 'this is base role 1' '/tmp/base_role_2.txt': ensure: file content: 'this is base role 2' role_a::files_hash: '/tmp/base_a_1.txt': ensure: file content: 'this is a role 1' '/tmp/base_a_2.txt': ensure: file content: 'this is a role 2' I would like to avoid having to repeat the parameters for `role_base` in `role_a`'s hieradata, but I cannot figure out how to do that. Is there a way to do what I am trying to do? Or is this a sign that I need to take another approach all together?

Viewing all articles
Browse latest Browse all 6104

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>