如何使用Ansible管道命令?e、 g.curl-sL host.com | sudo bash-
我想通过Ansible发出命令:如何使用Ansible管道命令?e、 g.curl-sL host.com | sudo bash-,ansible,pipe,Ansible,Pipe,我想通过Ansible发出命令: 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 ra
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]:失败!=>{“更改”: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“:”非零返回码“,”rc“:”2,“start“:”2017-12-27 15:11:55.435552“,”stderr“:”curl:option-:未知\ncurl:有关详细信息,请尝试“curl--help”或“curl--manual”,“stderr_行”:[“curl:option-:未知”,“curl:try'curl--help”或“curl--manual”了解更多信息“],“stdout:”,“stdout_行”:[]}
您可以:
- 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_模式运行的自我解释剧本
考虑使用or模块,而不是运行curl
例如:
- 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
如果只想删除警告消息,可以使用shell模块()并添加属性
args:
warn: no
shell属性命令,但这不是一个好的实践忽略警告,如果您考虑使用GETYURL模块(),例如,对于CITOS 7中的节点10安装,您可以使用:
- 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
对于其他版本或操作系统,您可以更改repo“https://rep.nodesource.com/setup_10.x“例如”https://deb.nodesource.com/setup_10.x“并且设置和安装命令符合SO。可能重复感谢您明确指出如何在shell模块中设置警告:
。博士对此并不清楚。