# If ansible_install_ansible_ara_version is not defined it should be "latest"
- name: Set ara default version to latest
  set_fact:
    install_ansible_ara_version: latest
  when: install_ansible_ara_version is not defined

# If a version is not explicitly set we want to make sure to
# completely omit the version argument to pip, as it will be coming
# from the long-form install_ansible_ara_name variable.  Additionally,
# if the version is the special value "latest", then we also want to
# omit any version number, but also set the package state to "latest".
- name: Set ARA version for installation
  set_fact:
    _install_ansible_ara_version: '{{ install_ansible_ara_version }}'
  when: install_ansible_ara_version not in ('', 'latest')

- name: Set ARA package state for installation
  set_fact:
    _install_ansible_ara_state: latest
  when: install_ansible_ara_version == 'latest'

- name: Install ARA
  pip:
    name: '{{ install_ansible_ara_name | default("ara[server]") }}'
    version: '{{ _install_ansible_ara_version | default(omit) }}'
    state: '{{ _install_ansible_ara_state | default(omit) }}'

# For configuring the callback plugins location in ansible.cfg
- name: Get ARA's location for callback plugins
  command: python3 -m ara.setup.callback_plugins
  register: install_ansible_ara_callback_plugins
  changed_when: false