Ansible: How to add variables to “command” or “shell”

Question:

Is it possible to use variables on command or shell modules?
I have the following code, and I would like to use variable file to provide some configurations:

I would like to read the Hadoop version from my variables file. On other modules of ansible I could use {{ansible_version}}, but with command or shell it doesn’t works.

I would like to convert to the following:

Because if I run the with this syntax it throws this error:

I have try using, but same problem:

What is the correct syntax?

Answer:

Quote the full string in the command argument:

Leave a Reply