Ask Your Question

Conditional Hiera

asked 2013-11-07 01:55:35 -0500

kemra102 gravatar image

It is possible to set two hiera varaibales such as $customername & $rolename for a server in it's hiera yaml file such as:

role_name: webserver 
customer_name: myclient

and then have two other yaml files that represent these values such as:


These would have the classes and other hiera variables needed that are specific to that server role or customer respectively.

What I need to know is if it i possible to do say:

if $role_name=webserver & $customer_name=myclient {
    # do something that only affects web servers for that client

For example client specific ... (more)

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2013-11-08 09:00:41 -0500

Define your variables rolename and customername as facts on the client system. Facter picks up file yaml files in /etc/facter/facts.d. Just create a file there. You can use 'facter -p' to check the facts.

On your hiera.yaml on the master define your hierarchy based upone thise facts. Your second set woudl end up in hiera.yaml this way:

      - "roles/%{role_name}"
      - "customers/%{customer_name}
    - yaml
     :datadir: /some/path/to/a/dir

Setting specific for rolename and customername will be set in files with yaml extension, eg /some/path/to/a/dir ... (more)

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2013-11-07 01:55:35 -0500

Seen: 1,115 times

Last updated: Nov 08 '13