S3 list result to file or variable

47 views
Skip to first unread message

ton...@gmail.com

unread,
Nov 7, 2018, 8:39:22 AM11/7/18
to Ansible Project
Hi. Im trying to automate our restore machine testing. 
At one point i need to connect to amason S3 and download the latest data from a bucket. 

s3://bucet.name/application_name/DATE/version/files1-3

What i have tried thus far:


- name: List s3 objects
      aws_s3:
        bucket: "bucket.name"
        prefix: "/application_name/"
        dest: /home/user/tmp-file
        mode: list
        max_keys: 5
      register: s3objects
      become: yes
      become_user: user    
    
    - name: show list?
      debug:
        msg: "heres the list: {{ s3objects.s3_keys }}"
    
    
    
    - name: write to file
      copy:
        content: "{{ s3objects }}"
        dest: /home/user/tmp-file
      with_items: s3objects.s3_keys  
      become: yes
      become_user: user

The tmp file has this info: 
"{"msg": "LIST operation complete", "failed": false, "changed": false, "s3_keys": []}"

Im very new to ansible, what i would ultimately want is to get this: 
aws s3 ls s3://bucet.name/application_name/ | tail -5

ton...@gmail.com

unread,
Nov 7, 2018, 8:57:20 AM11/7/18
to Ansible Project
hmm i see that i have one thing wrong. 
prefix is not what i thought it was. If i remove it i get the list for all the applications. 
 

ton...@gmail.com

unread,
Nov 7, 2018, 9:27:30 AM11/7/18
to Ansible Project
ANd if i enter prefix without / \   then i get the correct data. 
max_keys has no effect tho. 

Karl Auer

unread,
Nov 7, 2018, 4:06:05 PM11/7/18
to ansible-project
That must be irritating, since every example has leading slashes on the prefix!

Regards, K.


--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/3fab4bca-f77f-4f27-bca6-96c763621739%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Karl Auer

Email  : ka...@2pisoftware.com
Website: http://2pisoftware.com


GPG/PGP : 958A 2647 6C44 D376 3D63 86A5 FFB2 20BC 0257 5816
Previous: F0AB 6C70 A49D 1927 6E05 81E7 AD95 268F 2AB6 40EA

Reply all
Reply to author
Forward
0 new messages