Ansible wget, then exec scripts => get_url equivalent

I always wonder what is a good way to replace the following shell tasks using the โ€œcapable wayโ€ (using get_url , etc.):

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

or

 - name: Install nodesource repo shell: curl -sL https://deb.nodesource.com/setup_5.x | bash - 
+8
bash curl wget ansible ansible-playbook
source share
5 answers

This worked for 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 
+10
source share

@RaviTezu's solution does not work, because the file / script you want to execute must be located on the computer where you are executing your game / role.

According to the documentation here

The local script on the path will be passed to the remote node, and then executed.

Thus, one way to do this is to upload the file locally and use the task as shown below:

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

Or you can do this:

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

I would go for the first method if you load your own script, the second method is more useful in your case, because the script can be updated on time, so you are sure that every time you execute it, it uses the last script.

+3
source share

The following instruction worked for me:

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

Maybe this basic example can help you get started:

 --- - 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 
0
source share

Note: "force = yes", which will always load the script, overriding the old one. Also pay attention to "changed_when", which you can clarify in your case.

  - 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 
0
source share

All Articles