    - name: Instance or reconfigure
      stat:
        path: "/etc/eole/.instance"
      register: instanciated
      changed_when: true
      notify:
        - Test if already configured
        - Reconfigure
        - Install python-pexpect
        - Install python3-pexpect
        - Instance

    - name: Test if already instanciated
      stat:
        path: "/etc/eole/.instance"
      register: instanciated

    - name: Test if already configured
      stat:
        path: "/etc/eole/config.eol"
      register: configured

    - name: Reconfigure
      shell:
        cmd: /usr/bin/reconfigure
      when: instanciated.stat.exists and configured.stat.exists

    - name: Install python-pexpect
      apt:
        name: python-pexpect
        state: present
      when: ansible_python.version.major|int == 2 and not instanciated.stat.exists
      notify: Uninstall python-pexpect

    - name: Install python3-pexpect
      apt:
        name: python3-pexpect
        state: present
      when: ansible_python.version.major|int == 3 and not instanciated.stat.exists
      notify: Uninstall python3-pexpect

    - name: Instance
      cadoles.eole.instance:
        module: "{{ module_type }}"
        variables: "{{ module_instance_variables }}"
      when: not instanciated.stat.exists
      notify:
        - Is reboot needed

    - name: Uninstall python3-pexpect
      apt:
        name: python3-pexpect
        state: absent

    - name: Uninstall python-pexpect
      apt:
        name: python-pexpect
        state: absent

    - name: Refresh package lists
      shell:
        cmd: Query-Auto

    - name: Is reboot needed
      shell:
        cmd: "TERM=vt100 /usr/share/eole/diagnose/08-upgrade  | awk '/Reboot/ {print $5}'"
      register: reboot_needed
      notify:
        - Reboot

    - name: Reboot
      reboot:
        reboot_timeout: 3600
        search_paths:
          - '/lib/molly-guard'
      when: reboot_needed.stdout == "Oui"
      notify:
        - Wait for host

    - name: Wait for host
      wait_for_connection:
        delay: 10
        sleep: 2
        timeout: 800
