I have run into a problem that I have not been able to solve – I hope somebody out there has had better luck than I have. Here’s the setup:
At the top level directory there is an executive shell script that calls a playbook, the particular playbook called is based on inputs to the script. For each playbook there is a corresponding role subdirectory, and each role subdirectory is further divided into a tasks subdirectory and a vars subdirectory. There is one vars file corresponding to each task file. Each role contains a set of unique tasks. If a task is used in more than one playbook then the tasks and vars files are located under the common subdirectory.
The structure of my current ansible hierarchy is shown below. Note that the common subdirectory and the compA and compB subdirectories look similar to the compN subdirectory, but only the compN subdirectory is shown in detail for simplification.
well I guess the number of replies says it all: I must be trying to do something the language does not support. Ansible conditions operate on “include_vars” - include* statements in ansible are dynamic. Similarly, import* statements in ansible are static. Tags are applicable to statically imported constructs; tags are not applicable to dynamic inclusions such as include_roles or include_tasks.
Therefore, since ansible conditionals are applicable to dynamic constructs, and ansible tags are applicable to static constructs; the two are mutually exclusive. The language does not support the ability to tag variables that are included via include_vars. Bummer.
This begs the question: how does one conditionally include vars files in tagged tasks in ansible?? Anybody?
well I guess the number of replies says it all: I must be trying to do something the language does not support. Ansible
conditions operate on "include_vars" - include* statements in ansible are dynamic. Similarly, import* statements in
ansible are static. Tags are applicable to statically imported constructs; tags are not applicable to dynamic
inclusions such as include_roles or include_tasks.
Therefore, since ansible conditionals are applicable to dynamic constructs, and ansible tags are applicable to static
constructs; the two are mutually exclusive. The language does not support the ability to tag variables that are
included via include_vars. Bummer.
This begs the question: how does one conditionally include vars files in tagged tasks in ansible?? Anybody?
Why don't you use the inventory for these variables? It is possible to use multiple inventories which coincide with
your current variable files.