shell vs command with uuidgen

I have written next task:

`

  • name: Generate uuidgen
    local_action: command uuidgen -r > {{ consul_files_dir }}/{{ datacenter }}/consul.uuidgen
    become: False
    run_once: True
    when: consul_uuidgen_file.stat.exists == False
    register: consul_uuidgen
    `

And I got the following error:

TASK [consul : Generate uuidgen] *********************************************** task path: /home/francisco/git/ansible/roles/consul/tasks/consul_keys.yml:13 fatal: [10.200.220.38 -> localhost]: FAILED! => {"changed": true, "cmd": "\"uuidgen -r > /home/francisco/git/ansible/roles/consul/files/eu-irl-aws/consul.uuidgen\"", "delta": "0:00:00.001540", "end": "2016-10-07 16:39:30.809033", "failed": true, "rc": 127, "start": "2016-10-07 16:39:30.807493", "stderr": "/bin/sh: 1: uuidgen -r > /home/francisco/git/ansible/roles/consul/files/eu-irl-aws/consul.uuidgen: not found", "stdout": "", "stdout_lines": [], "warnings": []}

Finally, I changed command module to shell module and it worked.

What is the reason?

Regards.
Francisco

If you use redirections or pipes, you use the shell module.
If it’s a plain command without shell constructs, then you use command.

HTH

Regards

You are right Ricardo!

Thanks.
Francisco