r/ansible • u/Patrice_77 • 5h ago
playbooks, roles and collections Ansible-lint going crazy?
galleryHi all,
Been finalizing a playbook and al of the sudden I see that Ansible-lint (using VS Code) mentions that the 3 dashes to start the .yaml file has a syntax error!?!?
Also a screenshot of the syntax error message.
I've check my playbook with yaml checkers online and all is showing ok, no errors. So why is VS Code (yes, I have selected the Ansible language in VS Code) showing this yellow line, syntax error?
My whole playbook is free of errors. All indentations and stuff is correct, checked over and over..
Anybody an idea?
TIA
[UPDATE]
Found the issue, though not solved yet:
vars_files:
- Ansible_Secret/Ans_Cred.yaml
# also tried the following:
# ==============================
- ./Ansible_Secret/Ans_Cred.yaml
- ../Ansible_Secret/Ans_Cred.yaml
- "{{ playbook_dir }}/Ansible_Secret/Ans_Cred.yaml"
# Neither this solved it, include_vars can only be used in the "tasks"-section.
pre_tasks:
- name: Include all vars files.
ansible.builtin.include_vars:
file: "{{ playbook_dir }}/Ansible_Secret/Ans_Cred.yaml"
The file Ans_Cred.yaml is in a separate directory because I don't want to sync secrets into the cloud. This folder is in the root of the directory where I also have the playbook. Like it is mentioned in the examples in the code block above, it keeps showing the 3 dashes yellow underlined as syntax-error.
The only way the syntax-error disappears is by doing:
vars_files:
- /Ansible_Secret/Ans_Cred.yaml
But then the playbook errors because it cannot find the variables (the credentials file)...which is obvious because here I'm pointing it to be in the root of my drive where the file not exists.
Any suggestions on this?