问题
I'm trying to migrate my config files from a folder on an ec2 instance to an s3 bucket. We use ansible to update changes to these config files every deploy and I'm having issues getting ansible to work with s3. Here's the old ansible section for updating the config files to ec2.
- name: Install config files
copy: src="{{core_repo}}/config/{{item.path}}" dest=/opt/company/config owner=user group=user mode=0644 directory_mode=0755
with_items: config_files
tags:
- deploy
nothing crazy, just copy a bunch of files with certain permissions. Ansible's copy has no problem finding the files described in config_files.
Here's my new ansible section for updating the config files to s3.
- name: Install config files
s3: bucket=company-config object="/{{item.path}}" src="{{core_repo}}/config/{{item.path}}" mode=put aws_access_key=access aws_secret_key=secret
with_items: config_files
tags:
- deploy
As you can see, I haven't changed the way in which I reference the files themselves. However, I'm now receiving an error for each of these files:
failed: [ip] => (item={'path': 'application.properties'}) => {"failed": true, "item": {"path": "application.properties"}}
msg: Local object for PUT does not exist
Any idea what I might be doing wrong? Or any suggestions as to how I might fix this issue? I'm using ansible-playbook 1.9.4.
回答1:
Assuming you want to copy the files to S3 from your EC2 instance and the files have been copied to the EC2 instance using Install config files task, then the files reside in /opt/company/config
on the EC2 instance.
src
attribute should then be changed to "/opt/company/config/{{item.path}}"
and s3 module be called as follows:
- name: Install config files
s3: bucket=company-config object="/{{item.path}}" src="/opt/company/config/{{item.path}}" mode=put aws_access_key=access aws_secret_key=secret
with_items: config_files
tags:
- deploy
If you wanted to copy the files directly from your Ansible host to S3 then you'd call s3 module using local_action. The respective task is:
- name: Install config files
become: no
local_action: s3 bucket=company-config object="/{{item.path}}" src="{{core_repo}}/config/{{item.path}}" mode=put aws_access_key=access aws_secret_key=secret
with_items: config_files
tags:
- deploy
来源:https://stackoverflow.com/questions/35002282/ansible-file-doesnt-exist-for-s3-but-exists-for-copy