【问题标题】:Ansible error when using in variable equal sign在变量等号中使用时出现 Ansible 错误
【发布时间】:2019-11-29 17:57:42
【问题描述】:

我有 ansible 角色。当启动 ansibple-playbook main.yml -C 得到这个错误:

ERROR! Syntax Error while loading YAML.
  found unknown escape character

The error appears to be in '/main': line 41, column 93, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

service          : "-XX:+UseG1GC -Xmx3584m -Xms3584m -Xmn896m -XX:MaxPermSize=512M -XX:SurvivorRatio=5 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.port=9090 -Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.authenticate=false -XX:MaxTenuringThreshold=10 -XX:InitialTenuringThreshold=10 -Xloggc:gclogs/gc.log -XX:+PrintGCDetails -XX:+PrintGCApplicationStoppedTime -XX:+PrintGCApplicationConcurrentTime -XX:+PrintGCDateStamps -XX:+PrintTenuringDistribution -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=2000k"
                                                                                            ^ here

There appears to be both 'k=v' shorthand syntax and YAML in this task. Only one syntax may be used.
This one looks easy to fix. It seems that there is a value started
with a quote, and the YAML parser is expecting to see the line ended
with the same kind of quote. For instance:

    when: "ok" in result.stdout

Could be written as:

   when: '"ok" in result.stdout'

Or equivalently:

   when: "'ok' in result.stdout"

在我们的 group_vars 文件夹中,我们使用如下变量:

service          : "-XX:+UseG1GC -Xmx3584m -Xms3584m -Xmn896m -XX:MaxPermSize=512M -XX:SurvivorRatio=5 -Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.port=9090 -Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.authenticate=false -XX:MaxTenuringThreshold=10 -XX:
InitialTenuringThreshold=10 -Xloggc:gclogs/gc.log -XX:+PrintGCDetails -XX:+PrintGCApplicationStoppedTime -XX:+PrintGCApplicationConcurrentTime -XX:+PrintGCDate
Stamps -XX:+PrintTenuringDistribution -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=2000k"

这是作为 systemd 单元启动的命令。 我哪里错了? 我认为等号错误,但我无法替换它。

【问题讨论】:

  • 嗨,谢尔盖,欢迎来到 SO。你的问题是无法回答的。请阅读帮助部分中的How to create an MCVE。然后编辑您的问题并为其他人提供必要的信息以帮助您(最小的剧本、需要时的清单、加载的变量、使用 -vvv 选项运行以查看错误......)。

标签: ansible


【解决方案1】:

这一定是格式或缩进有问题。下面的剧本按预期工作。

- hosts: localhost
  vars:
    svc: "-XX:+UseG1GC -Xmx3584m -Xms3584m -Xmn896m -XX:MaxPermSize=512M -XX:SurvivorRatio=5
          -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.port=9090
          -Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.authenticate=false
          -XX:MaxTenuringThreshold=10 -XX:InitialTenuringThreshold=10 -Xloggc:gclogs/gc.log
          -XX:+PrintGCDetails -XX:+PrintGCApplicationStoppedTime -XX:+PrintGCApplicationConcurrentTime
          -XX:+PrintGCDateStamps -XX:+PrintTenuringDistribution -XX:+UseGCLogFileRotation
          -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=2000k"
  tasks:
    - debug:
        var: svc

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-24
    • 2019-11-22
    相关资源
    最近更新 更多