I want to make the command via Ansible:
curl -sL https://deb.nodesource.com/setup | sudo bash -
How can I do it via Ansible? Now I have:
- name: Add repository
command: curl -sL https://deb.nodesource.com/setup | sudo bash -
But it throw error:
[WARNING]: Consider using get_url or uri module rather than running curl
fatal: [127.0.0.1]: FAILED! => {"changed": true, "cmd": ["curl", "-sL", "https://deb.nodesource.com/setup", "|", "sudo", "bash", "-"], "delta": "0:00:00.006202", "end": "2017-12-27 15:11:55.441754", "msg": "non-zero return code", "rc": 2, "start": "2017-12-27 15:11:55.435552", "stderr": "curl: option -: is unknown\ncurl: try 'curl --help' or 'curl --manual' for more information", "stderr_lines": ["curl: option -: is unknown", "curl: try 'curl --help' or 'curl --manual' for more information"], "stdout": "", "stdout_lines": []}
You can:
- name: Add repository
shell: curl -sL https://deb.nodesource.com/setup | sudo bash -
args:
warn: no
shell
to allow pipes, warn: no
to suppress warning.
But if I were you, I'd use apt_key
+ apt_repository
Ansible modules to create self explaining playbook that also support check_mode
runs.
If you only wants to remove the warning message, you can use shell module (https://docs.ansible.com/ansible/latest/modules/shell_module.html#examples) and add the property
args:
warn: no
Below of shell property command, but it's not a good practice ignore warnings, it's better if you consider use the get_url module (https://docs.ansible.com/ansible/latest/modules/get_url_module.html#examples), for example for a Node 10 installation in a Centos 7, you can use:
- name: Download NodeJs script
get_url:
url: https://rep.nodesource.com/setup_10.x
dest: /opt/nodesetup
mode: 0755
- name: Execute setup NodeJs script
shell: /opt/nodesetup
- name: Install NodeJs
yum:
name: nodejs
state: present
For others versions or OS, yo can change the repo "https://rep.nodesource.com/setup_10.x" for example for "https://deb.nodesource.com/setup_10.x" and the setup and install commands accord with the SO.
Consider using the
get_url
oruri
module rather than runningcurl
.
For example:
- name: Download Node.js setup script
get_url: url=https://deb.nodesource.com/setup dest=/opt mode=755
- name: Setup Node.js
command: /opt/setup
- name: Install Node.js (JavaScript run-time environment)
apt: name=nodejs state=present
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With