【问题标题】:Trying to use the line cookbook and it fails with errors尝试使用 line cookbook 并失败并出现错误
【发布时间】:2019-01-23 20:00:19
【问题描述】:

任何人都使用过 Line 食谱 --> https://supermarket.chef.io/cookbooks/line

我正在尝试在 rsyslog.conf 文件中添加多行,并使用之前建议的 line cookbook。

食谱内容:

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

它失败了

================================================ ================================== 在资源 'replace_or_add[New Lines]' 上执行操作 edit 时出错 ==================================================== ===============================

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

我尝试使用How do I remove newlines from a text file? 中提到的 tr -d '\n'

有人测试了 line cook book 是否可以在 rsysconfig 文件中添加多行,甚至可以使用这本食谱在文件中添加多行??

谢谢你, 阿尼什

【问题讨论】:

    标签: ruby chef-infra chef-recipe chef-solo cookbook


    【解决方案1】:

    这不是文件,您的 line 值中有 \n 字符。一次一行。不妨试试poise-file。

    编辑:

    另外,请不要这样做,就像我上次告诉你的那样。 Rsyslog 支持$IncludeConfig /etc/rsyslog.d/ 之类的东西,它允许从多个离散文件中提取配置。改用那个。

    【讨论】:

    • 您能否详细说明“$IncludeConfig /etc/rsyslog.d/”我无法弄清楚如何从其他文件中包含配置,有没有我可以参考的示例跨度>
    • 打开您现有的rsyslog.conf 文件。默认情况下,它们中的大多数都有$IncludeConfig 行。因此,在这种情况下,您可以使用模板或文件资源将配置内容添加到/etc/rsyslog.d/whatever.conf,而不是编辑单个文件。简单得多:)
    猜你喜欢
    • 2018-03-31
    • 1970-01-01
    • 1970-01-01
    • 2012-09-24
    • 2018-02-24
    • 1970-01-01
    • 2015-09-19
    • 2017-12-21
    • 2018-03-17
    相关资源
    最近更新 更多