Hi there,
I am trying to deploy several drupal sites with a playbook. So far, I am only trying out some ansible features and I am stuck with how best structure my playbooks. The approach I would prefer is not working so I am hoping you can help me out.
Before going into the detail, let me explain why I prefer approach 1) over 2):
- Less verbose, just use with_items once when including the tasks-file
- Variable names would make more sense because I would be able to use ${site} everywhere instead of ${item} (in templates for instance)
- Included task-file can be reused for just deploying one site instead of many (it will depend on how you include it in the play-book)
Here you have the details, please let me know if I am missing something:
I use a sites_available.yml file that describes the different sites that should be deployed. Something like:
1) Preferred approach: Include task file with_items (I couldn't make this
work):
# Playbook: deploy-all.yml
Yep, you can't make it work (include + with_items) presently because
it's not meant to.
with_items is only legal on a task because the definition of each task
is uniform across all hosts in the play, and if we were to include
variables here, that would change things.
Now, we could generally make that work with non host and group
specific variables, but I'd be worried people would expect it to work
with facts and such and it would confuse people too greatly.
So far, I *think* you're the first person to try with_items with an
include statement.
If that didn't raise an error, it /should/, IMHO. Just as this also should:
- include: foo.yml
some_option_that_does_not_exist: 1234
with_items is only legal on a task because the definition of each task
is uniform across all hosts in the play, and if we were to include
variables here, that would change things.
I don’t get what you mean by “uniform accross all hosts” my proposed use of with_items would still perform the tasks in a uniformed fashion. It is just a short hand for what you can already do on a task by task basis.
So far, I think you’re the first person to try with_items with an
include statement.
Well, I “might” be the first, but got the idea from current docs:
tasks:
- include: wordpress.yml user=timmy
- include: wordpress.yml user=alice
- include: wordpress.yml user=bob
tasks:
include: wordpress.yml user=$item
with_items; $users
If that didn’t raise an error, it /should/, IMHO.
It does not raise any. That is for sure.
Thanks a lot, I am learning a lot with ansible.
It's possible for us to make this work, with pre-task variables.
However, in doing so, it would be a bit confusing for folks to try it
with other variables that were host specific. As such, I think it's
better to list things out and let them be explicit.
It just means the definition lives in the playbook, rather than in the
variable section.
Forgot about that. So much going on with 0.8 I can't remember it all
Daniel is the man!
--Michael