Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ansible : how to pass multiple commands

I tried this:

- command: ./configure chdir=/src/package/ - command: /usr/bin/make chdir=/src/package/ - command: /usr/bin/make install chdir=/src/package/ 

which works but I guess there is something more.. neat.

So I tried this:

from: https://stackoverflow.com/questions/24043561/multiple-commands-in-the-same-line-for-bruker-topspin which give me back "no such file or directory"

- command: ./configure;/usr/bin/make;/usr/bin/make install chdir=/src/package/ 

I tried this too: https://u.osu.edu/hasnan.1/2013/12/16/ansible-run-multiple-commands-using-command-module-and-with-items/

but I couldn't find the right syntax to put:

- command: "{{ item }}" chdir=/src/package/   with_items:       ./configure       /usr/bin/make       /usr/bin/make install 

That does not work, saying there is a quote issue.

Anyone?

like image 475
John Doe Avatar asked Jul 20 '14 14:07

John Doe


1 Answers

If a value in YAML begins with a curly brace ({), the YAML parser assumes that it is a dictionary. So, for cases like this where there is a (Jinja2) variable in the value, one of the following two strategies needs to be adopted to avoiding confusing the YAML parser:

Quote the whole command:

- command: "{{ item }} chdir=/src/package/"   with_items:   - ./configure   - /usr/bin/make   - /usr/bin/make install     

or change the order of the arguments:

- command: chdir=/src/package/ {{ item }}   with_items:   - ./configure   - /usr/bin/make   - /usr/bin/make install 

Thanks for @RamondelaFuente alternative suggestion.

like image 195
Pedro Romano Avatar answered Sep 24 '22 14:09

Pedro Romano