# Get community.general.make task idempotent

**URL:** <https://forum.ansible.com/t/get-community-general-make-task-idempotent/40196>\
**Category:** Get Help\
**Created:** [February 11, 2025, 10:29pm UTC](https://forum.ansible.com/t/get-community-general-make-task-idempotent/40196 "2025-02-11T22:29:29Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lonerider2010](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/lonerider2010/32/7558_2.png) [@Lonerider2010](https://forum.ansible.com/u/Lonerider2010)\
**Post date:** [February 11, 2025, 10:29pm UTC](https://forum.ansible.com/t/get-community-general-make-task-idempotent/40196/1 "2025-02-11T22:29:29Z")

</div>

Currently I try to install the GIMP plugin BIMP via Ansible. So the tasks I want to execute are:

- git clone the repository [https://github.com/alessandrofrancesconi/gimp-plugin-bimp.git](https://github.com/alessandrofrancesconi/gimp-plugin-bimp.git)
- change to the `gimp-plugin-bimp` directory
- make
- make install.

Now I found the `community.general.make` module. And yes, I could install the plugin with the help of this module. Unfortunately, every time I start the playbook again, it executes the make and make install tasks again.  
My understanding for getting the tasks idempotent is to use either `creates` or a `when` clause. But both are not allowed with the `community.general.make` module. So how can I achieve the idempotency?

Here a snipet from my playbook:

```auto
    - name: Clone the BIMP repository
      ansible.builtin.git:
        repo: https://github.com/alessandrofrancesconi/gimp-plugin-bimp.git
        dest: /opt/gimp-plugin-bimp
        clone: yes
        update: yes

    - name: Build the BIMP target
      community.general.make:
        chdir: /opt/gimp-plugin-bimp

    - name: Run BIMP 'install' target
      community.general.make:
        chdir: /opt/gimp-plugin-bimp
        target: install

```

---

<div class="post-metadata">

**Author:** ![chris](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/chris/32/293_2.png) [@chris](https://forum.ansible.com/u/chris)\
**Post date:** [February 11, 2025, 10:41pm UTC](https://forum.ansible.com/t/get-community-general-make-task-idempotent/40196/2 "2025-02-11T22:41:34Z")

</div>

You could just run the tasks when the `git clone` changes anything?

```auto
    - name: Clone the BIMP repository
      ansible.builtin.git:
        repo: https://github.com/alessandrofrancesconi/gimp-plugin-bimp.git
        dest: /opt/gimp-plugin-bimp
        clone: true
        update: true
      register: bimp_git_clone

    - name: Build and install BIMP when git clone results change
      block:

        - name: Build the BIMP target
          community.general.make:
            chdir: /opt/gimp-plugin-bimp

        - name: Run BIMP 'install' target
          community.general.make:
            chdir: /opt/gimp-plugin-bimp
            target: install

      when: bimp_git_clone.changed | bool

```

If you also specified a [version](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/git_module.html#parameter-version) for the `git clone` then it would be more idempotent?

---

<div class="post-metadata">

**Author:** ![Lonerider2010](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/lonerider2010/32/7558_2.png) [@Lonerider2010](https://forum.ansible.com/u/Lonerider2010)\
**Post date:** [February 11, 2025, 10:50pm UTC](https://forum.ansible.com/t/get-community-general-make-task-idempotent/40196/3 "2025-02-11T22:50:06Z")

</div>

The `git clone` copies the repo for the first run. For the next runs, Ansible says `ok`. The `make` command generates a file that I could specify with

```auto
creates: /opt/gimp-plugin-bimp/bin/bimp

```

but `creates` is not available in the `community.general.make` module.

---

<div class="post-metadata">

**Author:** ![chris](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/chris/32/293_2.png) [@chris](https://forum.ansible.com/u/chris)\
**Post date:** [February 11, 2025, 11:08pm UTC](https://forum.ansible.com/t/get-community-general-make-task-idempotent/40196/4 "2025-02-11T23:08:07Z")

</div>

You could do something like this — only run `make` and `make install` if the `git clone` changes anything or if the `/opt/gimp-plugin-bimp/bin/bimp` files doesn’t exist?

```yaml
    - name: Clone the BIMP repository
      ansible.builtin.git:
        repo: https://github.com/alessandrofrancesconi/gimp-plugin-bimp.git
        dest: /opt/gimp-plugin-bimp
        clone: true
        update: true
      register: bimp_git_clone

    - name: Stat /opt/gimp-plugin-bimp/bin/bimp
      ansible.builtin.stat:
        path: /opt/gimp-plugin-bimp/bin/bimp
      register: bimp_bin_bimp
  
    - name: Build and install BIMP when git clone results change or bin/bimp doesn't exist
      block:
  
        - name: Build the BIMP target
          community.general.make:
            chdir: /opt/gimp-plugin-bimp
  
        - name: Run BIMP 'install' target
          community.general.make:
            chdir: /opt/gimp-plugin-bimp
            target: install
  
      when: ( bimp_git_clone.changed | bool ) or ( not bimp_bin_bimp.stat.exists | bool )

```

---

<div class="post-metadata">

**Author:** ![Lonerider2010](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/lonerider2010/32/7558_2.png) [@Lonerider2010](https://forum.ansible.com/u/Lonerider2010)\
**Post date:** [February 11, 2025, 11:16pm UTC](https://forum.ansible.com/t/get-community-general-make-task-idempotent/40196/5 "2025-02-11T23:16:05Z")

</div>

@chris: Thanks for this hint. Unfortunately that does not work. Ansible throws the following exception:

```auto
fatal: [xxxxxxx]: FAILED! => {}

MSG:

The conditional check '( bimp_git_clone.changed | bool ) or ( not bimp_bin_bimp.exists | bool )' failed. The error was: error while evaluating conditional (( bimp_git_clone.changed | bool ) or ( not bimp_bin_bimp.exists | bool )): 'dict object' has no attribute 'exists'. 'dict object' has no attribute 'exists'

The error appears to be in '/media/web/projects/common/ansible/runner/project/set_RaspiHOME_example.yml': line 39, column 11, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

        - name: Build the BIMP target
          ^ here

```

Still I think it would be helpful to allow `creates` in the module.

---

<div class="post-metadata">

**Author:** ![chris](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/chris/32/293_2.png) [@chris](https://forum.ansible.com/u/chris)\
**Post date:** [February 11, 2025, 11:19pm UTC](https://forum.ansible.com/t/get-community-general-make-task-idempotent/40196/6 "2025-02-11T23:19:27Z")

</div>

Sorry I made a typo, `bimp_bin_bimp.exists` should have been `bimp_bin_bimp.stat.exists`, I have corrected it above.

> [@Lonerider2010](#):
>
> Still I think it would be helpful to allow `creates` in the module.

Open an issue for this in [the repo](https://github.com/ansible-collections/community.general/issues) if there isn’t one already?

---

<div class="post-metadata">

**Author:** ![Lonerider2010](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/lonerider2010/32/7558_2.png) [@Lonerider2010](https://forum.ansible.com/u/Lonerider2010)\
**Post date:** [February 11, 2025, 11:24pm UTC](https://forum.ansible.com/t/get-community-general-make-task-idempotent/40196/7 "2025-02-11T23:24:01Z")

</div>

@chris: Thanks very much, now it works fine.  
Before opening an issue, I wanted to make sure that I understand the matter correctly.

---

<div class="post-metadata">

**Author:** ![Lonerider2010](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/lonerider2010/32/7558_2.png) [@Lonerider2010](https://forum.ansible.com/u/Lonerider2010)\
**Post date:** [February 11, 2025, 11:38pm UTC](https://forum.ansible.com/t/get-community-general-make-task-idempotent/40196/8 "2025-02-11T23:38:55Z")

</div>

Now I created a feature request:  
[Add creates and when to community.general.make #9732](https://github.com/ansible-collections/community.general/issues/9732)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [March 13, 2025, 11:39pm UTC](https://forum.ansible.com/t/get-community-general-make-task-idempotent/40196/9 "2025-03-13T23:39:08Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
