---
Introduction
The "load-failure" error is a common issue that can occur during the linting process of Ansible playbooks. This error is triggered when the linter fails to process a file, indicating a potential issue with the file's content. There are several reasons why this error may occur, and it's essential to understand them to troubleshoot effectively.
Possible Causes of load-failure:
1. Unsupported Encoding: Ansible only supports files with UTF-8 encoding. If a playbook contains a different encoding, the linter may fail to process it.
2. Not an Ansible File: If the file being processed is not a valid Ansible playbook or role file, it may result in a "load-failure" error. Ensure that the file follows the correct Ansible structure and format.
3. Unsupported Custom YAML Objects: If the playbook contains custom YAML objects with the prefix "!!", the linter may have difficulty parsing them. Avoid using unsupported YAML objects in your playbooks.
4. Vault Decryption Issue: In cases where the linter fails to decrypt an inline "!vault" block, it can trigger a "load-failure" error. This issue might be related to problems with the vault password or the encryption format.
Handling the load-failure Error:
The "load-failure" error is not skippable, meaning it cannot be added to the warn_list or skip_list to bypass linting. However, in situations where the error is related to vault decryption and cannot be avoided, you can add the offending file to the exclude_paths configuration. This will exclude the problematic file from the linting process, allowing the remaining files to be processed.
Spotting the Problem
Let's take a look at a problematic code snippet:
``yaml
---
- name: Example playbook
hosts: all
!! custom: true
`
Here, we encounter a playbook with a custom attribute in the code prefixed with !!.
Ansible Lint Output
`bash
WARNING Listing 1 violation(s) that are fatal
load-failure[runtimeerror]: Failed to load YAML file
load-failure.yml:1 while parsing a tag
in "<unicode string>", line 4, column 1
did not find expected tag URI
in "<unicode string>", line 4, column 3
Rule Violation Summary
count tag profile rule associated tags
1 load-failure[runtimeerror] min core, unskippable
Failed: 1 failure(s), 0 warning(s) on 1 files.
`
The Correct Order
Let's rectify the previous example to fix the load-failure error:
`yaml
---
- name: Example playbook
hosts: all
tasks:
- name: Display a message
ansible.builtin.debug:
msg: "Hello world!"
`
Possible Error Codes:
- load-failure[not-found]
: This code indicates that one or more files or folders specified as arguments were not found on disk. Ensure that the file paths in your playbook are correct and that the files exist.
- load-failure[runtimeerror]`: This code indicates that one or more files with syntax erro