0

I need to a run two ansible command in a single line. While am running the command its taking only the second command .

ansible -i list  cdlk -a "touch /tmp/a" -a "touch /tmp/b" --private-key=/tmp/id_rsa

I have create a file called list and after running this command only /tmp/b file is getting created .How I can run multiple commands in single line?

4
  • 1
    What's wrong with -a "touch /tmp/a; touch /tmp/b"? Commented Apr 30, 2019 at 6:44
  • its executing only second command that is "touch /tmp/b" ./tmp/a is not getting created. Commented Apr 30, 2019 at 7:02
  • Even with the change suggested above? Commented Apr 30, 2019 at 7:02
  • Yes. Its worked .Thank you Commented Apr 30, 2019 at 10:06

1 Answer 1

2

By default ansible CLI uses command module, which does not feed its arguments trough shell.change your parameter according to requirement.An example is shared below

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

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.