The Puppet Labs Issue Tracker has Moved: https://tickets.puppetlabs.com

Bug #11051

Unrecognised escape sequence '\`' in file (escaped backtick in manifest)

Added by Egon Kastelijn almost 3 years ago. Updated 9 months ago.

Status:InvestigatingStart date:11/28/2011
Priority:NormalDue date:
Assignee:-% Done:

0%

Category:-
Target version:-
Affected Puppet version: Branch:
Keywords:puppet escape sequence backtick

We've Moved!

Ticket tracking is now hosted in JIRA: https://tickets.puppetlabs.com

This ticket is now tracked at: https://tickets.puppetlabs.com/browse/PUP-1340


Description

We are developing MySQL recipes to make Puppet create and manage databases.

In order to create a MySQL database the database-name needs to be surrounded by backticks:

exec { "database-${dbname}":
  command => "/usr/bin/mysql -uroot -p${mysql_password} -e \"create database \`${dbname}\`;\"",
  unless  => "/usr/bin/mysql -uroot -p${mysql_password} -e \"show databases\" |/bin/grep ^${dbname}$",
  require =>  Class["mysql::server"],
} 

The catalogs runs fine, and the MySQL database is nicely created on the node.

The problem is that the PuppetMaster complains about an unrecognised escape sequence:

Sat Nov 26 07:22:54 +0100 2011 Puppet (warning): Unrecognised escape sequence '\`' in file /etc/puppet/prod/modules/mysql/manifests/database.pp at line 15

History

#1 Updated by Ken Barber almost 3 years ago

  • Description updated (diff)

#2 Updated by Ken Barber almost 3 years ago

  • Status changed from Unreviewed to Investigating

\` is going to throw an error like you say …

Why don’t you either:

  • Avoid escaping it
  • Or double escape it if you really need the backslash

    “\\‘”

#3 Updated by Egon Kastelijn almost 3 years ago

Hi Ken,

Thanks for your quick response!

We tried both of your solutions, but both don’t work.

The MySQL client really wants those backticks around identifiers (database-names, etc). And a double escape gives an ugly mysql-client error also.

IMHO I think that the best solution would be to allow/recognise the escaped backtick as a valid escape sequence. (or do you see another option?)

regards,

Egon

#4 Updated by Ken Barber almost 3 years ago

Hrm. Why are you surrounding the database in back-ticks anyway? Its not necessary for mysql ‘create database’.

#5 Updated by Egon Kastelijn almost 3 years ago

Hi Ken,

You are correct for 50% of the cases. ;)

If your database names do not contain any ‘–’ characters, then the backtick are not needed. But if they do, then the database is not created when you omit the backticks.

#6 Updated by Ken Barber almost 3 years ago

Okay – gotcha.

So interestingly, the double backslashes actually work for me:

$dbname = "foo-bar"

exec { "database-${dbname}":
  command => "/usr/bin/mysql -uroot -pmyrootpassword -e \"create database \\`${dbname}\\`;\"",
  unless  => "/usr/bin/mysql -uroot -pmyrootpassword -e \"show databases\" |/bin/grep ^${dbname}$",
  logoutput => on_failure,
} 

You say this returned some error?

Egon Kastelijn wrote:

Hi Ken,

You are correct for 50% of the cases. ;)

If your database names do not contain any ‘–’ characters, then the backtick are not needed. But if they do, then the database is not created when you omit the backticks.

#7 Updated by Nick Lewis almost 3 years ago

This looks like perfectly correct behavior to me. has no meaning to Puppet, and isn't an escape sequence (what would it mean? \ == \` ?) It’s inconvenient, but needing to escape the escape character is common. But in this case, couldn’t you do

command => "/usr/bin/mysql -uroot -p${mysql_password} -e 'create database `${dbname}`;'"

so that your backticks have no meaning to the shell? And then you don’t even need to escape those inner double quotes.

#8 Updated by Egon Kastelijn over 2 years ago

Hi,

Sorry for my late reply. We tested the work-around with the double back-slash before the backtick. –> It works! We don’t see the warnings in the Puppet log anymore, and the manifest works fine.

Thanks!

Egon

#9 Updated by Anonymous 9 months ago

Redmine Issue #11051 has been migrated to JIRA:

https://tickets.puppetlabs.com/browse/PUP-1340

Also available in: Atom PDF