is it possible to write the shell command in one line ?
- shell: my command register: var run_once: true this work
- shell: "my command" register=var run_once=true this does not work
Shell is a one-to-one comparison to running the command yourself. From Ansible documentation:
The
shellmodule takes the command name followed by a list of space-delimited arguments.
So my_command register=var run_once=true would be correct if my_command runs that way when you run it in your local shell.
While you didn't ask about it, it's worth noting that it looks like you're trying to add parameters to the shell module that don't exist, so the first example you provided would have to use the args parameter:
- name: Execute my command in a remote shell shell: my_command args: register: var run_once: true Documented examples of shell are here