S3不存在Ansible文件,但副本存在 [英] Ansible file doesn't exist for S3 but exists for copy
问题描述
我正在尝试将配置文件从ec2实例上的文件夹迁移到s3存储桶.我们使用ansible在每次部署时更新对这些配置文件的更改,而在使用s3时ansible遇到了问题.这是用于将配置文件更新到ec2的旧版本.
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
没什么疯狂的,只需复制一堆具有特定权限的文件即可. Ansible的副本可以毫无问题地找到config_files中描述的文件.
nothing crazy, just copy a bunch of files with certain permissions. Ansible's copy has no problem finding the files described in config_files.
这是我的新ansible部分,用于将配置文件更新为s3.
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
知道我可能做错了什么吗?或关于如何解决此问题的任何建议?我正在使用ansible-playbook 1.9.4.
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.
推荐答案
假定您要将文件从EC2实例复制到S3,并且已使用 Install config files 将文件复制到EC2实例. >任务,然后文件位于EC2实例上的/opt/company/config
中.
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
属性更改为"/opt/company/config/{{item.path}}"
,并按以下方式调用s3模块:
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
如果您想将文件直接从Ansible主机复制到S3,则可以使用local_action调用s3模块.各自的任务是:
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
这篇关于S3不存在Ansible文件,但副本存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!