How to use ansible role from galaxy with my own parameters?

449 Views Asked by At

I would like to use a role found on ansible galaxy: robertdebock.java

I would like to use this role to install java with the version as parameter. I have tried this in my roles/java/tasks/main.yml file:

- name: Install Java
  include_role:
    name: robertdebock.java
  vars:
    java_version: 10

Unfortunately, only version 11 is installed, no matter what I provide as parameter for java_version.

How is it possible to use an existing Galaxy role with my own parameters?

2

There are 2 best solutions below

0
On BEST ANSWER

Yes, it's possible to use an existing Galaxy role with your own parameters.

But in your case, read the VALID-COMBINATIONS.md documentation.

You probably get the default version for your OS:

https://github.com/robertdebock/ansible-role-java/blob/master/vars/main.yml#L73

java_openjdk_package: "{{ _java_openjdk_package[java_type][java_version][ansible_distribution] | default(_java_openjdk_package[java_type][java_version]['default'] | default([])) }}"
0
On

You can pass variables to the role when you use it in your playbook:

- name: Install Java
  roles: 
  - { role: robertdebock.java, java_version: 10 }

As long as the variables use the same name, they will be pulled in as role variables, in the proper scope