Hi
I’ve just started to play with Ansible for a small project. I started out with an example playbook and started to expand it. Part of my current playbook is up at https://gist.github.com/brianly/6402488.
As this got more complex I’ve noticed that copy and template actions don’t always happen for tasks. To fix this I’ve had to split tasks up, but this doesn’t feel right to me.
A lot of what is on lines 70 to 87 seems like it should be merged into a couple of tasks. The tasks on lines 74 and 77 are very simple, but when these actions were together only the copy task would complete. The template task never executed.
I’m running ansible 1.2.2 on OS X.
Any ideas? Feel free to point out other problems, but I haven’t had time to get to grips with all of the other modules yet.
-Brian
The name line on 69 only applies to the next module statement (file on line 70). Starting at line 71, each of those file: lines should have a dash in front of it, or they should have their own name lines. The same goes for lines 89-92 and 97-98.
Finally, you should start using the new “with:” syntax instead of only_if, which will be deprecated at some point in the future.
There’s nothing wrong with the copy or template modules. What you are doing here is making one task that continually overrides the action such that the very last action is the one that takes.
you wan this:
- action: foo args
- action: foo args
- action: foo args
instead of:
- action: foo
action: foo
action: foo
Of course I prefer just
- foo: args
- foo: args
- foo: args
Why does this happen? Because you’re specifying a hash/dictionary, and there can only be one of each key. You can only specify one action for each task unless you are doing a loop using something like “with_items”.
BTW, James means “when:” instead of “only_if”, not “with”. “with” is another thing It’s a much easier way to write conditionals. The basic problem is that there are some old tutorials out there. Always look at the http://ansibleworks.com/ documentation to see the latest, I suspect you might have been reading some old internet content elsewhere.