<p>Ansible <code>command</code> module requires only one command and cannot be changed. You should use the <code>shell</code> module at the very least. Note however that this will break the idempotency of the playbook.</p>

<p>You should probably split the task up into three:</p>

<ul>
<li>configure task using the <code>shell</code> module. Use <code>creates:</code> to tell the task to be skipped if the configure task has already created the expected output file</li>
<li>make task, using <a href="https://docs.ansible.com/ansible/latest/modules/make_module.html#make-module" rel="noreferrer">the Ansible Make module</a></li>
<li>similarly for the make install task.</li>
</ul>

<p>This should yield the same actual result, but would be more likely to be idempotent.</p>

CC BY-SA 4.0
2019-11-21T15:04:00.693Z
How exactly would I specify the make and the make install tasks. I do know about the `make` keyword, but all my previous attempts didn't work correctly.
Kyu96
CC BY-SA 4.0
2019-11-21T15:05:30.937Z
did you use the `target` parameter of the module? by setting the target parameter (ie target=install) you could run the make install.
Bruce Becker
CC BY-SA 4.0
2019-11-21T15:02:12.263Z
2019-11-21T15:02:12.263Z
Bruce Becker
<p>I just figured it out.
Splitting it up into more commands worked perfectly</p>

<pre><code>  - name: doit
    command: chdir=/tmp/proftpd/ ./configure

  - name: a shit here we go again
    command: chdir=/tmp/proftpd/ make

  - name: another one
    command: chdir=/tmp/proftpd/ sudo make install
</code></pre>

CC BY-SA 4.0
2019-11-21T15:01:14.880Z
2019-11-21T15:01:14.880Z
Kyu96
<p>So I have have an Ansible Task that extracts a programs sourcecode zip into a certain directory and is then supposed to compile and install it.
The extraction of the zip works fine, but then I need to execute the commands:</p>

<pre><code>./configure
make
sudo make install
</code></pre>

<p>And these commands need to be execute from within the extracted directory. I tried several things to execute it, I couldnt get it to work.</p>

<pre><code>  - name: doit
    command: chdir=/tmp/proftpd/ ./configure &amp;&amp; make &amp;&amp; make install
    become: yes
</code></pre>

<p>I tried this but it fails:</p>

<pre><code>  TASK [doit] ********************************************************************
fatal: [centos]: FAILED! =&gt; {"changed": true, "cmd": ["./configure", "&amp;&amp;", "make", "&amp;&amp;", "make", "install"], "delta": "0:00:00.152824", "end": "2019-11-21 14:20:48.656070", "msg": "non-zero return code", "rc": 1, "start": "2019-11-21 14:20:48.503246", "stderr": "configure: WARNING: you should use --build, --host, --target\nconfigure: WARNING: invalid host type: &amp;&amp;\nconfigure: WARNING: you should use --build, --host, --target\nconfigure: WARNING: you should use --build, --host, --target\nconfigure: WARNING: invalid host type: &amp;&amp;\nconfigure: WARNING: you should use --build, --host, --target\nconfigure: WARNING: you should use --build, --host, --target\nInvalid configuration `&amp;&amp;': machine `&amp;&amp;' not recognized\nconfigure: error: /bin/sh .//config.sub &amp;&amp; failed", "stderr_lines": ["configure: WARNING: you should use --build, --host, --target", "configure: WARNING: invalid host type: &amp;&amp;", "configure: WARNING: you should use --build, --host, --target", "configure: WARNING: you should use --build, --host, --target", "configure: WARNING: invalid host type: &amp;&amp;", "configure: WARNING: you should use --build, --host, --target", "configure: WARNING: you should use --build, --host, --target", "Invalid configuration `&amp;&amp;': machine `&amp;&amp;' not recognized", "configure: error: /bin/sh .//config.sub &amp;&amp; failed"], "stdout": "checking build system type... ", "stdout_lines": ["checking build system type... "]}
</code></pre>

<p>How can I achieve this properly with ansible?</p>

<ansible><configuration-management><vagrant><installation>
Ansible configure and compile in directory
Kyu96
# Ansible configure and compile in directory

(Asked by: username_0 on 2019-11-21)

So I have have an Ansible Task that extracts a programs sourcecode zip into a certain directory and is then supposed to compile and install it.
The extraction of the zip works fine, but then I need to execute the commands:
./configure
make
sudo make install

And these commands need to be execute from within the extracted directory. I tried several things to execute it, I couldnt get it to work.
  - name: doit
    command: chdir=/tmp/proftpd/ ./configure && make && make install
    become: yes

I tried this but it fails:
  TASK [doit] ********************************************************************
fatal: [centos]: FAILED! => {"changed": true, "cmd": ["./configure", "&&", "make", "&&", "make", "install"], "delta": "0:00:00.152824", "end": "2019-11-21 14:20:48.656070", "msg": "non-zero return code", "rc": 1, "start": "2019-11-21 14:20:48.503246", "stderr": "configure: WARNING: you should use --build, --host, --target\nconfigure: WARNING: invalid host type: &&\nconfigure: WARNING: you should use --build, --host, --target\nconfigure: WARNING: you should use --build, --host, --target\nconfigure: WARNING: invalid host type: &&\nconfigure: WARNING: you should use --build, --host, --target\nconfigure: WARNING: you should use --build, --host, --target\nInvalid configuration `&&': machine `&&' not recognized\nconfigure: error: /bin/sh .//config.sub && failed", "stderr_lines": ["configure: WARNING: you should use --build, --host, --target", "configure: WARNING: invalid host type: &&", "configure: WARNING: you should use --build, --host, --target", "configure: WARNING: you should use --build, --host, --target", "configure: WARNING: invalid host type: &&", "configure: WARNING: you should use --build, --host, --target", "configure: WARNING: you should use --build, --host, --target", "Invalid configuration `&&': machine `&&' not recognized", "configure: error: /bin/sh .//config.sub && failed"], "stdout": "checking build system type... ", "stdout_lines": ["checking build system type... "]}

How can I achieve this properly with ansible?

**Tags:** ansible, configuration-management, vagrant, installation


---

## 2 answers

### Answer by username_1 on 2019-11-21. Score: 5

Ansible `command` module requires only one command and cannot be changed. You should use the `shell` module at the very least. Note however that this will break the idempotency of the playbook.

You should probably split the task up into three:

* configure task using the `shell` module. Use `creates:` to tell the task to be skipped if the configure task has already created the expected output file
* make task, using [the Ansible Make module](https://docs.ansible.com/ansible/latest/modules/make_module.html#make-module)
* similarly for the make install task.

This should yield the same actual result, but would be more likely to be idempotent.

> **Comments:**
> **username_0**: How exactly would I specify the make and the make install tasks. I do know about the `make` keyword, but all my previous attempts didn't work correctly.  
> **username_1**: did you use the `target` parameter of the module? by setting the target parameter (ie target=install) you could run the make install.  

---

### Answer by username_0 on 2019-11-21. Score: 1

I just figured it out.
Splitting it up into more commands worked perfectly
  - name: doit
    command: chdir=/tmp/proftpd/ ./configure

  - name: a shit here we go again
    command: chdir=/tmp/proftpd/ make

  - name: another one
    command: chdir=/tmp/proftpd/ sudo make install


---

