2016-05-01 3 views
8

मैं हमेशा आश्चर्य "ansible रास्ता" का उपयोग निम्नलिखित shell कार्यों को बदलने के लिए अच्छा तरीका (get_url साथ, आदि) है क्या:ansible wget तो स्क्रिप्ट Exec => GET_URL बराबर

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

या

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

उत्तर

10

यह मेरे लिए काम किया:

- 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

मैं सोचता यह सही तरीका नहीं है, धन्यवाद;) – Oliboy50

+4

'स्क्रिप्ट' मॉड्यूल लक्ष्य की मेजबानी के लिए एक स्थानीय स्क्रिप्ट हस्तांतरित कर देता है, तो यह निष्पादित करता है। लक्ष्य होस्ट में 'get_url' डाउनलोड। इसलिए आपको 'खोल' या 'कमांड' की आवश्यकता है, न कि 'स्क्रिप्ट'। –

0

हो सकता है इस बुनियादी उदाहरण y मदद कर सकते हैं कहां शुरू करने के लिए:

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

@RaviTezu समाधान काम नहीं करता है, क्योंकि फ़ाइल/लिपि है कि आप पर अमल करना चाहते हैं मशीन जहाँ आप अपने प्ले/भूमिका को अंजाम पर होना चाहिए।

प्रलेखन here

पथ पर स्थानीय स्क्रिप्ट दूरस्थ नोड के लिए स्थानांतरित कर दिया जाएगा और उसके बाद मार डाला के अनुसार।

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

या आप यह कर सकते हैं:

- 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/ 

मैं के लिए जाना होगा

तो एक तरह से स्थानीय स्तर पर यह फ़ाइल डाउनलोड करने और नीचे की तरह एक काम का उपयोग करना है क्या करना पहली विधि यदि आप अपनी खुद की स्क्रिप्ट अपलोड कर रहे हैं, तो दूसरी विधि आपके मामले में अधिक उपयोगी है क्योंकि स्क्रिप्ट समय पर अपडेट हो सकती है, इसलिए आप सुनिश्चित करते हैं कि हर बार जब आप इसे निष्पादित करते हैं तो यह नवीनतम स्क्रिप्ट का उपयोग करता है।

0

नोट करें: "बल = हाँ", जो हमेशा पुराने को ओवरराइड करते हुए स्क्रिप्ट डाउनलोड करेगा। "change_when" भी ध्यान दें, जिसे आप अपने मामले के अनुसार परिष्कृत कर सकते हैं।

- 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

मेरे लिए, निम्न कथन काम किया:

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

प्रश्न यह था कि इससे कैसे बचें और जवाब के मूल मॉड्यूल का उपयोग करें, शेल नहीं। –

+0

यह सच है, धन्यवाद। –