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

exec and Bash vars, false-postive "single quoted string containing a variable found on line" #113

Closed
andreashaerter opened this issue Jul 3, 2012 · 5 comments
Milestone

Comments

@andreashaerter
Copy link

puppet-lint detects Bash vars in single quoted strings and reports "single quoted string containing a variable found on line".

The following example shows the problem:

class foobar() {
  # wrong behavior
  # puppet-lint detects the Bash var ${FOOBAR} and reports
  # "ERROR: single quoted string containing a variable found on line"
  exec{ 'wrong single quoted string containing a variable':
    command   => 'set -e; set -u;
                  FOOBAR=\'this is a Bash var\';
                  echo "Bash: ${FOOBAR}";',
    path      => [ '/usr/local/bin', '/sbin', '/bin', '/usr/sbin', '/usr/bin' ],
    provider  => 'shell',
    logoutput => true,
  }
}

I don't know any Ruby nor the puppet-lint internals. And I see that the basic problem is: Bash uses the same variable syntax as Puppet. So searching for Puppet vars in exec command/onlyif/unless will find Bash vars.

Therefore the only quick idea I got to solve/soften this problem is to adjust the "single quoted string containing a variable found on line" error check:

  1. If a var in a single quoted string was found, check if the string belongs to an exec's command/onlyif/unless.
  2. If so, check if the found variable is defined in Puppet:
    • If so, report an ERROR
    • If not, report NO error (assuming it is a non-var var belonging to the exec command's shell code).

As puppet-lint is able to detect 'top-scope variable being used without an explicit namespace' there already seems to be some intelligence regarding Puppet vars in strings. Maybe a comparable procedure is able to solve the false-positive-bash-var errors.

@rharrison10
Copy link

I am also seeing this issue with the command parameter for cron resources.

@matthewianmorgan
Copy link

Unfortunately this isn't as simple as the description suggests.

A class that I have defined has a parameter that may take bash variables. So simply ignoring command, onlyif and unless statements won't do the complete job.

@stevenpost
Copy link

Since this issue is still open and a similar one was closed, I'll add my comments here, even though it is a rather old ticket.
The pull request in [1] changes this from an error to a warning.
Also it's not just exec statements where these occur.
I use the file_line type from stdlib to manage some variables in configuration files (which are actually bash scripts executed within init scripts), sometimes these will contain bash variables and thus need to be treated as literal strings. I imagine people managing their yum repo configs are also affected.

[1] #189

@xarses
Copy link
Contributor

xarses commented Nov 27, 2013

I created pull #234 changing @andreashaerter example around to use double quotes should work now

class foobar() {
  # wrong behavior
  # puppet-lint detects the Bash var ${FOOBAR} and reports
  # "ERROR: single quoted string containing a variable found on line"
  exec{ 'wrong single quoted string containing a variable':
    command   => "set -e; set -u;
                  FOOBAR=\'this is a Bash var\';
                  echo \"Bash: \${FOOBAR}\";",
    path      => [ '/usr/local/bin', '/sbin', '/bin', '/usr/sbin', '/usr/bin' ],
    provider  => 'shell',
    logoutput => true,
  }
}

@rodjek
Copy link
Owner

rodjek commented Jan 5, 2014

#234 has been merged into master, you will now be able to do what @xarses has suggested above.

@rodjek rodjek closed this as completed Jan 5, 2014
joshbetz added a commit to Automattic/vip-quickstart that referenced this issue Nov 6, 2014
Not really. It's a bash variable, but it looks like a Puppet
variable. We can still use double quotes and escape the $.

rodjek/puppet-lint#113

ERROR: single quoted string containing a variable found on line 3
alexmv pushed a commit to alexmv/puppet-lint that referenced this issue Jun 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants