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

src parameter doesn't work as expected when using the FQCN of the k8s module #341

Closed romogo17 closed 3 years ago

romogo17 commented 3 years ago
SUMMARY

When using the FQCN of the k8s module with the src parameter, the module fails to find or access the referenced file

An exception occurred during task execution. To see the full traceback, use -vvv. The error was: If you are using a module and expect the file to exist on the remote, see the remote_src option
fatal: [kube-instance-singlenode]: FAILED! => changed=false 
  msg: |-
    Could not find or access '/tmp/calico.yaml' on the Ansible Controller.
    If you are using a module and expect the file to exist on the remote, see the remote_src option
ISSUE TYPE
COMPONENT NAME

k8s

ANSIBLE VERSION
ansible 2.10.4
  config file = /Users/ro/Dev/kubernetes-fundamentals/ansible.cfg
  configured module search path = ['/Users/ro/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/Cellar/ansible/2.10.4/libexec/lib/python3.9/site-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 3.9.1 (default, Dec 28 2020, 11:24:06) [Clang 12.0.0 (clang-1200.0.32.28)]
CONFIGURATION
DEFAULT_LOAD_CALLBACK_PLUGINS(/Users/ro/Dev/k8s-lab/ansible.cfg) = True
DEFAULT_ROLES_PATH(/Users/ro/Dev/k8s-lab/ansible.cfg) = ['/Users/ro/Dev/k8s-lab/roles']
DEFAULT_STDOUT_CALLBACK(/Users/ro/Dev/k8s-lab/ansible.cfg) = yaml
HOST_KEY_CHECKING(/Users/ro/Dev/k8s-lab/ansible.cfg) = False
INVENTORY_ENABLED(/Users/ro/Dev/k8s-lab/ansible.cfg) = ['gcp_compute']
OS / ENVIRONMENT

Controller

Remote

STEPS TO REPRODUCE

To reproduce, use the module with the FQCN using the src parameter on a file in the remote host

- hosts: all
  tasks:
    - name: Download the calico manifest
      ansible.builtin.get_url:
        url: "https://docs.projectcalico.org/manifests/calico.yaml"
        dest: "/tmp"
    - name: Apply the calico manifests
      community.kubernetes.k8s:
        src: "/tmp/calico.yaml"
EXPECTED RESULTS
PLAY [all] ***********************************************************************************************************************************************************

TASK [Gathering Facts] ***********************************************************************************************************************************************
ok: [kube-instance-singlenode]

TASK [Download the calico manifest] **********************************************************************************************************************************
ok: [kube-instance-singlenode]

TASK [Apply the calico manifests] ************************************************************************************************************************************
changed: [kube-instance-singlenode]

PLAY RECAP ***********************************************************************************************************************************************************
kube-instance-singlenode   : ok=3    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

These results are obtained when using a playbook without the FQCN, such as

- hosts: all

  tasks:
    - name: Download the calico manifest
      ansible.builtin.get_url:
        url: "https://docs.projectcalico.org/manifests/calico.yaml"
        dest: "/tmp"
    - name: Apply the calico manifests
      k8s:
        src: "/tmp/calico.yaml"
ACTUAL RESULTS
PLAY [all] ***************************************************************************************************************

TASK [Gathering Facts] ***************************************************************************************************
ok: [kube-instance-singlenode]

TASK [Download the calico manifest] **************************************************************************************
ok: [kube-instance-singlenode]

TASK [Apply the calico manifests] ****************************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: If you are using a module and expect the file to exist on the remote, see the remote_src option
fatal: [kube-instance-singlenode]: FAILED! => changed=false 
  msg: |-
    Could not find or access '/tmp/calico.yaml' on the Ansible Controller.
    If you are using a module and expect the file to exist on the remote, see the remote_src option

PLAY RECAP ***************************************************************************************************************
kube-instance-singlenode   : ok=2    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   
tima commented 3 years ago

@romogo17 I think this may be a duplicate of #307 and #333. Could you verify what version of this collection you are using here?

romogo17 commented 3 years ago

Hi @tima, I'm currently using v1.1.1

# /usr/local/Cellar/ansible/2.10.4/libexec/lib/python3.9/site-packages/ansible_collections
Collection           Version
-------------------- -------
community.kubernetes 1.1.1 

After reading #307 (and #320) I tried to install the collection directly from the main branch.

TEST

I used the playbook I was having issues with, and it worked fine with and without the FQCN

- hosts: all
  tasks:
    - name: Download the calico manifest
      ansible.builtin.get_url:
        url: "https://docs.projectcalico.org/manifests/calico.yaml"
        dest: "/tmp"
    - name: Apply the calico manifests
      community.kubernetes.k8s:
        src: "/tmp/calico.yaml"
- hosts: all
  tasks:
    - name: Download the calico manifest
      ansible.builtin.get_url:
        url: "https://docs.projectcalico.org/manifests/calico.yaml"
        dest: "/tmp"
    - name: Apply the calico manifests
      k8s:
        src: "/tmp/calico.yaml"
RESULTS
TASK [Download the calico manifest] *************************************************************************************
ok: [kube-instance-singlenode]

TASK [Apply the calico manifests] ***************************************************************************************
changed: [kube-instance-singlenode]

PLAY RECAP **************************************************************************************************************
kube-instance-singlenode   : ok=3    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

Thank you for pointing me into the right direction!