# How to skip recursive role dependencies parsing

**URL:** <https://forum.ansible.com/t/how-to-skip-recursive-role-dependencies-parsing/20502>\
**Category:** Ansible Project\
**Created:** [February 9, 2016, 7:10pm UTC](https://forum.ansible.com/t/how-to-skip-recursive-role-dependencies-parsing/20502 "2016-02-09T19:10:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![lalmsun7](https://avatars.discourse-cdn.com/v4/letter/l/c5a1d2/32.png) [@lalmsun7](https://forum.ansible.com/u/lalmsun7)\
**Post date:** [February 9, 2016, 7:10pm UTC](https://forum.ansible.com/t/how-to-skip-recursive-role-dependencies-parsing/20502/1 "2016-02-09T19:10:09Z")

</div>

Hi,  
I encountered a problem and cannot figure it out. I have a Ansible task to install a web app. This web app task has a role dependency to install tomcat while tomcat has a role dependency to install java. In the java task I created two files under /role/java/var to define the different java version on Solaris and Linux. I used the following code to include the yml files under /role/java/var:

- name: Include variables for the appropriate OS family  
include\_vars: “{{ ansible\_os\_family }}.yml”

After the code above the java task will include linux.yml and solaris.yml based on the OS:

- name: Include RedHat-specific tasks  
include: RedHat.yml  
when: ansible\_os\_family == “RedHat”

- name: Include Solaris-specific tasks  
include: Solaris.yml  
when: ansible\_os\_family == “Solaris”

Inside the RedHat.yml there are series tasks and one of those is looking for the java version to install:

- name: Install Oracle JDK (RedHat)  
yum: name=“{{ item }}” state=present enablerepo=kdm  
with\_items: “jdkversions[jdkversion][‘pkgs’]”  
register: yum\_install  
ignore\_errors: yes

The “jdkversions” is defined in the yml file under /role/java/var. Everything works fine if tomcat and java are installed.

If I gave a condition to the web app task not to run role dependency “tomcat” then problem is coming: it still goes to Java task and skips all the other tasks but “- name: Install Oracle JDK (RedHat)”; and then throws out error complaining that “with\_items expects a list or a set” because the yml files under /role/java/var were not loaded and thus no “jdkversions” is defined.

Can anyone please tell me the rule that which task will be skipped and which one will not be skipped if the role dependencies are told not to execute? I understand that Ansible will parse all tasks regardless even I told the role dependencies not to run but if some tasks are skipped while the others are not then how to resolve it?

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![lalmsun7](https://avatars.discourse-cdn.com/v4/letter/l/c5a1d2/32.png) [@lalmsun7](https://forum.ansible.com/u/lalmsun7)\
**Post date:** [February 10, 2016, 10:18pm UTC](https://forum.ansible.com/t/how-to-skip-recursive-role-dependencies-parsing/20502/2 "2016-02-10T22:18:42Z")

</div>

Hi,

I think my first post was not clear enough. I’m simplifying the issue here:  
The role “webApp” has a dependency to install java. Java installation is required only when the parameter “is\_required” sets to “true”. In the java task I created two files under /role/java/vars which are conditionally included based on the target operating system (RedHat or Solaris).

Role webApp:

meta/main.yml:

- { role: java, when: is\_required }

Role Java:

tasks/main.yml:  
…

- name: Include variables for the appropriate OS family  
**include\_vars: “{{ ansible\_os\_family }}.yml”** ---- the variable “ **jdkversions** ” is defined in the .yml (RedHat.yml and Solaris.yml)

- name: Install Oracle JDK (RedHat)  
yum: name=“{{ item }}” state=present enablerepo=kdm  
with\_items: “ **jdkversions** [jdkversion][‘pkgs’]”  
register: yum\_install  
ignore\_errors: yes  
…

If I set “is\_required” to “false” in the web app task the problem is coming: it skipped the step to include yml files under /role/java/vars ( **include\_vars: “{{ ansible\_os\_family }}.yml”** ) but still parsed the variable **jdkversions** in the task “- name: Install Oracle JDK (RedHat)” and then this task threw out error:  
_fatal: with\_items expects a list or a set_

The reason that the variable “ **jdkversions** ” is defined in vars/main.yml other than defaults/main.yml is because we don’t want it to be overwritten and the values of this variable is different based on operating systems.

Can someone please tell me how to prevent it from parsing the variables that were skipped previously?

Thanks.
