augeas设置值与空格失败

时间:2013-08-25 12:22:50

标签: whitespace vagrant puppet augeas


当我用空白设置值(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\" }"
我尝试了不同的方法来逃避这个值,但每次尝试都失败了同样的错误。 我做错了什么?谢谢你的任何有用的答案!

2 个答案:

答案 0 :(得分:1)

您有两个问题:

  • 您的更改可能会创建一个没有父arg个节点的directive节点,该节点对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"'

应该更好。

答案 1 :(得分:0)

“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>