# Ansible syntax check fail in gitlab-ci

**URL:** <https://forum.ansible.com/t/ansible-syntax-check-fail-in-gitlab-ci/29633>\
**Category:** Ansible Project\
**Tags:** galaxy-ng\
**Created:** [February 6, 2019, 4:50pm UTC](https://forum.ansible.com/t/ansible-syntax-check-fail-in-gitlab-ci/29633 "2019-02-06T16:50:49Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Remi\_Desgrange](https://avatars.discourse-cdn.com/v4/letter/r/b2d939/32.png) [@Remi\_Desgrange](https://forum.ansible.com/u/Remi_Desgrange)\
**Post date:** [February 6, 2019, 4:50pm UTC](https://forum.ansible.com/t/ansible-syntax-check-fail-in-gitlab-ci/29633/1 "2019-02-06T16:50:49Z")

</div>

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.
