ansible wget then exec scripts => get_url equivalent
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 - name: Remove the zsh-installer.sh file: path=/tmp/zsh-installer.sh state=absent
@RaviTezu solution doesn't work because the file/script that you wish to execute must be on the machine where you execute your play/role.
As per the documentation here
The local script at path will be transferred to the remote node and then executed.
So one way to do it is by downloading the file locally and using a task like 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 are uploading your own script, the second method is more useful in your case because the script might gets updated in time so you are sure each time you execute it it uses the latest script.
Consider using the
get_url
oruri
module rather than runningcurl
.
For example:
- name: Download setup_8.x script get_url: url=https://deb.nodesource.com/setup_8.x dest=/opt mode=755- name: Setup Node.js command: /opt/setup_8.x- name: Install Node.js (JavaScript run-time environment) apt: name=nodejs state=present