Red Cricket
Red Cricket

Reputation: 10470

Is Puppet Evaluating Variables in my YAML data?

I have this in a yaml file in my hiera data:

wsgi_keystone_conf_contents: |
 Listen 5000 
 Listen 35357

 <VirtualHost *:5000>
     WSGIDaemonProcess keystone-public processes=5 threads=1 user=keystone group=keystone display-name=%{GROUP}
     WSGIProcessGroup keystone-public
     WSGIScriptAlias / /var/www/cgi-bin/keystone/main
     WSGIApplicationGroup %{GLOBAL}
     WSGIPassAuthorization On
     LogLevel info 
     ErrorLogFormat "%{cu}t %M"
     ErrorLog /var/log/httpd/keystone-error.log
     CustomLog /var/log/httpd/keystone-access.log combined
 </VirtualHost>

 <VirtualHost *:35357>
     WSGIDaemonProcess keystone-admin processes=5 threads=1 user=keystone group=keystone display-name=%{GROUP}
     WSGIProcessGroup keystone-admin
     WSGIScriptAlias / /var/www/cgi-bin/keystone/admin
     WSGIApplicationGroup %{GLOBAL}
     WSGIPassAuthorization On
     LogLevel info 
     ErrorLogFormat "%{cu}t %M"
     ErrorLog /var/log/httpd/keystone-error.log
     CustomLog /var/log/httpd/keystone-access.log combined
 </VirtualHost>

And I try to create a my wsgi-keystone.conf file in my puppet manifest like so :

file { '/etc/httpd/conf.d/wsgi-keystone.conf':
    ensure   => present,
    content  => $wsgi_keystone_conf_contents,
}

But this results in a file that looks like this ...

Listen 5000
Listen 35357

<VirtualHost *:5000>
    WSGIDaemonProcess keystone-public processes=5 threads=1 user=keystone group=keystone display-name=
    WSGIProcessGroup keystone-public
    WSGIScriptAlias / /var/www/cgi-bin/keystone/main
    WSGIApplicationGroup
    WSGIPassAuthorization On
    LogLevel info
    ErrorLogFormat "t %M"
    ErrorLog /var/log/httpd/keystone-error.log
    CustomLog /var/log/httpd/keystone-access.log combined
</VirtualHost>

<VirtualHost *:35357>
    WSGIDaemonProcess keystone-admin processes=5 threads=1 user=keystone group=keystone display-name=
    WSGIProcessGroup keystone-admin
    WSGIScriptAlias / /var/www/cgi-bin/keystone/admin
    WSGIApplicationGroup
    WSGIPassAuthorization On
    LogLevel info
    ErrorLogFormat "t %M"
    ErrorLog /var/log/httpd/keystone-error.log
    CustomLog /var/log/httpd/keystone-access.log combined
</VirtualHost>

The above file has syntax error and httpd will not restart. How am I supposed to put data in my YAML file? Do I need to escape the %'s?

Upvotes: 1

Views: 306

Answers (1)

Dan Bowling
Dan Bowling

Reputation: 1225

Short answer, yes.

In Hiera, there are interpolation tokens:

Interpolation tokens look like %{variable} or %{function("input")}. That is, they consist of:

  • A percent sign (%)
  • An opening curly brace ({)

One of:

  • A variable name
  • A lookup function and its input (Hiera 1.3 and later)
  • A closing curly brace

If any setting in the config file or value in a data source contains an interpolation token, Hiera will replace the token with the value it refers to at run time.

That means that your %{GLOBAL} exactly matches an interpolation token. In your final output Puppet shows it has no value for the variable GLOBAL and it outputs blank.

There is a thread on escaping Hiera data on SO, but I don't think this is normally what you want to do. The best practice would be to write an erb template, and simply pass the values to the template you want to put in rather than the entire contents of the configuration file.

Upvotes: 1

Related Questions