# dependency modeling

**URL:** <https://forum.ansible.com/t/dependency-modeling/14424>\
**Category:** Ansible Project\
**Created:** [January 25, 2014, 4:36am UTC](https://forum.ansible.com/t/dependency-modeling/14424 "2014-01-25T04:36:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Xu\_Chen](https://avatars.discourse-cdn.com/v4/letter/x/958977/32.png) [@Xu\_Chen](https://forum.ansible.com/u/Xu_Chen)\
**Post date:** [January 25, 2014, 4:36am UTC](https://forum.ansible.com/t/dependency-modeling/14424/1 "2014-01-25T04:36:02Z")

</div>

I have a use case for Ansible where I have several code bases (say, C\_A and C\_B), and several services (S\_A1, S\_A2, S\_B1, S\_B2). Here S\_A1 and S\_A2 are essentially different executables from the same repo containing C\_A. It’s relatively easy to model the dependency such that when a node is running a service, the dependent code base is deployed.

What I need is to write a somewhat generic playbook to upgrade a code base (say C\_A) on all or a group of nodes. And if a node is running a corresponding service (say S\_A1), the service must be stopped first, perform upgrade, and restart the service.

Ideally, I want to be able to do something like: “ansible-play -i nodes upgrade.yml -e code\_base=C\_A --limit group-test”

I’ve thought about modeling C\_\* and S\_\* as roles, and use role dependency to link them. But I am not sure if we can iterate through all the nodes that take a particular role.  
Another way might be to define two levels of groups, a group of nodes that runs a service, and a group of services that should run a code base. In this case, at least we might be able to write a playbook like:

- hosts: “group\_{{ code\_base }}”  
roles:
- { role: role\_code\_base, name: “{{ code\_base }}”}

But in this case, I am not sure how to trigger the right services to reload, and stop them all in the first place.

Any ideas? Thanks…

---

<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:** [January 25, 2014, 3:44pm UTC](https://forum.ansible.com/t/dependency-modeling/14424/2 "2014-01-25T15:44:18Z")

</div>

Playbooks are supposed to be a record of history, thus you really shouldn’t parameterize the name of a group.

List out the groups and store them in version control, and if neccessary, keep seperate playbooks for different groups if you like.

You can pull multiple playbooks together in one file, like so:

multi.yml:

- include: pb\_one.yml
- include: pb\_two.yml

---

<div class="post-metadata">

**Author:** ![Xu\_Chen](https://avatars.discourse-cdn.com/v4/letter/x/958977/32.png) [@Xu\_Chen](https://forum.ansible.com/u/Xu_Chen)\
**Post date:** [January 28, 2014, 11:53pm UTC](https://forum.ansible.com/t/dependency-modeling/14424/3 "2014-01-28T23:53:02Z")

</div>

Thanks..

But I am still curious.. is there a way to list all the roles a node is taking when running a task?

I can potentially add a line in a common config file for each role. But this won't remove a role from that file if I update the playbook or role dependency such that a node is no longer taking a role.

Any ideas?
