2017-12-27 226 views
0

我想使通過Ansible命令:Ansible:curl -sL host.com | sudo的慶典 -

curl -sL https://deb.nodesource.com/setup | sudo bash - 

如何通過Ansible辦呢?現在我有:

- name: Add repository 
    command: curl -sL https://deb.nodesource.com/setup | sudo bash - 

但它拋出錯誤:

[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": []}

回答

3

您可以:

- name: Add repository 
    shell: curl -sL https://deb.nodesource.com/setup | sudo bash - 
    args: 
    warn: no 

shell允許管道,warn: no打壓警告。

但是,如果我是你,我會用apt_key + apt_repository Ansible模塊來創建自我解釋劇本,也支持check_mode運行。