gantsign / ansible-role-java

Ansible role for installing Java from Adoptium

Home Page:https://galaxy.ansible.com/gantsign/java

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ansible_env is undefined

hollmanenciso opened this issue · comments

Hi .

I0m trying your ansible role, simple way as you mention on documentation:

- hosts: all
  become: true
  gather_facts: no

  roles:
    - gantsign.java

But I'm performing the next issue when it's applying.

TASK [java : create download directory] ***************************************************************************************************************************************************************************
task path: /mnt/c/Users/henciso/repos/devopsadmin-jenkins-slaves-ondemand/Ansible/roles/java/tasks/adoptopenjdk.yml:7
fatal: [localhost]: FAILED! => {
    "msg": "The task includes an option with an undefined variable. The error was: 'ansible_env' is undefined\n\nThe error appears to have been in 'slaves-ondemand/Ansible/roles/java/tasks/adoptopenjdk.yml': line 7, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: create download directory\n  ^ here\n"
}

Any suggestion? not sure if I'm doing something wrong or I missing something else?
thanks

@hollmanenciso thanks for reporting this issue.

This role uses ansible_env.HOME to determine where to download the JDK to, specifying this explicitly using either java_download_dir or x_ansible_download_dir will likely solve your problem.

According to the Ansible docs:
"ansible_env: is normally populated by fact gathering (M(gather_facts)) and the value of the variables depends on the user that did the gathering action. If you change remote_user/become_user you might end up using the wrong values for those variables." https://docs.ansible.com/ansible/latest/user_guide/playbooks_environment.html#playbooks-environment.

So you may also be able to resolve the issue by running gather_facts at the beginning of your playbook: https://docs.ansible.com/ansible/latest/modules/gather_facts_module.html.

I'm wondering if this may be a breaking change in Ansible itself, which version of Ansible are you running?

You're right, I solve it with gather_facts. many thanks for your help and useful links to understand in details!

Ansible version: 2.5.1

cheers!