Using git module with multiple repos and only running make when a particular repo changes.

12 views
Skip to first unread message

Rodney Lott

unread,
Aug 14, 2015, 2:16:02 PM8/14/15
to Ansible Project
My ansible version:

etdev@rlotttrustystock101012240:~$ ansible --version
ansible 1.9.2
  configured module search path = None

I am using a local connection (i.e. doing stuff on my local machine).

In my playbook, I have the following line that checks out additional code repos to build using the git module:

- name: Checkout src directories
     
register: repos_state
      git
: repo={{ item.value.url }} dest={{ item.value.checkout_dir }} version={{ item.value.revision }} force=true
      with_dict
: "{{ repos }}"

The repos variable is defined something like this:

repos:
  dcs
:
    url
: "http://supersecretrepo/dcsurl.git"
    revision
: 283fa10
    checkout_dir
: "{{ srcdir }}/dcs"
    build_dir
: "{{ srcdir }}/dcs"
  ecp
:
    url
: "http://supersecretrepo/ecpurl.git"
    revision
: fad759e
    checkout_dir
: "{{ srcdir }}/ecp"
    build_dir
: "{{ srcdir }}/ecp"
  vue
:
    url
: "http://supersecretrepo/vueurl.git"
    revision
: dc9acab
    checkout_dir
: "{{ srcdir }}/vue/vue"
    build_dir
: "{{ srcdir }}/vue"

I have a task following this that builds stuff from these repositories:

    - name: Build the software
      shell
: nohup make deb > /tmp/{{ item.key }}-build.txt chdir={{ item.value.build_dir }}
      with_dict
: "{{ repos }}"
     
when: repos_state.changed

So, when the variable repos_state shows an overall change, then it will rebuild ALL the software locations. 

What I would like to know is if there is a more fine grained way to do this. Let's say that I update the revision for repo dcs. In this case, I want my build software to only build the one that has changed. I have tried to figure out how to do this but haven't had much luck.

Does anyone have a suggestion about how I could do this? I tried "when: repos_state[ {{item.key}} ].changed" but that didn't work. 

I'm still fairly new to Ansible so I apologize if my question is simple. 

Thanks.

Rodney
Reply all
Reply to author
Forward
0 new messages