Wednesday, August 16, 2017

False positive: ansible-lint reports [ANSIBLE0002] Trailing whitespace when there are none

The problem

When running ansible-lint on a Ansible role, it reported [ANSIBLE0002] Trailing whitespace on every line in one of my task files, like shown in the example below:


(vansible23)[audun@hostname my-role]$ ansible-lint .
[ANSIBLE0002] Trailing whitespace
/home/audun/git/my-role/tasks/main.yml:1
---

[ANSIBLE0002] Trailing whitespace
/home/audun/git/my-role/tasks/main.yml:2


[ANSIBLE0002] Trailing whitespace
/home/audun/git/my-role/tasks/main.yml:3
- debug: msg="Hello World"



The investigation

I had a suspicion there might be hidden characters in the file, but before running it through a HEX editor, I tried to check it with the Linux file command:


(vansible23)[audun@hostname my-role]$ file /home/audun/git/my-role/tasks/main.yml
/home/audun/git/my-role/tasks/main.yml: ASCII text, with CRLF line terminators



As shown above, it turned out that the file had CRLF line terminators on every line, indicating that this file had been created on Windows. That was luckily easy to fix.


The solution

The dos2unix command was used to change the file to Unix format:


(vansible23)[audun@hostname my-role]$ dos2unix /home/audun/git/my-role/tasks/main.yml
dos2unix: converting file /home/audun/git/my-role/tasks/main.yml to Unix format ...



Afterwards ansible-lint reported no issues:


(vansible23)[audun@hostname my-role]$ ansible-lint .

No comments:

Post a Comment