---
# tasks file for atom
- name: test veriables and environment
  assert:
    that:
      - ansible_pkg_mgr is defined
      - ansible_pkg_mgr == "yum" or
        ansible_pkg_mgr == "dnf" or
        ansible_pkg_mgr == "apt" or
        ansible_pkg_mgr == "zypper"
      - atom_package_url is defined
      - atom_package is defined

- name: install requirements
  package:
    name: "{{ atom_requirements }}"
    state: present
  when:
    - atom_requirements is defined
    - ansible_pkg_mgr == "apt"
  register: atom_install_requirements
  until: atom_install_requirements is succeeded
  retries: 3

- name: download atom
  get_url:
    url: "{{ atom_package_url }}"
    dest: "/tmp/{{ atom_package }}"
    validate_certs: no
  when:
    - ansible_pkg_mgr == "apt" or
      ansible_pkg_mgr == "dnf" or
      ansible_pkg_mgr == "yum" or
      ansible_pkg_mgr == "zypper"
  register: atom_download_atom
  until: atom_download_atom is succeeded
  retries: 3

- name: install atom deb
  apt:
    deb: "/tmp/{{ atom_package }}"
    state: present
  when:
    - ansible_pkg_mgr == "apt"

- name: install atom rpm dnf
  dnf:
    name: "/tmp/{{ atom_package }}"
    state: present
  when:
    - ansible_pkg_mgr == "dnf"

- name: install atom rpm yum
  yum:
    name: "/tmp/{{ atom_package }}"
    state: present
  when:
    - ansible_pkg_mgr == "yum"

- name: install atom rpm zypper
  zypper:
    name: "/tmp/{{ atom_package }}"
    state: present
    disable_gpg_check: yes
  when:
    - ansible_pkg_mgr == "zypper"
