2014-04-08 17 views
24

Sto provando a wget un file da un server web all'interno di un playbook Ansible.Ansible e Wget

Ecco il frammento di Ansible:

--- 
- hosts: all 
    sudo: true 
    tasks: 
    - name: Prepare Install folder 
    sudo: true 
    action: shell sudo mkdir -p /tmp/my_install/mysql/ && cd /tmp/my_install/mysql/ 
    - name: Download MySql 
    sudo: true 
    action: shell sudo wget http://{{ repo_host }}/MySQL-5.6.15-1.el6.x86_64.rpm-bundle.tar 

Invocare tramite:

ansible-playbook my_3rparties.yml -l vsrv644 --extra-vars "repo_host=vsrv656" -K -f 10 

non riesce con il seguente:

Cannot write to `MySQL-5.6.15-1.el6.x86_64.rpm-bundle.tar' (Permission denied). 
FATAL: all hosts have already failed -- aborting 

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

vsrv644    : ok=2 changed=1 unreachable=0 failed=1 

Quando si cerca di fare il comando che non riescono via normale ssh remoto per imitare quello che farebbe l'ansible, non funziona come segue:

-bash-4.1$ ssh [email protected] 'cd /tmp/my_install/mysql && sudo wget http://vsrv656/MySQL-5.6.15-1.el6.x86_64.rpm-bundle.tar' 
Enter passphrase for key '/usr2/ihazan/.ssh/id_rsa': 
sudo: sorry, you must have a tty to run sudo 

Ma posso risolverlo usando -t come segue:

-bash-4.1$ ssh -t [email protected] 'cd /tmp/my_install/mysql && sudo wget http://vsrv656/MySQL-5.6.15-1.el6.x86_64.rpm-bundle.tar' 

allora funziona.

C'è un modo per impostare l'opzione -t (pseudo tty) su ansible?

P.S: Potrei risolverlo modificando il file sudoers come altri propongono, ma questo è un passaggio manuale che sto cercando di evitare.

risposta

53

Non utilizzare shell -module quando sono disponibili moduli specializzati. Nel tuo caso:

creare directory con file -module:

- name: create project directory {{ common.project_dir }} 
    file: state=directory path={{ common.project_dir }} 

Scaricare file con get_url -module:

- name: download sources 
    get_url: url={{ opencv.url }} dest={{ common.project_dir }}/{{ opencv.file }} 

nota la nuova sintassi chiamata modulo negli esempi precedenti.

Se è necessario utilizzare sudo con password, ricordare di fornire --ask-sudo-pass quando necessario (vedere ad esempio Remote Connection Information).

+0

Thx, questo è stato utile !!! –