Ansible syntax check fail in gitlab-ci

Hi,

I have a working playbook. It works on my machine, but also in CI. But running “ansible-playbook -i hosts.yml site.yml --syntax-check” in a gitlab-ci with a docker container (image: williamyeh/ansible:ubuntu16.04) doesn’t work.

Here is the message :
`
ERROR! Syntax Error while loading YAML.
found unknown escape character

The error appears to have been in ‘/builds/infra/ansibleplaybook/roles/ssh/tasks/harden_ssh.yml’: line 28, column 23, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

dest: /etc/ssh/sshd_config
regexp: “^HostKey /etc/ssh/ssh_host_ecdsa_key”
^ here
`

And the task :

`

  • name: Remove ecdsa
    lineinfile:
    dest: /etc/ssh/sshd_config
    regexp: “^HostKey /etc/ssh/ssh_host_ecdsa_key”
    state: absent
    notify: Restart ssh

`

In gitlab-ci I don’t do anything silly, here is the gitlab-ci.yml file :

`

stages:

  • test
  • update
  • run

image: williamyeh/ansible:ubuntu16.04

before_script:

setup ssh

  • ‘which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )’
  • eval $(ssh-agent -s)
  • echo “$ANSIBLE_SSH_PRIVATE_KEY” | tr -d ‘\r’ | ssh-add - > /dev/null
  • mkdir -p ~/.ssh
  • chmod 700 ~/.ssh
  • ‘[[ -f /.dockerenv ]] && echo -e “Host *\n\tStrictHostKeyChecking no\n\n” > ~/.ssh/config’

install depdencies

  • ‘ansible-galaxy install -r requirements.yml’

syntax check code:
stage: test
script:

  • bash -c “ansible-playbook -i hosts.yml site.yml --syntax-check”
    tags:
  • docker

install ssh key on server when merging to master

run global ssh playbook:
stage: run
script:

  • ‘ansible-playbook -i hosts.yml ssh.yml’
    only:
  • pushes
  • master
    except:
  • schedules
    tags:
  • docker

update server every night.

run update ansible playbook:
stage: update
script:

  • ‘ansible-playbook -i hosts.yml update.yml’
    only:
  • schedules
  • master
    tags:
  • docker

`

In advance thanks.