My original playbook and tasks that is meant to run on localhost:
- name: Fetch file
fetch:
src: \\10.14.2.130\shared\folder\Data\{{ filename }}
dest: /var/lib/awx/projects/Windows/
flat: yes
delegate_to: 10.12.201.60
become: yes
become_method: runas
become_user: SYSTEM
- name: Initialise data list
set_fact:
data_list: []
delegate_to: localhost
- name: Read input file
read_csv:
path: "{{ filename }}"
key: FirstName
fieldnames: FirstName,LastName,EmailAddress
delimiter: ','
register: userdata
delegate_to: localhost
- name: Extract the list
set_fact:
data_list: "{{ data_list + [{ 'FirstName': item.FirstName, 'LastName': item.LastName, 'EmailAddress': item.EmailAddress }] }}"
loop: "{{ userdata | community.general.json_query('dict.[*][0]') }}"
- name: Set fact for data_list
set_fact:
data_list: "{{ data_list[1:] }}"
As the first task failed and I am unable to fetch the csv file "{{ filename }}" into ansible machine, I amended some of the playbook's details, namely the 'delegate_to' and path of the CSV file in C drive, then ran the playbook on a Windows host:
- name: copy file
win_copy:
src: \\10.14.2.130\shared\folder\Data\{{ filename }}
dest: C:/
remote_src: true
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: C:\{{ filename }}
key: FirstName
fieldnames: FirstName,LastName,EmailAddress
delimiter: ','
register: userdata
delegate_to: 10.12.201.60
- name: Extract the list
set_fact:
data_list: "{{ data_list + [{ 'FirstName': item.FirstName, 'LastName': item.LastName, 'EmailAddress': item.EmailAddress }] }}"
loop: "{{ userdata | community.general.json_query('dict.[*][0]') }}"
- name: Set fact for data_list
set_fact:
data_list: "{{ data_list[1:] }}"
This is the error I get after running the playbook:
fatal: [10.12.201.60]: FAILED! => {
"msg": "The module read_csv was redirected to community.general.read_csv, which could not be loaded."
How can I run these set of tasks successfully on another remote server instead of localhost?
In a nutshell:
Note: there are other optimization/good practice to be applied while processing this data but I can't really guess without a proper example data and expected result. The goal was to answer your direct question