looking for solutions for a packaging play inside a playbook

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

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!

yes that was a long question indeed (after a long ansible day :wink:

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

Don’t use old style variables BTW: