I need to deploy the query applicatio before yje tomweb application, so in my playbook I wrote 2 plays:
the one I want to play first will run the role this way:
roles:
{ role: tomweb, when: module == ‘tomweb’ }
vars:
module: “{{ PARAM[0] }}”
the play I want to run after the 1st one is then defined later with this rôle:
roles:
{ role: query, when: module == ‘query’ }
vars:
module: “{{ PARAM[0] }}”
The last play will be like:
roles:
{ role: restart, when: module == ‘restart’ }
vars:
module: “{{ PARAM[0] }}”
This way to proceed do work but I have to duplicate all pre_tasks and variables, is there a way to say I want to run for sure the tomweb role first if the line with this module is present in the inventory file ?
And so have only one play in my playbook ?
That way you could make tomweb role ‘depend’ on ‘query’ role, so the query role would run first before tomweb (if that’s what you want.
You might also want to consider using a handler to restart.
Also maybe think about using groups in your inventory
[ref-query]
host1
[ref-tomweb]
host1
then your playbook could have
hosts: ref-query
roles:
query
hosts: ref-tomweb
roles:
tomweb
hosts: all
roles:
restart
(restart could be a handler as well, so perhaps not necessary to be a separate role). Handlers are nice as they can be made to only do things (like restarts) if changes have occurred.
Or something like that.
I think it might be worth experimenting with how you organise your variables so that your playbooks run have to run roles against hosts - that way the playbooks don’t become complicated with lots of conditionals etc.