Ansible 尝试评估命令行并因构建而失败

Ansible tries to evalue a comand line and fails by builds

尝试在 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'}'''

进入日志:

The error appears to be in '/var/lib/jenkins/workspace/eda-ami-builder/00_build/ami/eda/packer/ansible/roles/bootstrap/tasks/yum.yml': line 30, column 30, but may be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

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

您可以在 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'}"