Ask Your Question

Custom Fact always adds new line at the end

asked 2015-05-29 01:14:59 -0500

DanielG gravatar image


I am trying to add a custom fact but when i use it in the module or template it always adds a new line.

Here is my fact definition:

    setcode do
      `host $HOSTNAME |awk -F " " '{print $3}' |sed -e 's/,//g'`

But always when i add this fact it adds a new line at the end for example:

notify { 'test_message':
message => "I am the service ip: $::service_ip"   

And the result:

    Notice: /Stage[main]/snmp/Notify[test_message]/message: current_value absent, should be I am the service ip:

I also tried to put it like that: (but the result was the same)

setcode do
        Facter::Core::Execution.exec(`host $HOSTNAME |awk -F " " '{print $3}' |sed -e 's/,//g'`)

I am not an expert in shell-scripts and the code is copied, so probaly there is the error. The command works on AIX and the result is the ip I need without any new line. I am using PE 3.8.0.

Thanks in advance for any help.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2015-05-29 02:53:47 -0500

The issue you're having is that the print command in awk tries to be helpful by inserting a newline for you. So I guess you could just use awk's printf command instead:

`host $HOSTNAME |awk -F " " '{printf $3}' |sed -e 's/,//g'`

That said, you should just use Ruby. :)

edit flag offensive delete link more


Thank you very much!

DanielG gravatar imageDanielG ( 2015-05-29 05:25:05 -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-05-29 01:14:59 -0500

Seen: 310 times

Last updated: May 29 '15