PyratLabs / ansible-role-k3s

Ansible role for installing k3s as either a standalone server or HA cluster.
BSD 3-Clause "New" or "Revised" License
627 stars 135 forks source link

Bad indentation in registry configuration: registries.yaml with rewrite rules #197

Closed Jonaprince closed 1 year ago

Jonaprince commented 1 year ago

Summary

When adding rewrite rule into to add registry pull through cache the registries.yaml file created on k3s node indentation had bad indentation so rewrite rules is not used.

Issue Type

Controller Environment and Configuration

# Begin ANSIBLE VERSION
ansible [core 2.12.2]
  config file = /root/garage-installer/install-k3s/ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.8/site-packages/ansible
  ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.8.12 (default, Apr 21 2022, 07:55:08) [GCC 8.5.0 20210514 (Red Hat 8.5.0-10)]
  jinja version = 2.10.3
  libyaml = True
# End ANSIBLE VERSION

# Begin ANSIBLE CONFIG
DEFAULT_BECOME(/root/garage-installer/install-k3s/ansible.cfg) = True
DEFAULT_BECOME_METHOD(/root/garage-installer/install-k3s/ansible.cfg) = sudo
DEFAULT_ROLES_PATH(/root/garage-installer/install-k3s/ansible.cfg) = ['/root/garage-installer/install-k3s/roles']
HOST_KEY_CHECKING(/root/garage-installer/install-k3s/ansible.cfg) = False
# End ANSIBLE CONFIG

# Begin ANSIBLE ROLES
# /root/garage-installer/install-k3s/roles
- ansible-role-k3s, (unknown version)
# End ANSIBLE ROLES

# Begin PLAY HOSTS
["Node1"]
# End PLAY HOSTS

# Begin K3S ROLE CONFIG
## Node1
k3s_become: true
k3s_etcd_datastore: true
k3s_release_version: "v1.24.7+k3s1"
k3s_server: {"tls-san": ["apiserver.example.com"]}
k3s_registries: {"mirrors": {"docker.io": {"endpoint": ["http://example.com"], "rewrite": {"(.*)": "docker-hub/$1"}}}}
k3s_control_node: "true"
k3s_check_openrc_run: {"changed": false, "skipped": true, "skip_reason": "Conditional result was False"}
k3s_check_cgroup_option: {"changed": false, "stdout": "cpuset\t0\t308\t1", "stderr": "", "rc": 0, "cmd": ["grep", "-E", "^cpuset\\s+.*\\s+1$", "/proc/cgroups"], "start": "2022-11-14 10:07:55.773975", "end": "2022-11-14 10:07:55.776973", "delta": "0:00:00.002998", "msg": "", "stdout_lines": ["cpuset\t0\t308\t1"], "stderr_lines": [], "failed": false, "failed_when_result": false}

Steps to Reproduce

You can reproduce the issue adding this into your inventory:

k3s_registries:
  mirrors:
    docker.io:
      endpoint:
        - "http://registry.example.com"
      rewrite:
        "(.*)": "docker-hub/$1"

Expected Result

/etc/rancher/k3s/registries.yaml should contain:

mirrors:
  docker.io:
    endpoint:
    - http://registry.example.com
    rewrite:
      (.*): docker-hub/$1

Actual Result

Produced file contains 4 indentations instead of 2 in rewrite section.

mirrors:
  docker.io:
    endpoint:
    - http://registry.example.com
    rewrite:
        (.*): docker-hub/$1