Ask Your Question

variable parsing inside quotes

asked 2015-11-18 18:02:28 -0500

johntest gravatar image

updated 2015-11-19 09:18:44 -0500

Give the class below, how can I parse variables in the last exec resource?

UPDATE: I've tried a few things now including file_line from stdlib and nothing is properly working in this situation. I guess I have to ask the question if there is even a way to do this via puppet or not.

Currently it comes out blank as such:

/usr/sbin/balance -b 3306 :3306 ! :3306

The class is

class balance (
  $dbserver1 = 'server1',
  $dbserver2 = 'server2',


  package { 'balance':
    ensure => "installed",
  } ->

  exec { 'run-balance':
    command => "/usr/sbin/balance -b 3306 ${dbserver1}:3306 ! ${dbserver2}:3306",
    unless  => '/bin/ps afx | grep balance > /dev/null',
  } ->

  exec { 'add-rclocal':
    command => "echo '/usr/sbin/balance -b 3306 ${dbserver1}:3306 ! ${dbserver2}:3306' >> /etc/rc.local",
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2015-11-19 03:58:37 -0500

Cristian Falcas gravatar image

Escape the $ sign:

exec { 'add-rclocal':
    command => "echo '/usr/sbin/balance -b 3306 \${dbserver1}:3306 ! \${dbserver2}:3306' >> /etc/rc.local",
edit flag offensive delete link more


That gives me this in rc.local /usr/sbin/balance -b 3306 ${dbserver1}:3306 ! ${dbserver2}:3306 I would actually like to parse the variables. Is there a way to do this with augeas maybe? Just add a line.

johntest gravatar imagejohntest ( 2015-11-19 08:34:22 -0500 )edit

Just to be sure, so you want to get "echo '/usr/sbin/balance -b 3306 server1:3306 ! server2:3306' >> /etc/rc.local"? Then your code should work as it is, there is no error with it. Maybe you are overwritten $dbserver1 and $dbserver2 from somewhere?

Cristian Falcas gravatar imageCristian Falcas ( 2015-11-19 09:36:50 -0500 )edit

I want this to end up in the rc.local file '/usr/sbin/balance -b 3306 server1:3306 ! server2:3306' (without the first and last single quotes). this is not happening. I even just tried file_line from stdlib. What else can I try? Thanks!

johntest gravatar imagejohntest ( 2015-11-19 09:39:40 -0500 )edit

It's fixed. I had a small typo in the variable name argh! Thanks for your help!

johntest gravatar imagejohntest ( 2015-11-19 09:47:00 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2015-11-18 18:02:28 -0500

Seen: 66 times

Last updated: Nov 19 '15