# Parsing csv file and running shell command

**URL:** <https://forum.ansible.com/t/parsing-csv-file-and-running-shell-command/37885>\
**Category:** Ansible Project\
**Created:** [April 14, 2023, 4:14am UTC](https://forum.ansible.com/t/parsing-csv-file-and-running-shell-command/37885 "2023-04-14T04:14:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andrew\_Morgan](https://avatars.discourse-cdn.com/v4/letter/a/50afbb/32.png) [@Andrew\_Morgan](https://forum.ansible.com/u/Andrew_Morgan)\
**Post date:** [April 14, 2023, 4:14am UTC](https://forum.ansible.com/t/parsing-csv-file-and-running-shell-command/37885/1 "2023-04-14T04:14:42Z")

</div>

Hello All,

I am trying to use ansible to read values from a csv file (source and destination) and then run commands using the shell module, but I am having no success. Please assist .

The playbook:

---

<div class="post-metadata">

**Author:** ![vbotka](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/vbotka/32/359_2.png) [@vbotka](https://forum.ansible.com/u/vbotka)\
**Post date:** [April 14, 2023, 6:23am UTC](https://forum.ansible.com/t/parsing-csv-file-and-running-shell-command/37885/2 "2023-04-14T06:23:42Z")

</div>

You're not running the \*aws\* command. You're testing the \*aws\* command  
with \*echo\*. Actually, this is a good idea to see the commands before  
you run them. Register the results and take a look at \*stdout\*.

In the module \*command\*, there is a couple of syntax problems  
in the run-string. To make the syntax both simpler and easier to read  
use the \*folded style\*. See  
[https://yaml.org/spec/1.2.2/#813-folded-style](https://yaml.org/spec/1.2.2/#813-folded-style)

The tasks below

&nbsp;&nbsp;&nbsp;&nbsp;- command: \>-  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;aws s3 cp  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{{ item.source }}  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{{ item.destination }}  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;--recursive --acl parameters --profile prod  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;loop: "{{ s3list.list }}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;register: out  
&nbsp;&nbsp;&nbsp;&nbsp;- debug:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;msg: "{{ out.results|map(attribute='stdout')|list }}"

should give you what you want

&nbsp;&nbsp;msg:  
&nbsp;&nbsp;- aws s3 cp S3://mybucket/puppy/test.jpg S3://mybucket2/trying/  
&nbsp;&nbsp;&nbsp;&nbsp;--recursive --acl parameters --profile prod  
&nbsp;&nbsp;- aws s3 cp S3://mybucket/puppy/ds.jpg S3://mybucket3/trying/  
&nbsp;&nbsp;&nbsp;&nbsp;--recursive --acl parameters --profile prod  
&nbsp;&nbsp;- aws s3 cp S3://mybucket/puppy/as.jpg S3://mybucket4/trying/  
&nbsp;&nbsp;&nbsp;&nbsp;--recursive --acl parameters --profile prod  
&nbsp;&nbsp;- aws s3 cp S3://mybucket/puppy/was.jpg S3://mybucket5/trying/  
&nbsp;&nbsp;&nbsp;&nbsp;--recursive --acl parameters --profile prod  
&nbsp;&nbsp;- aws s3 cp S3://mybucket/puppy/qaes.jpg S3://mybucket6/trying/  
&nbsp;&nbsp;&nbsp;&nbsp;--recursive --acl parameters --profile prod

If this is what you want remove \*echo\* and run the \*aws\* command with  
the option \*--dryrun\*

&nbsp;&nbsp;&nbsp;&nbsp;- command: \>-  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;aws s3 cp  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{{ item.source }}  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{{ item.destination }}  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;--dryrun --recursive --acl parameters --profile prod  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;loop: "{{ s3list.list }}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;register: out  
&nbsp;&nbsp;&nbsp;&nbsp;- debug:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var: out

If everything is alright copy the files

&nbsp;&nbsp;&nbsp;&nbsp;- command: \>-  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;aws s3 cp  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{{ item.source }}  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{{ item.destination }}  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;--recursive --acl parameters --profile prod  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;loop: "{{ s3list.list }}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;register: out  
&nbsp;&nbsp;&nbsp;&nbsp;- debug:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var: out

Notes:

\* You can remove the option \*--recursive\* as long as you copy single  
&nbsp;&nbsp;files  
\* You'll have to replace \*parameters\* with actual values. See  
&nbsp;&nbsp;[https://docs.aws.amazon.com/cli/latest/reference/s3/cp.html](https://docs.aws.amazon.com/cli/latest/reference/s3/cp.html)

---

<div class="post-metadata">

**Author:** ![Andrew\_Morgan](https://avatars.discourse-cdn.com/v4/letter/a/50afbb/32.png) [@Andrew\_Morgan](https://forum.ansible.com/u/Andrew_Morgan)\
**Post date:** [April 14, 2023, 8:02pm UTC](https://forum.ansible.com/t/parsing-csv-file-and-running-shell-command/37885/3 "2023-04-14T20:02:37Z")

</div>

Thank you every much, that worked, although I am not certain why echo with shell module wouldnt work , but thank you!
