1

My plan is to copy file from ec2 to s3 bucket using ansible, Here I've make playbook but getting some error:

copy2s3.yml

---
- name: Copy to s3
   s3:
     aws_access_key: "{{ lookup('env','aws_key') }}"
     aws_secret_key: "{{ lookup('env','aws_secret') }}"
     bucket: "{{ aws_packages_bucket }}"
     object: "/JI79IML/my_part_X86_64_c7.15.tar.gz"
     dest: "/data/parts/JI79IML/my_part_X86_64_c7.15.tar.gz"
     mode: get
     overwrite: no

Getting below error:

$ ansible-playbook copy2s3.yml -i 172.18.2.12,

 ERROR! 's3' is not a valid attribute for a Play

The error appears to have been in '/home/ubuntu/bk/copy2s3.yml': line 2, column 3, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

---
- name: Copy to s3
^ here
2

Module name (s3) should be at the same indentation level as the name:

- name: Copy to s3
  s3:
    aws_access_key: "{{ lookup('env','aws_key') }}"
    aws_secret_key: "{{ lookup('env','aws_secret') }}"
    bucket: "{{ aws_packages_bucket }}"
    object: "/JI79IML/my_part_X86_64_c7.15.tar.gz"
    dest: "/data/parts/JI79IML/my_part_X86_64_c7.15.tar.gz"
    mode: get
    overwrite: no
  • I use same but still getting same error, showing YAML syntax ok !, Is need to install s3 plugins in ansible? – Nullpointer Apr 4 '17 at 4:33
  • If syntax is ok, then, what other error are you getting? S3 module should be available by default. Also, try updating your Ansible and boto libraries: pip install -U ansible boto. – Marko Živanović Apr 4 '17 at 9:20
  • I resolve issue with above but need to write hosts, tasks, connection and gather_facts above on script then its works – Nullpointer Apr 4 '17 at 9:25
  • Yes, the above is just a single task, if you want to run it as a playbook, you'll need the parameters you described. – Marko Živanović Apr 4 '17 at 9:29
0

To Copy Object from Local Server to S3 using Ansible module, Use

mode: put

get will be used to download the object.

Reference

0

I had a similar issue when using aws_s3, the replacement module for s3.

Check to see if you have boto (for s3 and aws_s3) and boto3 (for aws_s3) correctly installed.

I had both boto & boto3 installed but, due to playing with virtual environments, they were only installed for Python3.5 and no other versions of python. Thus python (Python2.7 on my setup) that Ansible uses could not import the boto's and failed with this very esoteric error message.

To ensure that all is correctly installed is run python on the command line and try to import the boto's manually:

13:20 $ python
Python 2.7.12 (default, Nov 19 2016, 06:48:10) 
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import boto
>>> import boto3
>>> 
13:21 $ python3
Python 3.5.2 (default, Sep 14 2017, 22:51:06) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import boto
>>> import boto3
>>> 

If you receive an error in python then you get the error in Ansible.

0

Add task: above - name like this:

---
- hosts: localhost
  tasks:
    - name: Copy to s3
      s3:
          aws_access_key: "{{ lookup('env','aws_key') }}"
          aws_secret_key: "{{ lookup('env','aws_secret') }}"
          bucket: "{{ aws_packages_bucket }}"
          object: "/JI79IML/my_part_X86_64_c7.15.tar.gz"
          dest: "/data/parts/JI79IML/my_part_X86_64_c7.15.tar.gz"
          mode: put
          overwrite: no

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.