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

Reported Syntax error when using conditional facts["${facts['factname']}"] #154

Open
Cinderhaze opened this issue Sep 21, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@Cinderhaze
Copy link

Cinderhaze commented Sep 21, 2023

Describe the Bug

We are trying to use the value of a fact as a key for looking up another fact in a conditional. Inside the body of the conditional, we are trying to use the fact, and it is reporting as a syntax error, but it passes puppet parser validate

Initial example that caused it to fail

if $facts["file_${facts['some_custom_fact']}_yaml] {
  service: "${facts['some_custom_fact']}":
    ensure => running,
    enable => true
}

Error was on the line inside of the conditional where we were setting the service name.

I noticed that if I commented out the service line and made changes below it, I still got syntax errors on the commented line.

if $facts["file_${facts['some_custom_fact']}_yaml] {
  service: "$some_custom_fact}":
#  service: "${facts['some_custom_fact']}":
    ensure => running,
    enable => true
}

Expected Behavior

Given usage of using a facts[] lookup as part of a facts lookup is valid consistent with puppet parser validate

Steps to Reproduce

Steps to reproduce the behavior:

cat << 'EOF' > error.pp
if $facts["[]"] {
  #"${bar}"
}
EOF
puppet-lint error.pp

Environment

  • Version [2.5.2, 4.0.0(pdk)]

Additional Context

Minimal example that still signals syntax error seems to occur if there are square brackets in the conditional string. Note that the line that it fails on is the comment inside the

if $facts["[]"] {
  #"${bar}"
}

This leads me to believe that there is some error in parsing the 'key' in the facts map, that causes some kind of downstream problems.

We can workaround this by storing the fact in a local variable, and using the local variable for any references within our class.

@Cinderhaze Cinderhaze added the bug Something isn't working label Sep 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant