Dependancies and Plays?

Hi everyone.

Is there a good way to specify that a play needs whatever is done by another play? EG I have a playbook that installs apache. I have another playbook that installs a wiki and yet another that installs wordpress. (I’m making this all up for this example) Both the wiki and wordpress depend on apache. Rather than including the apache play in the wiki and wordpress plays, is there a way to make the wordpress and wiki plays call the apache play if needed?

Including the apache play might work in some cases. I’d need to be able to exit the apache play early, but the only way I know to do that is by failing out in a debug statement, which would signify that installing apache failed, rather than signifying that apache is already installed. The other problem is that I might want to install the wiki or wordpress on a system that doesn’t have the identical apache setup to the one produced by my apache playbook.

Maybe this problem is better described as conditionally activating a play or a set of tasks? Right now if I want to do something more complex than one task (eg copy this over there, unpack it, put it in a shoebox, mail it to Aunt Mildred etc…) I have to use a when: statement on all of those instead of some kind of single conditional. I can conditionally include a play, but then I have to bounce back and forth between files… Hmm… that is probably my best option…

Chances are, I’m just thinking about this wrong, so please set me straight. How do you all handle playbook dependencies?

Thanks & Thank you for Ansible!
-Dylan

There is no such thing in ansible as “playbook dependency”.

The way i do it, is to have a master playbook, that includes all playbooks for my site, in the needed order.
Then use --limit and/or --tags to target a part of it.

Serge

Hi,

Ansible tasks should be idempotent (multiple executions of them should result in exactly the same state). If they are not, try to redesign them and than use the approach from Serge. :slight_smile:

In case you were including task lists instead of whole playbooks, you could also check if a directory exists (eg. /etc/apache), register a variable for this task and than conditionally (when: apache.changed) execute the include statement for the dependent task list…

Greetings,
gw