yaml

Posts tagged with #yaml
Total: 3

yamllint error: "invalid config: ignore should contain file patterns"

Notes | 2023-01-12 (updated 2025-10-25) | 1 min read
#linting #yaml #yamllint

Setting up a new repository for YAML linting today I was running in a bit of an issue with yamllint.

I was using a YAML list to specify ingores, as mentioned in the documentation:

ignore:
  - "*.dont-lint-me.yaml"
  - "/bin/"
  - "!/bin/*.lint-me-anyway.yaml"

This however did not work with the above mentioned error message. After a lot of debugging I found that they released a new version recently which introduced this feature.

My solution was to update my locally build container image to the latest version, as of writing 1.29.0, in which this feature is introduced.

Read more…

yamllint: Ignore exisiting errors

Notes | 2022-01-14 (updated 2025-10-25) | 1 min read
#automation #cicd #yaml #yamllint

When adding yamllint to an existing project it can be hard to fix all the errors at once.

I wrote a simple script to create a rules block that simply ignores all rules that currently trigger for a file. This works by generating a rules block ignoring paths.

Read more…

Replace Line In YAML While Keeping Indentation Using Ansible

Notes | 2021-08-08 (updated 2025-10-25) | 1 min read
#ansible #yaml

In theory Ansible should be declarative and have full control over the systems we touch with it.

In practice, this is unfortunately not always the case.

This combination of tasks loads a given yaml file from the remote host, combines a “overwrite dict” onto it, and writes the file back to disk.

- name: Load yaml file contents as fact
  ansible.builtin.slurp:
    src: /etc/some-file.yaml
  register: yaml_file

- name: Parse yaml file contents
  ansible.builtin.set_fact:
    yaml_file_content: "{{ yaml_file.content | b64decode | from_yaml }}"

- name: Create the keys/values that should be overwritten
  ansible.builtin.set_fact:
    yaml_file_content_overwrite:
      some:
        key: "Overwrite value"
      another: "Also overwritten"

- name: Write yaml file with changed values
  ansible.builtin.copy:
    content: "{{ yaml_file_content | combine(yaml_file_content_overwrite, recursive=true) | to_yaml }}"
    dest: /etc/some-file.yaml
I like keeping my learning public. The below is my very old and naive solution I did based on regex.

With this nifty task we can replace the value of a key (given as yaml_key) to a new value (given as new_value) while preserving it’s indentation.

Read more…