shell module: Bash <(process substitution) with ansible

ansible, shell

Solution

EDIT: though this answers this the question I think mgsk's answer is a better answer since I agree that it's not the right way to go about it with Ansible.

This should fix your issue:

- name: install pip
  shell: "python <(curl https://bootstrap.pypa.io/get-pip.py)" executable=/bin/bash

If you are wondering the difference between these two commands:

python <(curl https://bootstrap.pypa.io/get-pip.py)
python <$(curl https://bootstrap.pypa.io/get-pip.py)

The first one uses process substitution which is a bash feature which is why you cannot use it with /bin/sh as your shell. What it's doing is taking the output of the curl command (which is a python script), writing it to a temporary file and using that file as an argument to python which takes a python script as its first argument.

The second one is an ambiguous redirect because the python script that is generated from the curl is not a file

Problem

I want to run a command: ``` - name: install pip shell: "python <(curl https://bootstrap.pypa.io/get-pip.py)" ``` But achieve an error ``` failed: [default] => {"changed": true, "cmd": "python <(curl https://bootstrap.pypa.io/get-pip.py)", "delta": "0:00:00.002073", "end": "2014-12-03 15:52:01.780837", "rc": 2, "start": "2014-12-03 15:52:01.778764", "warnings": []} stderr: /bin/sh: 1: Syntax error: "(" unexpected ``` I tried to change it to something like: ``` python <$(curl https://bootstrap.pypa.io/get-pip.py) ``` but it doesn't work. Any thoughts? NB: this question about using `<` operator in shell module and I know that better to use `apt` for install something

Original source