Why do tabs in YAML work some but not at all times?

We’ve used tab-characters in some of YAML-files here:

host:   "foo"
port:   8011
p:      "bar"

For some reason, the same version of Ansible running the same playbook works just fine with these files for some users, but complains about “invalid characters” for others:

ERROR! Syntax Error while loading YAML.
  found character '\t' that cannot start any token

The error appears to have been in '.../playbooks/roles/native-package/defaults/main.yml': line 1, column
8, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:


tmpdir: >-
       ^ here
There appears to be a tab character at the start of the line.

YAML does not use tabs for formatting. Tabs should be replaced with spaces.

For example:
    - name: update tooling
      vars:
        version: 1.2.3
#    ^--- there is a tab there.

Should be written as:
    - name: update tooling
      vars:
        version: 1.2.3
# ^--- all spaces here.

I’m not asking, whether tabs are “better” than spaces — but I’d like to understand the inconsistency…

Answer

Attribution
Source : Link , Question Author : Mikhail T. , Answer Author : Community

Leave a Comment