# looking for solutions for a packaging play inside a playbook

**URL:** <https://forum.ansible.com/t/looking-for-solutions-for-a-packaging-play-inside-a-playbook/13976>\
**Category:** Ansible Project\
**Created:** [November 22, 2013, 5:06pm UTC](https://forum.ansible.com/t/looking-for-solutions-for-a-packaging-play-inside-a-playbook/13976 "2013-11-22T17:06:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jerome\_Wagner](https://avatars.discourse-cdn.com/v4/letter/j/76d3ee/32.png) [@Jerome\_Wagner](https://forum.ansible.com/u/Jerome_Wagner)\
**Post date:** [November 22, 2013, 5:06pm UTC](https://forum.ansible.com/t/looking-for-solutions-for-a-packaging-play-inside-a-playbook/13976/1 "2013-11-22T17:06:51Z")

</div>

Hello,

I am trying to setup my global playbook as :

> **configuration of apps through vars** :
> 
> - which apps, which repo they’re in, which git branch (“HEAD” or git sha)
> 
> **play 1 : packaging on localhost**.  
> this clones repos, builds applications, create packages in several {app}-{sha}.tgz

{ role: packager, apps: list1\_of\_apps }  
{ role: packager, apps: list2\_of\_apps }

> **play2…N: preparation of remotes and deployment of packages,…**  
> this does all the rest

I have 2 difficulties:  
(1) when an app is declared as “HEAD”, I still want the package to be built with the git sha  
I have been able to solve this on the hypothesis that there is only one git repository, by registering the output of an update of the git module into a git\_head variable, and accessing it from other hosts via hostvars[‘127.0.0.1’].git\_head

(2) where there are multiple repos and multiple calls to the packager role.  
In this case I could not find a solution.

I would like to dynamically build a dict that would look like :

> head\_sha:  
> myrepo1: ab1253…
> 
> myrepo2: cb2343…
> 
> myrepo3: ffb1253…

but I cannot find a way to mix all the results of the git module (mix of all the with\_items results of the multiple role.packager calls) and cannot find a way to extract the sha from all these results depending on the repo used by the app being installed.

Do you know a solution I could use to capture and propagate to other hosts the captured shas of the HEADs of the repos and how to exploit this data structure ?

Thank you for your help  
Jerome

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [November 22, 2013, 9:02pm UTC](https://forum.ansible.com/t/looking-for-solutions-for-a-packaging-play-inside-a-playbook/13976/2 "2013-11-22T21:02:18Z")

</div>

Sorry, but this is a very long question and I’m having difficulty in understanding what you are asking since there are various gaps in the explanation and I can’t see your playbook – not that we have time to dig through.

Is there a specific question about Ansible we can help with and a snippet of playbook you can share that helps narrow down the question?

That would be much appreciated, thanks!

---

<div class="post-metadata">

**Author:** ![Jerome\_Wagner](https://avatars.discourse-cdn.com/v4/letter/j/76d3ee/32.png) [@Jerome\_Wagner](https://forum.ansible.com/u/Jerome_Wagner)\
**Post date:** [November 22, 2013, 9:53pm UTC](https://forum.ansible.com/t/looking-for-solutions-for-a-packaging-play-inside-a-playbook/13976/3 "2013-11-22T21:53:25Z")

</div>

yes that was a long question indeed (after a long ansible day 😉

Here is a with-playbook question (hopefully more clear) :

**A first play is responsible for preparing packages**

- hosts: localhost  
gather\_facts: no

roles:

- { role: packager, apps: $node\_apps }
- { role: packager, apps: $php\_apps }

with for example for $node\_apps :

node\_apps:

- packager\_type: tar  
gitrepo: “{{ gitrepo\_app1 }}”  
gitversion: **HEAD**  
app\_id: app1\_1  
… other keys specific to node apps

- packager\_type: tar

gitrepo: “{{ gitrepo\_app1 }}”  
gitversion: **bc7837d032a2d648b607f012e2d1e33b3dcb6679**  
app\_id: app1\_2  
… other keys specific to node apps

- packager\_type: tar  
gitrepo: “{{ gitrepo\_app2 }}”  
gitversion: **HEAD**  
app\_id: app2  
… other keys specific to node apps

the role.packager loops over the apps, clone the repo at the requested version, and locally build a {{ appname }}-{{ sha }}.tgz. Note that sha is the real sha even if HEAD was requested.

This can be done with _register: git\_results_ since the **git:** module returns the sha.before and sha.after for each item in the with\_items loop

Now in another play, i need to **unarchive:** {{ appname }}-{{ sha }}.tgz

by doing a _with\_indexed\_items: node\_apps_ I might be able to find the correct sha in  
{{ hostvars[‘127.0.0.1’].git\_results.results[item.0].after }} (not tested I just found this idea, is this the correct way to handle this ?)

my issue is that since the role.packager is called 2 times, git\_results is overwritten by the second call and the first values are lost.

so should I :  
(1) - try and have only one long list of multi-technology apps (node, php, ruby,…) =\> only one call to role.packager

(2) - interlace “deploy” plays with “packaging” plays like so :

> - hosts: localhost
> 
> roles:
> 
> - { role: packager, apps: $node\_apps }
> 
> - hosts: node\_apps\_group
> 
> roles:
> 
> - { role: deploy\_node\_apps, apps: $node\_apps }
> 
> - hosts: localhost
> 
> roles:
> 
> - { role: packager, apps: $php\_apps }
> 
> - hosts: php\_apps\_group
> 
> roles:
> 
> - { role: deploy\_php\_apps, apps: $php\_apps }

maybe some of you have found other ways to do something similar and can help me !  
thank you very much  
Jerome

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [November 23, 2013, 3:58pm UTC](https://forum.ansible.com/t/looking-for-solutions-for-a-packaging-play-inside-a-playbook/13976/4 "2013-11-23T15:58:08Z")

</div>

Don’t use old style variables BTW:
