kubernetes.core icon indicating copy to clipboard operation
kubernetes.core copied to clipboard

kubernetes.core.helm_repository to be stateful

Open edgan opened this issue 2 years ago • 2 comments

SUMMARY

kubernetes.core.helm_repository, or a new function, should be stateful, as in state: present. Currently it installs a repository, but can't verify if it is already installed. If it is already installed it will just throw an error saying it is already installed.

ISSUE TYPE
  • Feature Idea
COMPONENT NAME

kubernetes.core.helm_repository

ADDITIONAL INFORMATION

Workaround code:

- name: "helm_repo_check_{{ nexus.helm.repo.name }}"
  changed_when: false
  shell:
    cmd: "helm repo list | grep {{ nexus.helm.repo.name }}"
- name: nexus_helm_repo
  kubernetes.core.helm_repository:
    name: "{{ nexus.helm.repo.name }}"
    repo_url: "nexus.helm.repo.url }}"
  when: helm_repo_nexus.rc == 1
`

edgan avatar Jun 16 '22 14:06 edgan

@edgan The module already supports this:

- hosts: localhost
  gather_facts: no
  tasks:
    - kubernetes.core.helm_repository:
        repo_url: https://charts.bitnami.com/bitnami
        name: bitnami

    - kubernetes.core.helm_repository:
        repo_url: https://charts.bitnami.com/bitnami
        name: bitnami
PLAY [localhost] ****************************************************************************************************************************

TASK [kubernetes.core.helm_repository] ******************************************************************************************************
changed: [localhost]

TASK [kubernetes.core.helm_repository] ******************************************************************************************************
ok: [localhost]

PLAY RECAP **********************************************************************************************************************************
localhost                  : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

Could you provide more information about what version of the collection and what version of ansible you are using? Also, could you provide the output from running the playbook using -vvv?

gravesm avatar Jun 16 '22 18:06 gravesm

I got here because I got the Repository already have a repository named $foo error, but it happened to me because I already had it listed with a different URL.

I can reproduce the exact error with:

- hosts: localhost
  gather_facts: no
  tasks:
    - kubernetes.core.helm_repository:
        repo_url: https://charts.bitnami.com/bitnami
        name: bitnami

    - kubernetes.core.helm_repository:
        repo_url: https://charts.bitnami.com/bitnami/ # note the trailing "/"
        name: bitnami
$ ansible-playbook ansible-helm-repo.yaml 
TASK [kubernetes.core.helm_repository] 
changed: [localhost]

TASK [kubernetes.core.helm_repository] 
fatal: [localhost]: FAILED! => {"changed": false, "msg": "Repository already have a repository named bitnami"}

Maybe this was issue for the original reporter as well?

Note that helm gives a different message, but still does not point out that the issue is the different URL. I know it should be obvious, but my brain sometimes goes on vacation. :)

$helm repo add bitnami https://charts.gitlab.io/
Error: repository name (bitnami) already exists, please specify a different name

em- avatar Nov 25 '22 10:11 em-