Hi there,
I’m using ansible 1.9.2. We don’t use ansible for configuration management, but instead for deployment automation.
I’m trying to set some conditions early on in a play so that the right tasks get executed under the right conditions later in the play. This play is called multiple times from a playbook. I thought I had a good thing going here, until I realized upon the 2nd include of the play, the default I intended for a var was set to a value which got set within the first include of the play. I had thought that upon the 2nd include of the play, all vars would get set again to my intended default value. But that didn’t happen.
The details of what’s happening, including the playbook and play are at the bottom…
And when you get there … Is this expected? Is this a bug? Shouldn’t it work the way I expect?
The reason why I’m even going down this road is because ansible doesn’t support conditionally including a play within a playbook. “Conditions on include don’t apply to the include itself, it is applied to the tasks included”, from a previous post.
Thank you in advance!
kallen
`
ansible_1.9.2 $ cat sushi_playbook.yml
If I am following what behavior you are looking for (what you describe is how includes are intended to work) your playbook includes should be implemented as a role and then called with parameters. See if the added namespacing protections roles have, but includes does not kicks in.
Thank you. However, our playbooks don’t use roles. For our deployment orchestration, it doesn’t seem necessary, or at least it works well without them.
Can anyone speak to how that variable is getting set as the playbook executes the second include? Will this absolutely not work without roles?
I realize your are using includes. I was pointing out that you want to use roles for the benefit of the namespacing protection that roles have and includes do not. From what I see this is correct behavior for what you’ve implemented and not a bug. A role should give you the separate variable namespace scope you seem to be expecting.
So your expectation is incorrect, as any play level variable modified
during the play is still modified during any subsequent part of the
play, includes are not namespaced, in a play you only have 2 scopes:
play vars and host vars, both carry forward any changes made at any
point in the play. In the case of hostvars they'll carry over to
subsequent plays also.
What you want is 2 plays that set the same default vars and you can do
include #1 in the first play and include #2 in the 2nd, then the vars
will look like what you expect.
Thank you Brian. That’s the Clue I needed. I’ll rethink this…
kallen