I have a provision playbook: https://gist.github.com/mlieberman85/c144fcc384cfcdc992d8 and the last line of it doesn’t work because roles can’t be variables I guess.
Also there’s no way to conditionally include playbooks only task files. What is the best practice to have a single provision set of tasks that runs locally to provision an instance and then based off of variables runs a role on the spun up instance(s)?
Hi Michael,
I think the way you’d want to do this is to provision your machines, then use the add_hosts (or the group_by) module to dynamically create groups of servers based on variable data . Then, create playbooks that target each group. So, for example, you create a series of web servers, add them to a group called web with add_host or group_by, then target the group ‘web’ in a playbook using include statements. If there are hosts in the web group, the playbook will run. For included playbooks that have no hosts for groups that are targeted, the playbook will be skipped.
I do something like this, albeit on a very small scale, in a sample playbook I wrote to spin up a cloud instance, wait for it to come online, then install Docker on it. https://github.com/angstwad/ansible-docker-rackspace/blob/master/playbooks/rax-servers.yml
If you look at that play, the second task is adding the server created in the first task to a group called “dockergroup”. I can then later do work on that group by creating a play that targets “hosts: dockergroup”.
Hope that helps.