【问题标题】:Text block in yaml and escaping charactersyaml中的文本块和转义字符
【发布时间】:2015-10-31 17:11:31
【问题描述】:

我收到以下saltstack YAML 错误:

Rendering SLS 'openstack:openstack.horizon.CentOS' failed: could not found expected ':'; line 63

horizon_https:
  file.prepend:
    - text: |-
      <VirtualHost *:80>
      ServerName openstack.example.com    <======================
      <IfModule mod_rewrite.c>
      RewriteEngine On
      RewriteCond %{HTTPS} off
      RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
      </IfModule>

对于以下 YAML 位:

horizon_https:
  file.prepend:
    - text: |-
      <VirtualHost *:80>
      ServerName openstack.example.com
      <IfModule mod_rewrite.c>
      RewriteEngine On
      RewriteCond %{HTTPS} off
      RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
      </IfModule>
      <IfModule !mod_rewrite.c>
      RedirectPermanent / https://openstack.example.com
      </IfModule>
      </VirtualHost>
      <VirtualHost *:443>
      ServerName openstack.example.com

      SSLEngine On
      # Remember to replace certificates and keys with valid paths in your environment
      SSLCertificateFile /etc/apache2/SSL/openstack.example.com.crt
      SSLCACertificateFile /etc/apache2/SSL/openstack.example.com.crt
      SSLCertificateKeyFile /etc/apache2/SSL/openstack.example.com.key
      SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown

      # HTTP Strict Transport Security (HSTS) enforces that all communications
      # with a server go over SSL. This mitigates the threat from attacks such
      # as SSL-Strip which replaces links on the wire, stripping away https prefixes
      # and potentially allowing an attacker to view confidential information on the
      # wire
      Header add Strict-Transport-Security "max-age=15768000"

知道问题出在哪里吗?

【问题讨论】:

    标签: escaping special-characters yaml salt-stack


    【解决方案1】:

    text 是一个映射键,字符串&lt;VirtualHost *:80&gt;\nServername ... 是它的值。该值不能与键在同一级别缩进。

    所以你必须这样做:

    horizon_https:
      file.prepend:
        - text: |-
            <VirtualHost *:80>
            ServerName openstack.example.com
            <IfModule mod_rewrite.c>
            RewriteEngine On
            RewriteCond %{HTTPS} off
            RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
            </IfModule>
    

    错误消息抱怨无法找到的冒号是在所指示的行之前缺少的“:”。由于它在 text 映射键的同一级别缩进,因此它期望它包含一个键,后跟冒号+空格。

    (这并不能解决 could not found 错误消息的不合语法性,但至少应该摆脱它)

    【讨论】:

      猜你喜欢
      • 2011-08-28
      • 2016-01-04
      • 2022-10-05
      • 2014-03-05
      • 1970-01-01
      • 2015-01-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多