【问题标题】:Ansible tries to evalue a comand line and fails by buildsAnsible 尝试评估命令行并因构建而失败
【发布时间】:2020-07-10 11:19:12
【问题描述】:

尝试在 cfg 文件中插入一行,但似乎尝试对其进行评估,但失败,如下例所示:

- name: Set logging output
  lineinfile:
    dest: /etc/cloud/cloud.cfg.d/05_logging.cfg
    state: present
    regexp: '^output:'
    line: '''output:{all: '| tee -a /var/log/test.log'}'''

进入日志:

错误似乎在“/var/lib/jenkins/workspace/eda-ami-builder/00_build/ami/eda/packer/ansible/roles/bootstrap/tasks/yum.yml”中:第 30 行,列30,但可能 根据确切的语法问题,位于文件的其他位置。

违规行似乎是:

    regexp: '^output:'
    line: '''output:{all: '| tee -a /var/log/cloud-init-output.log'}'''
                             ^ here

【问题讨论】:

  • 您的报价不平衡。您期望的确切输出是什么?对于它的价值:''' 被解释为一个开头的单引号,后跟一个转义的单引号(即连续两个单引号)。恐怕您的意图是使用 python 三引号,这不是 yaml 的工作方式。

标签: ansible failed-installation


【解决方案1】:

您可以在 Ansible 中将值标记为 unsafe 以执行此操作:

- name: Set logging output
  lineinfile:
    dest: /etc/cloud/cloud.cfg.d/05_logging.cfg
    state: present
    regexp: '^output:'
    line: !unsafe "output:{all: '| tee -a /var/log/test.log'}"

【讨论】:

  • 刚刚测试过, !unsafe 确实解决了这个问题,只是你需要在输出之前关闭单个:',如下所示: - name: Set logging output lineinfile: dest: /etc/cloud/cloud. cfg.d/05_logging.cfg state: present regexp: '^output:' line: !unsafe "output:{all: '| tee -a /var/log/test.log'}" 使用我提出的解决方案05_logging.cfg 如下:'output:{all:'| tee -a /var/log/test.log'}' 我想改为: output:{all: '| tee -a /var/log/test.log'} 太好了,谢谢伙计!
  • 是的,在您的问题中使用三引号并没有真正说明您的意图,但现在它是。
猜你喜欢
  • 1970-01-01
  • 2018-03-11
  • 2019-09-20
  • 1970-01-01
  • 2016-10-18
  • 1970-01-01
  • 1970-01-01
  • 2015-08-26
  • 2023-03-22
相关资源
最近更新 更多