ansible-collections / community.kubernetes

Kubernetes Collection for Ansible
https://galaxy.ansible.com/community/kubernetes
GNU General Public License v3.0
265 stars 104 forks source link

helm_repository add repo failed with auth #337

Closed PengBAI closed 3 years ago

PengBAI commented 3 years ago
SUMMARY

use module helm_repository to add helm repo

- name: Add default repository
  community.kubernetes.helm_repository:
    name: "{{ helm_repo_name }}"
    repo_url: "{{ helm_repo_url }}"
    repo_username: "{{ helm_repo_username }}"
    repo_password: "{{ helm_repo_password }}"

the first time of run playbook is OK. the second time is failed with

FAILED! => {"changed": false, "msg": "Repository already have a repository named xxxx"}
ISSUE TYPE
COMPONENT NAME
ANSIBLE VERSION
ansible 2.9.14
  config file = /home/vagrant/workspace/kazan-ansible/ansible.cfg
  configured module search path = [u'/home/vagrant/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/dist-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.18 (default, Aug  4 2020, 11:16:42) [GCC 9.3.0]
CONFIGURATION
DEFAULT_VAULT_PASSWORD_FILE(env: ANSIBLE_VAULT_PASSWORD_FILE) = xxxxx
MAX_FILE_SIZE_FOR_DIFF(env: ANSIBLE_MAX_DIFF_SIZE) = 360000
OS / ENVIRONMENT

DISTRIB_ID=Ubuntu DISTRIB_RELEASE=20.04 DISTRIB_CODENAME=focal DISTRIB_DESCRIPTION="Ubuntu 20.04.1 LTS"

STEPS TO REPRODUCE
  1. run playbook with auth: ex:
    - name: Add default repository
    community.kubernetes.helm_repository:
    name: "{{ helm_repo_name }}"
    repo_url: "{{ helm_repo_url }}"
    repo_username: "{{ helm_repo_username }}"
    repo_password: "{{ helm_repo_password }}"
  2. run a second time

<!--- HINT: You can paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
<!--- Describe what you expected to happen when running the steps above -->
from the second time, playbook pass with ok, no changed.

##### ACTUAL RESULTS
<!--- Describe what actually happened. If possible run with extra verbosity (-vvvv) -->

<!--- Paste verbatim command output between quotes -->
```paste below
FAILED! => {"changed": false, "msg": "Repository already have a repository named xxxx"}
Akasurde commented 3 years ago

@PengBAI Thanks for reporting this issue. Could you please provide helm repo list --output=yaml before and after?

PengBAI commented 3 years ago

@PengBAI Thanks for reporting this issue. Could you please provide helm repo list --output=yaml before and after?

first run from scratch:

repo list before:
    "stdout_lines": [
        "[]"
    ]
add repo:
    "stdout_lines": [
        "\"my-repo\" has been added to your repositories"
    ]
repo list after:
    "stdout_lines": [
        "- name: my-repo",
        "  url: https://xxxxxxxxxxxxxxxxxxxxxxxx"
    ]

second run the same playbook:

repo list before:
    "stdout_lines": [
        "- name: my-repo",
        "  url: https://xxxxxxxxxxxxxxxxxxxxxxxx"
    ]
add repo:
    "msg": "Repository already have a repository named my-repo"
PengBAI commented 3 years ago

if I run with command

helm repo add --username {{ helm_repo_username }} --password {{ helm_repo_password }} {{ helm_repo_name }} {{ helm_repo_url }}

it's OK, just skipping:

    "stdout_lines": [
        "\"my-repo\" already exists with the same configuration, skipping"
    ]

I'm using Helm 3 for information. So maybe a bug in some controls or checks in code

alinabuzachis commented 3 years ago

Hi @PengBAI, I would like to thank you for your quick replies. Could you kindly share the playbook you used? Also, I wanted to kindly ask you to ckeck whether both URLs of the repo (during the first and second execution of the playbook) are the same. Thank you.

PengBAI commented 3 years ago

hello all,

My bad... I set the variable as

helm_repo_url: " https://xxxxxxxxxxxxxxxx"
there is a leading space before https.

so https://github.com/ansible-collections/community.kubernetes/blob/221631c06a89dc1ff53140c57adbd8522259258c/plugins/modules/helm_repository.py#L219

It's a users' entry error, but maybe add a trim on repo_url is better. what do you think

alinabuzachis commented 3 years ago

Hello @PengBAI, no problem! I am closing the issue since the problem was in the playbook.