-2

How can I make the last exec resource parse variables?

Currently it is coming out blank inside rc.local file as such:

[root@server1 ~]# cat /etc/rc.local
#!/bin/sh
/usr/sbin/balance -b 127.0.0.1 3306 :3306 ! :3306

Also for clarification, the "run-balance" exec resource produces the correct output with properly parsed variables and these are the same variables used in the following "add-rclocal" resource.

Class

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

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

}->

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

}->

exec { 'add-rclocal': 
  command => "echo '/usr/sbin/balance -b 127.0.0.1 3306 ${dbserver1}:3306 ! ${dbserver2}:3306' >> /etc/rc.local",

}

}
John Test
  • 89
  • 1
  • 3
  • 14

1 Answers1

2

The only solution I can come up with that would produce your results is if dbserver2 is being passed in as an empty string. It will be defined, but empty, so it won't assign the default. Sort of like:

class { 'balance':
  dbserver1 => 'dbhost1',
  dbserver2 => '',
}

You'll probably want to check your inputs. And maybe put something like this in to interrogate what those variables are being assigned as:

warning("Balance was passed servers ${dbserver1} and ${dbserver2}.") 

Which will emit the variables in the log-stream.

sysadmin1138
  • 133,124
  • 18
  • 176
  • 300