2016-01-25 31 views
1

我試圖將我的配置文件從ec2實例上的文件夾遷移到s3存儲桶。我們使用ansible來更新每次部署時對這些配置文件的更改,並且我遇到了無法與s3一起工作的問題。以下是將配置文件更新到ec2的舊版本。Ansible文件不存在S3但存在複製

- 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中描述的文件時沒有問題。

這裏是我的新配置文件更新到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 

正如你所看到的,我並沒有改變中,我引用文件本身的方式。但是,我現在每個文件都收到錯誤:

failed: [ip] => (item={'path': 'application.properties'}) => {"failed": true, "item": {"path": "application.properties"}} 
msg: Local object for PUT does not exist 

任何想法我可能會做錯什麼?或者有什麼建議可以解決這個問題?我正在使用animated-playbook 1.9.4。

+0

您是從Ansible主機還是從EC2實例將文件複製到S3? –

+0

@PasiH我從Ansible主機將文件複製到S3。 – cscan

回答

1

假設你想要的文件到S3從您的EC2實例複製並使用安裝配置文件任務的文件已經被複制到EC2實例,然後將文件駐留在/opt/company/config的EC2實例。然後

src屬性應改爲"/opt/company/config/{{item.path}}"和S3模塊調用如下:

- 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模塊。相應的任務是:

- 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 
+0

我的意圖是後者。前面加上local_action的s3命令會引發另一個錯誤: 失敗:[ip-> 127.0.0.1] =>(item = {'path':'application.properties'})=> {「failed」:true, 「item」:{「path」:「application.properties」},「parsed」:false} [sudo via ansible,key = key]密碼: – cscan

+0

看起來你正在用'sudo'運行劇本。嘗試在「安裝配置文件」任務中禁用'sudo'(答案已更新)。 –