2016-05-01 23 views
8

Mi chiedo sempre che cosa è il buon modo per sostituire i seguenti shell attività utilizzando la "via ansible" (con get_url, ecc):wget ansible poi exec script => GET_URL equivalente

- name: Install oh-my-zsh 
    shell: wget -qO - https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh | bash - 

o

- name: Install nodesource repo 
    shell: curl -sL https://deb.nodesource.com/setup_5.x | bash - 

risposta

10

questo ha funzionato per me:

- name: Download zsh installer 
    get_url: url=https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh dest=/tmp/zsh-installer.sh 

    - name: Execute the zsh-installer.sh 
    shell: /tmp/zsh-installer.sh 
+0

io pensa che sia la strada giusta, grazie;) – Oliboy50

+4

Il modulo 'script' trasferisce uno script locale per l'host di destinazione, quindi lo esegue. I download 'get_url' nell'host di destinazione. Quindi hai bisogno di 'shell' o 'comando', non 'script'. –

0

può essere questo esempio di base può aiutare y OU per iniziare:

--- 
- name: Installing Zsh and git 
    apt: pkg=zsh,git state=latest 
    register: installation 

- name: Backing up existing ~/.zshrc 
    shell: if [ -f ~/.zshrc ]; then mv ~/.zshrc{,.orig}; fi 
    when: installation|success 
    sudo: no 

- name: Cloning oh-my-zsh 
    git: 
    repo=https://github.com/robbyrussell/oh-my-zsh 
    dest=~/.oh-my-zsh 
    when: installation|success 
    register: cloning 
    sudo: no 

- name: Creating new ~/.zshrc 
    copy: 
    src=~/.oh-my-zsh/templates/zshrc.zsh-template 
    dest=~/.zshrc 
    when: cloning|success 
    sudo: no 
3

soluzione @RaviTezu non funziona perché il file/script che si desidera eseguire deve essere sulla macchina in cui si esegue il vostro gioco/ruolo.

Come per la documentazione here

Lo script locale nel percorso sarà trasferita al nodo remoto e quindi eseguito.

Quindi un modo per farlo è scaricando il file in locale e l'utilizzo di un compito come di seguito:

- name: execute the script.sh 
    script: /local/path/to/script.sh 

Oppure si può fare questo:

- name: download setup_5.x file to tmp dir 
    get_url: 
    url: https://deb.nodesource.com/setup_5.x 
    dest: /tmp/ 
    mode: 0755 

- name: execute setup_5.x script 
    shell: setup_5.x 
    args: 
    chdir: /tmp/ 

vorrei andare per la primo metodo se stai caricando il tuo script, il secondo metodo è più utile nel tuo caso perché lo script potrebbe essere aggiornato in tempo così sei sicuro che ogni volta che lo esegui userà l'ultimo script.

0

Nota: "force = yes", che scaricherà sempre lo script, sovrascrivendo quello vecchio. Nota anche "changed_when", che puoi perfezionare in base al tuo caso.

- name: 'Download {{ helm.install_script_url }}' 
    environment: 
     http_proxy: '{{proxy_env.http_proxy | default ("") }}' 
     https_proxy: '{{proxy_env.https_proxy | default ("") }}' 
     no_proxy: '{{proxy_env.no_proxy | default ("") }}' 
    get_url: url={{ helm.install_script_url | default ("") }} dest=/tmp/helm_install_script force=yes mode="0755" 
    when: helm.install_script_url is defined 
    tags: 
    - helm_x 

    - name: Run {{ helm.install_script_url }} 
    environment: 
     http_proxy: '{{proxy_env.http_proxy | default ("") }}' 
     https_proxy: '{{proxy_env.https_proxy | default ("") }}' 
     no_proxy: '{{proxy_env.no_proxy | default ("") }}' 
    command: "/tmp/helm_install_script" 
    register: command_result 
    changed_when: "'is up-to-date' not in command_result.stdout" 
    when: helm.install_script_url is defined 
    args: 
     chdir: /tmp/ 
    tags: 
    - helm_x 
1

Per me, la seguente dichiarazione lavorato:

- name: "Execute Script" 
    shell: curl -sL https://rpm.nodesource.com/setup_6.x | bash - 
+3

La domanda era come evitare ciò e utilizzare i moduli nativi Ansible, non la shell. –

+0

Questo è vero, grazie. –

Problemi correlati