How to pipe commands using Ansible? e.g. curl -sL host.com | sudo bash -

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.


Consider using the get_url or uri module rather than running curl.

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

Tags:

Pipe

Ansible