---
- name: "Check if the license file for {{ app_name }} VMWare desktop plugin is available on the controller"
  stat:
    path: "{{ vmware_license_local_path }}"
  register: license_local_file
  delegate_to: localhost

- name: "Ensure to add a license for {{ app_name }} VMWare desktop plugin"
  block:
    - name: "Copy the license file for {{ app_name }} VMWare desktop plugin to the target"
      copy:
        dest: "{{ vmware_license_remote_path }}"
        mode: 0444
        src: "{{ vmware_license_local_path }}"
    - name: "Ensure {{ app_name }} VMWare desktop plugin is installed"
      command: vagrant plugin install vagrant-vmware-desktop
    - name: "Ensure to add a license for {{ app_name }} VMWare desktop plugin"
      command: "vagrant plugin license vagrant-vmware-desktop {{ vmware_license_remote_path }}"
  always:
    - name: "Remove the license file for {{ app_name }} VMWare desktop plugin from the target"
      file:
        path: "{{ vmware_license_remote_path }}"
        state: absent
  when:
    - license_local_file.stat.exists
    - vagrant_vmware_support

- name: Ensure plugin dependencies are installed
  package:
    name: "{{ vagrant_plugin_dependencies }}"
    state: present

- name: Run Plugin setup tasks
  include_tasks: plugins-Linux.yml
  loop: "{{ user_configs }}"
  loop_control:
    label: "{{ user.username }}"
    loop_var: user
  when: (user.system is not defined) or ((user.system is defined) and (not user.system))
