2
votes

I am working on designing a puppet architecture for our company. I really like the idea of hiera and YAML files to classify my nodes. However, I would really like to be able to either apply YAML files that aren't based on facts or import YAML files into another YAML file.

For example NodeA.yaml

---
include webserver.yaml
include public.yaml

classes:
etc. . . 

This would allow me to reuse my code as much as possible. That way when I make a change to my web server configs, I only have to do it in one file instead of every node's YAML file.

I'm open to other solutions as well.

1
@kkamilpl has it right: the problem you say you want to address is best handled by proper definition and use of your hiera hierarchy. Indeed, in many respects that provides an externally-directed means of doing exactly what you propose, as it can cause hiera to consider multiple data files together, some more specific to the current node than others. You do not necessarily need custom facts to make it work, though it might be helpful to pair this with ENC-set global variables. - John Bollinger

1 Answers

3
votes
  • YAML does not support import or include
  • (not recomended) You can use loadyaml from stdlib module to achieve desired functionality. Check this example of using loadyaml function.
  • You can easily achieve expected functionality just by designing a proper hiera hierarchy. I do not understand why you do not want to use facter facts? e.g: on each node define custom facter fact location. Next define a hiera hierarchy:

    :hierarchy:
      - "%{::location}"/"%{::fqdn}"
      - "%{::location}"/common
      - common 
    

    Next in file location_1/node1.yaml you define data specific only for that node1. In file location_1/common.yaml you define data common for all nodes in location_1. In common.yaml you define data common for all nodes. If some data is common for all nodes you define it once in common.yaml and that's all. You do not have to redundantly define it in every node's yaml file.