Ansible tries to evalue a comand line and fails by builds

Viewed 26

Trying to insert a line in the cfg file but seems to try to evaluate it instead and fails as in the example below:

- 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'}'''

Getting in the logs:

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
1 Answers

You can mark values as unsafe in Ansible in order to do this:

- 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'}"
Related