【问题标题】:augeas set value with whitespace failed带空格的 augeas 设置值失败
【发布时间】:2013-08-25 12:22:50
【问题描述】:


当我使用空格设置值(augeas-0.10.0 与 puppet-2.7.11 一起使用)时,我遇到了 augeas 问题,例如。

...
changes => "set *[self::directive='FastCgiExternalServer']/arg '/usr/lib/cgi-bin/php5-fcgi -socket /var/run/php5-fpm.sock -pass-header Authorization'", ...

保存后我收到此错误消息:


/augeas/files/etc/apache2/mods-available/fastcgi.conf/error = "put_failed"
/augeas/files/etc/apache2/mods-available/fastcgi.conf/error/path = "/files/etc/apache2/mods-available/fastcgi.conf/IfModule/directive"
/augeas/files/etc/apache2/mods-available/fastcgi.conf/error/lens = "/usr/share/augeas/lenses/dist/httpd.aug:76.18-77.49:"
/augeas/files/etc/apache2/mods-available/fastcgi.conf/error/message = "Failed to match \n    ({ /arg/ = /([^\001-\004\t\n \"']|\\\\\"|\\\\')+|\"([^\001-\004\n\"\\]|\\\\[^\001-\004\n])\"|'([^\001-\004\n'\\]|\\\\[^\001-\004\n])'/ }({ /arg/ = /([^\001-\004\t\n \"']|\\\\\"|\\\\')+|\"([^\001-\004\n\"\\]|\\\\[^\001-\004\n])\"|'([^\001-\004\n'\\]|\\\\[^\001-\004\n])'/ })*)?\n  with tree\n    { \"arg\" = \"/usr/lib/cgi-bin/php5-fcgi -socket /var/run/php5-fpm.sock -pass-header Authorization\" }"
我尝试了不同的方法来逃避这个值,但每次尝试都失败了,都出现了同样的错误。 我做错了什么?感谢您提供任何有用的答案!

【问题讨论】:

    标签: whitespace vagrant puppet augeas


    【解决方案1】:

    你有两个问题:

    • 您的更改可能会创建一个没有父 directive 节点的 arg 节点,这对于 Httpd.lns 镜头无效;
    • 您需要在值周围加上引号,因为它包含空格。

    所以(使用augtool):

    # Make sure the directive exists
    set directive[. = 'FastCgiExternalServer'] FastCgiExternalServer
    # Set the argument
    set directive[. = 'FastCgiExternalServer']/arg '"/usr/lib/cgi-bin/php5-fcgi -socket /var/run/php5-fpm.sock -pass-header Authorization"'
    

    应该会更好。

    【讨论】:

    • 是的,但是这个值/usr/lib/cgi-bin...,在fastcgi.conf中会出现双引号,格式不正确,apache重新加载后会失败。我有希望,这是任何方式插入它没有 qoutes 没有任何黑客......
    • 如果你不能有任何引号,那么每个部分都应该是一个单独的arg 节点。如果您认为这是错误的,您可以针对 Httpd.lns 镜头提交错误。
    • 是的,我认为这是一个错误。你的意思是 httpd.aug 文件在你的存储库中的 lens 目录中?
    • Httpd.lns 镜头在httpd.aug 文件(其中包含Httpd 模块)中进行了描述。您可以直接针对Httpd.lns 镜头进行报告,描述您的用例。
    【解决方案2】:

    “arg”实际上是一个列表。应该枚举每个参数:

    defvar conf /files/etc/apache2/sites-available/foo
    clear $conf/VirtualHost
    set $conf/VirtualHost/arg "172.16.0.1:80"
    set $conf/VirtualHost/directive "FastCgiExternalServer"
    set $conf/VirtualHost/*[self::directive='FastCgiExternalServer']/arg[0] "/usr/lib/cgi-bin/php5-fcgi"
    set $conf/VirtualHost/*[self::directive='FastCgiExternalServer']/arg[1] "-socket"
    set $conf/VirtualHost/*[self::directive='FastCgiExternalServer']/arg[2] "/var/run/php5-fpm.sock"
    set $conf/VirtualHost/*[self::directive='FastCgiExternalServer']/arg[3] "-pass-header"
    set $conf/VirtualHost/*[self::directive='FastCgiExternalServer']/arg[4] "Authorization"
    

    它产生以下文件:

    <VirtualHost 172.16.0.1:80>
    FastCgiExternalServer -socket /var/run/php5-fpm.sock -pass-header Authorization
    </VirtualHost>
    

    【讨论】:

      猜你喜欢
      • 2013-01-05
      • 2015-08-18
      • 1970-01-01
      • 2019-03-26
      • 2011-03-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多