hashim vayalar
hashim vayalar

Reputation: 313

s3 multiple files download using ansible

I tried to download multiple files from s3 bucket.

---
- name: s3
  hosts: localhost
  gather_facts: false
  tasks:
  - name: List bucket content
    aws_s3:
      bucket: ddd-ops1-linux-infra-repos-stage-31948338
      object: /incoming-manual/"{{ item }}"
      dest: /tmp/"{{ item }}"
      mode: get
    with_items:
      - TaniumClient-7.2.314.3518-1.rhe6.x86_64.rpm
      - TaniumClient-7.2.314.3518-1.rhe7.x86_64.rpm

When I use the loop I am getting below error

failed: [localhost] (item=TaniumClient-7.2.314.3518-1.rhe6.x86_64.rpm) => {"ansible_loop_var": "item", "changed": false, "item": "TaniumClient-7.2.314.3518-1.rhe6.x86_64.rpm", "msg": "Key incoming-manual/\"TaniumClient-7.2.314.3518-1.rhe6.x86_64.rpm\" does not exist."}
failed: [localhost] (item=TaniumClient-7.2.314.3518-1.rhe7.x86_64.rpm) => {"ansible_loop_var": "item", "changed": false, "item": "TaniumClient-7.2.314.3518-1.rhe7.x86_64.rpm", "msg": "Key incoming-manual/\"TaniumClient-7.2.314.3518-1.rhe7.x86_64.rpm\" does not exist."}

But If I mention the filename without loop, it works

---
- name: s3
  hosts: localhost
  gather_facts: false
  tasks:
  - name: List bucket content
    aws_s3:
      bucket: ddd-ops1-linux-infra-repos-stage-31948338
      object: /manual/TaniumClient-7.2.314.3518-1.rhe7.x86_64.rpm
      dest: /tmp/TaniumClient-7.2.314.3518-1.rhe7.x86_64.rpm
      mode: get

What am doing wrong here ? Is there any option to download multiple files from s3 bucket ?

Upvotes: 0

Views: 3813

Answers (1)

larsks
larsks

Reputation: 311988

You need to remove or relocate your quotes. As you can see from the error message, they are being interpreted as part of the filename. This would work:

---
- name: s3
  hosts: localhost
  gather_facts: false
  tasks:
  - name: List bucket content
    aws_s3:
      bucket: ddd-ops1-linux-infra-repos-stage-31948338
      object: "/incoming-manual/{{ item }}"
      dest: "/tmp/{{ item }}"
      mode: get
    with_items:
      - TaniumClient-7.2.314.3518-1.rhe6.x86_64.rpm
      - TaniumClient-7.2.314.3518-1.rhe7.x86_64.rpm

Upvotes: 2

Related Questions