ansible - 如何使用 Ansible 管道命令?例如curl -sL host.com |须藤重击 -

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

最佳答案

你可以:

- 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运行。

关于ansible - 如何使用 Ansible 管道命令?例如curl -sL host.com |须藤重击 -,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47994497/

相关文章:

ansible - 为什么我的 Ansible 任务挂起?

ansible - 如何在ansible playbook中只运行一项任务?

c++ - 父进程和子进程的切换发生在这里?

c - 多进程管道

c++ - 故障管道三个命令 "dmesg|sort|more"c++

linux - 简单的 shell 。混合管道和输出

amazon-ec2 - 可以使用 Ansible "serial"参数指定区域吗?

ansible - JMESpath 表达式按属性过滤对象并返回具有此属性集的对象名称列表

php - Laravel 无法连接到 dockerise 数据库

python - 如何正确关闭两个进程共享的管道?