Question

I have a C++ program hosted in Bitbucket git repository that I'm compiling with CMake. The current play can be seen below. It works fine except build-task is run every time the play is run. Instead I'd like build-task to run only when new software version is pulled by git-module. How I can tell in build-task if clone-task found new version ?

---
# tasks of role: foo

- name: clone repository
  git: repo=git@bitbucket.org:foo/foo.git
       dest={{ foo.dir }}
       accept_hostkey=yes

- name: create build dir
  file: state=directory path={{ foo.build_dir }}

- name: build
  command: "{{ item }} chdir={{ foo.build_dir }}"
  with_items:
    - cmake ..
    - make
Was it helpful?

Solution

You can register variable with output of clone task and invoke build task when state of clone task is changed

For example:

---
# tasks of role: foo

- name: clone repository
  git: repo=git@bitbucket.org:foo/foo.git
       dest={{ foo.dir }}
       accept_hostkey=yes
  register: gitclone

- name: create build dir
  file: state=directory path={{ foo.build_dir }}

- name: build
  command: "{{ item }} chdir={{ foo.build_dir }}"
  with_items:
    - cmake ..
    - make
  when: gitclone.changed
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top