Trying to use the line cookbook and it fails with errors

410 views Asked by At

Anyone used the Line cookbook --> https://supermarket.chef.io/cookbooks/line

I'm trying to add multiple lines to the rsyslog.conf file and using the line cookbook which was suggested earlier.

Contents of the recipe:

replace_or_add "New Lines" do
    path "/etc/rsyslog.conf"
    pattern "# ### end of the forwarding rule ###"
    line "#audit log\n$ModLoad imfile\n$InputFileName /var/log/audit/audit.log\n$InputFileTag tag_audit_log:\n$InputFileStateFile audit_log\n$InputFileSeverity info\n$InputFileFacility local6\n$InputRunFileMonitor\n*.*"
 end

It fails with

================================================================================ Error executing action edit on resource 'replace_or_add[New Lines]' ================================================================================

ArgumentError
-------------
Line #audit log
$ModLoad imfile
$InputFileName /var/log/audit/audit.log
$InputFileTag tag_audit_log:
$InputFileStateFile audit_log
$InputFileSeverity info
$InputFileFacility local6
$InputRunFileMonitor

 has embedded EOL characters, not allowed for this resource

I tried using the tr -d '\n' < yourfile.txt as mentioned in How do I remove newlines from a text file? but it still fails with the same error. but it still fails with the same eror.

Anyone tested the line cook book for adding multiple lines to a rsysconfig file or even adding multiple lines to a file using this cookbook??

Thank you, Anish

1

There are 1 answers

2
coderanger On

It's not the file, you have \n characters in your line value. One line at a time. Try poise-file instead probably.

EDIT:

Also, srsly don't do this, like I told you last time. Rsyslog supports things like $IncludeConfig /etc/rsyslog.d/ which allow pulling config in from multiple discrete files. Use that instead.