2014-03-02 56 views
1

我有在Ansible以下劇本sudo的權限:複製與下ansible

--- 
- hosts: ESNodes 
    sudo: yes 
    tasks: 
    - name: Copy Elasticsearch 
    copy: src=~/elasticsearch-1.0.0.tar.gz dest=/opt/elasticsearch-1.0.0.tar.gz 
    - name: Untar Elasticsearch 
    action: shell cd /opt/ && tar xvfz elasticsearch-1.0.0.tar.gz 

當運行劇本如下:

bash-4.1$ ansible-playbook es_playbook.yml -K 
sudo password: 

PLAY [ESNodes] **************************************************************** 

GATHERING FACTS *************************************************************** 
ok: [isk-vsrv643] 

TASK: [Copy Elasticsearch] **************************************************** 
failed: [isk-vsrv643] => {"failed": true} 
msg: Could not replace file: /usr2/ihazan/.ansible/tmp/ansible-1393762341.08-257257560838959/source to /opt/elasticsearch-1.0.0.tar.gz: [Errno 13] Permission denied: '/usr2/ihazan/.ansible/tmp/ansible-1393762341.08-257257560838959/source' 

FATAL: all hosts have already failed -- aborting 

PLAY RECAP ******************************************************************** 
      to retry, use: --limit @/usr2/ihazan/es_playbook.retry 

isk-vsrv643    : ok=1 changed=0 unreachable=0 failed=1 

它失敗權限的問題。

在遠程主機上,我不能這樣做:

-bash-4.1$ cp elasticsearch-1.0.0.tar.gz /opt/ 
cp: cannot create regular file `/opt/elasticsearch-1.0.0.tar.gz': Permission denied 

但我可以做的:

-bash-4.1$ sudo cp elasticsearch-1.0.0.tar.gz /opt/ 

什麼我在劇本越來越錯了嗎?

提前

+0

你可以用-vvv運行劇本嗎? – leucos

回答

1

Ansible THX很可能甚至沒有登錄你缺少user指令:

--- 
- hosts: ESNodes 
    user: whatever_user_that_you_use_to_login_and_has_sudo_access 
    sudo: yes 

    tasks: 
    - name: Copy Elasticsearch 
    copy: src=~/elasticsearch-1.0.0.tar.gz dest=/opt/elasticsearch-1.0.0.tar.gz 
    - name: Untar Elasticsearch 
    action: shell cd /opt/ && tar xvfz elasticsearch-1.0.0.tar.gz 

希望它能幫助。

0

哈杉,可能是你缺少用戶進行須藤在目的地主機:如果你沒有在劇本聲明它,你需要添加額外的增值經銷商在ansible-劇本命令,例如:

ansible-playbook -i hosts playbook.yml --extra-vars "user=your_user" 

然後,ansible會使用目標主機中的「your_user」來運行任務。