Get community.general.make task idempotent

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

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:

    - 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

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

    - 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 for the git clone then it would be more idempotent?

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

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

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

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?

    - 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 )

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

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.

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

Open an issue for this in the repo if there isn’t one already?

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

1 Like

Now I created a feature request:
Add creates and when to community.general.make #9732

1 Like

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