0

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...

2
  • 1
    Ansible uses pyyaml for parsing, which will use libYAML if it's present, but includes it's own fallback parser that gets used if the system doesn't have libYAML. It sounds like either libYAML or the pyyaml fallback parser has an issue with tabs. Commented Dec 14, 2018 at 19:55
  • Thanks. Looks like all systems involved have PyYAML installed - 3.13 or 3.12...
    – Mikhail T.
    Commented Dec 14, 2018 at 20:16

1 Answer 1

0

Some IDEs or extensions may be reading or converting tabs to spaces, or spaces to tabs. Check the tab settings showing in the files for each user.

1
  • 1
    As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
    – Community Bot
    Commented Mar 28, 2023 at 15:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .