2

This works:

  ansible host -a "echo hello"                # hello

But this returned a weird answer

  ansible host -a "echo hello && echo world"      # hello && echo world

Does ansible escape && and ; with ansible -a?

How can I excute it?

2 Answers 2

5

By default ansible CLI uses command module, which does not feed its arguments trough shell.

You want to use shell module instead:

ansible host -m shell -a 'echo hello && echo world'
Sign up to request clarification or add additional context in comments.

Comments

3

I remembered that ansible uses just ssh.

# not work
ansible host -a "echo hello && echo world"
# works
ansible host -a "bash -c 'echo hello && echo world'"

The command is excuted just through the ssh command.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.