Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OSP: literal function and braces #1175

Open
halfninja opened this issue Dec 3, 2024 · 4 comments
Open

OSP: literal function and braces #1175

halfninja opened this issue Dec 3, 2024 · 4 comments
Labels
triaged This ticket has been accepted to our backlog and migrated internally

Comments

@halfninja
Copy link

Describe the Change You Would Like

The documentation for the Hiera literal function says this:

This is useful when dealing with Apache config files, for example, which might include text such as %{SERVER_NAME}. For example:

server_name_string: "%{literal('%SERVER_NAME')}"

The latter example works fine - the issue is with "such as %{SERVER_NAME}". A reasonable reader would then expect to be able to do this:

server_name_string: "%{literal('%{SERVER_NAME}')}"

but it fails (tested in Hiera from Puppet 8.6.0):

Syntax error in string: %{literal('%{SERVER_NAME}')}

This may be as expected behaviour but in that case the documentation should demonstrate how to work around this, such as

server_name_string: "%{literal('%')}{SERVER_NAME}"
@joshcooper
Copy link
Contributor

Thanks @halfninja that makes sense. I'm going to transfer this to the puppet-docs repo to get that updated.

@joshcooper joshcooper transferred this issue from puppetlabs/puppet Dec 10, 2024
@joshcooper
Copy link
Contributor

How about:

- for example, which might include text such as `%{SERVER_NAME}`. For example:
+ for example, which might need to contain the string `%{SERVER_NAME}`. In order to accomplish this, you'll need to remove the braces and use the `literal` function, for example: 

And then have the code block follow:

server_name_string: "%{literal('%SERVER_NAME')}"

@halfninja
Copy link
Author

Suppose it depends if the target supports the form without braces. I guess httpd does but others might not.

I actually started using this for Logback config to output things like %mdc{trace_id} until I realised that this particular syntax doesn't trigger Hiera's interpolation and can be written as-is, I guess because the % and the { are separated.

@lisarobertson lisarobertson added the triaged This ticket has been accepted to our backlog and migrated internally label Dec 13, 2024
@lisarobertson lisarobertson changed the title literal function and braces OSP: literal function and braces Dec 13, 2024
Copy link

Migrated issue to PUPDOC-5705

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triaged This ticket has been accepted to our backlog and migrated internally
Projects
None yet
Development

No branches or pull requests

3 participants