盐堆模式匹配失败

时间:2018-07-28 04:48:37

标签: salt-stack

我正在尝试使用无主盐替换Packer中httpd.conf中的一行。我总是使用grep命令检查模式,如果它可以工作,那么同样也可以在saltstack中工作,但是这次失败了。由于我的正则表达式不好,请对此提供帮助。

我要替换下面的行

CustomLog "|'/apps/CA/secure-proxy/bizportalsps/httpd/bin/rotatelogs' '/apps/CA/secure-proxy/bizportalsps/httpd/logs/access_log' 10M" common

CustomLog /apps/CA/secure-proxy/bizportalsps/httpd/logs/access_log common

所以我用

Log-file-update:
  file.replace:
    - name: /apps/CA/secure-proxy/bizportalsps/httpd/conf/httpd.conf
    - pattern: 'CustomLog \"\|'/apps/CA/secure-proxy/bizportalsps/httpd/bin/rotatelogs' '/apps/CA/secure-proxy/bizportalsps/httpd/logs/access_log' 10M\" common'
    - repl: 'CustomLog /apps/CA/secure-proxy/bizportalsps/httpd/logs/access_log common'
    - append_if_not_found: False

但是失败了。任何建议都会非常有帮助。

以下是错误。

<pre> <code>
amazon-ebs: [CRITICAL] Rendering SLS 'base:install' failed: while parsing a block mapping
    amazon-ebs:   in "<unicode string>", line 46, column 7:
    amazon-ebs:         - pattern: 'CustomLog \"\|'/apps/C ...
    amazon-ebs:           ^
    amazon-ebs: expected <block end>, but found '<scalar>'
    amazon-ebs:   in "<unicode string>", line 46, column 32:
    amazon-ebs:         - pattern: 'CustomLog \"\|'/apps/CA/secure-proxy/bizportals ...
    amazon-ebs:                                    ^

1 个答案:

答案 0 :(得分:1)

这是因为您的模式中的第一个'

这应该有效,

Log-file-update:
  file.replace:
    - name: /etc/pki/tls/certs/test
    - pattern: CustomLog \"|\'/apps/CA/secure-proxy/bizportalsps/httpd/bin/rotatelogs\' \'/apps/CA/secure-proxy/bizportalsps/httpd/logs/access_log\' 10M\" common
    - repl: CustomLog /apps/CA/secure-proxy/bizportalsps/httpd/logs/access_log common
    - append_if_not_found: False