Search code examples
ansiblecontrollerfetchlocalhost

No such file or directory: Ansible controller cannot find file in own machine?


My playbook has a task that requires fetching of a file from a Windows Share drive. The play runs on localhost:

    - name: Fetch file
      fetch:
        src: \\10.14.2.130\shared\folder\Data\users.csv
        dest: /var/lib/awx/projects/Windowsfile/
        flat: yes
      delegate_to: 10.12.201.60
      become: yes
      become_method: runas
      become_user: SYSTEM

    - name: Initialise data list
      set_fact:
        data_list: []

    - name: Read input file
      read_csv:
        path: users.csv
        key: FirstName  
        fieldnames: FirstName,LastName,EmailAddress,Mobile
        delimiter: ','
      register: userdata

When I run the playbook in a terminal console, it managed to run successfully. But when I run it on ansible controller, it is giving this error:

TASK [Create_from_csv : Fetch file] ********************************************
changed: [localhost -> 10.12.201.60] => {"changed": true, "checksum": "ff94f775fdd699d9a5f9c9026ce187030cf4c4d5", "dest": "/var/lib/awx/projects/Windowsfile/users.csv", "md5sum": "a05583cd02cf2e06c8b51c7d7e2f5284", "remote_checksum": "ff94f775fdd699d9a5f9c9026ce187030cf4c4d5", "remote_md5sum": null}

TASK [Create_from_csv : Initialise data list] **********************************
ok: [localhost] => {"ansible_facts": {"data_list": []}, "changed": false}

TASK [Create_from_csv : Read input file] ***************************************
fatal: [localhost]: FAILED! => {"changed": false, "msg": "Unable to open file: [Errno 2] No such file or directory: 'users.csv'"}

Looks like ansible managed to fetch the file to its machine, yet it is unable to find it in its own directory.

Does anyone know how to resolve this issue?


Solution

  • Initially, I thought using gitlab to sync the project in ansible was causing the issue, but nope.

    All I had to do is to write the full path in the read_csv task:

    - name: Read input file
      read_csv:
        path: /var/lib/awx/projects/Windowsfile/users.csv
        key: FirstName  
        fieldnames: FirstName,LastName,EmailAddress,Mobile
        delimiter: ','
      register: userdata