local_action results in a "failure encoding into utf-8"

I’m trying to run the openssl command via Ansible.

  • name: Generate a Production CSR
    local_action: /usr/bin/openssl req
    -new -newkey rsa:2048 -nodes
    -subj ‘{{ local_generate_prod_csr }}’
    -days 3650 -keyout STAR_{{ domain_name }}-privatekey.pem
    -out STAR_{{ domain_name }}.pem
    register: local_generate_prod_csr

Everything looks fine when I view the verbose output:

<127.0.0.1> EXEC [‘/bin/sh’, ‘-c’, ‘mkdir -p $HOME/.ansible/tmp/ansible-1384997601.86-108284890956864 && chmod a+rx $HOME/.ansible/tmp/ansible-1384997601.86-108284890956864 && echo $HOME/.ansible/tmp/ansible-1384997601.86-108284890956864’]
<127.0.0.1> EXEC [‘/bin/sh’, ‘-c’, ‘mkdir -p $HOME/.ansible/tmp/ansible-1384997601.86-123003779483972 && chmod a+rx $HOME/.ansible/tmp/ansible-1384997601.86-123003779483972 && echo $HOME/.ansible/tmp/ansible-1384997601.86-123003779483972’]
<127.0.0.1> REMOTE_MODULE /usr/bin/openssl req -new -newkey rsa:2048 -nodes -subj ‘/C=US/ST=California/L=Los Angeles/O=IT/CN=.selfishxmas.com’ -days 3650 -keyout STAR_selfishxmas.com-privatekey.pem -out STAR_selfishxmas.com.pem
<127.0.0.1> REMOTE_MODULE /usr/bin/openssl req -new -newkey rsa:2048 -nodes -subj '/C=US/ST=California/L=Los Angeles/O=IT/CN=
.selfishxmas.com’ -days 3650 -keyout STAR_selfishxmas.com-privatekey.pem -out STAR_selfishxmas.com.pem

but it results in:

fatal: [162.243.95.241] => failure encoding into utf-8
fatal: [162.243.67.77] => failure encoding into utf-8

If I take the command from the verbose output,

/usr/bin/openssl req -new -newkey rsa:2048 -nodes -subj ‘/C=US/ST=California/L=Los Angeles/O=IT/CN=*.selfishxmas.com’ -days 3650 -keyout STAR_selfishxmas.com-privatekey.pem -out STAR_selfishxmas.com.pem

And copy and paste it into the terminal window I get the standard output:

Generating a 2048 bit RSA private key
…+++
…+++
writing new private key to ‘STAR_selfishxmas.com-privatekey.pem’

Changing it from

local_action: /usr/bin/openssl

to

local_action: shell /usr/bin/openssl

fixed my problem. If this isn’t best practice I’d love to know! Thanks.

Looks like it is trying to look for /usr/bin/openssl as a module name and freaking out.

I think the error reporting should be better in this case, but it should still be some kind of error.

If you can file a ticket we can improve the error message I think.

Please open a ticket at github.com/ansible/ansible.

Thanks!