1

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

Anish
  • 21
  • 2
  • 6

1 Answers1

2

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.

coderanger
  • 52,400
  • 4
  • 52
  • 75
  • Could you please elaborate "$IncludeConfig /etc/rsyslog.d/ " I'm unable to figure it out on how to include config from other files, Is there an example i could refer tooo – Anish Aug 16 '18 at 19:48
  • Open up your existing `rsyslog.conf` file. Most of them have an `$IncludeConfig` line by default. So in this case rather than editing the single file, you would use a template or file resource to add your config content to `/etc/rsyslog.d/whatever.conf`. Much simpler :) – coderanger Aug 16 '18 at 20:27