Itai Ganot
Itai Ganot

Reputation: 6305

Puppet/Ruby: How to use a ruby variable in a bash line?

I have a Nagios NRPE module in my Puppet environment.

In the nrpe.cfg template I've configured some if statements in order to set specific checks to specific hosts.

Example:

<% if @hostname =~ /rs\d+/ -%> 
command[check_smtp]=/usr/lib64/nagios/plugins/check_smtp -H rs01.company.com -p 25 -e rs01.company.com 
<% end -%> 

Meaning: If hostname starts with chars rs followed by a digit then apply the check commands in the if statement block.

I want change the check to something like this:

command[check_smtp]=/usr/lib64/nagios/plugins/check_smtp -H @hostname -p 25 -e @hostname

But the problem is that @hostname is a ruby variable and the check command is written in bash.

How can I achieve my goal?

Upvotes: 0

Views: 94

Answers (1)

iced
iced

Reputation: 1572

<% if @hostname =~ /rs\d+/ -%> 
command[check_smtp]=/usr/lib64/nagios/plugins/check_smtp -H <%= @hostname -%> -p 25 -e <%= @hostname -%>
<% end -%> 

Upvotes: 1

Related Questions