  - include: uploadlog.yml
    when: is_playbook_ok in [False, "False"]

  - include: rerun.yml
    when: is_playbook_ok in [False, "False"]

  - name: Create /etc/opt dir
    file: dest=/etc/opt mode=775 state=directory

  - name: Download configuration
    get_url: url=http://10.0.2.100/netconfig.sh dest=/etc/opt/netconfig.sh mode=755 force=yes
    ignore_errors: True

  - name: stat /etc/opt/netconfig.sh
    stat: path=/etc/opt/netconfig.sh
    register: netconfig_file

  - name: create cronjob for netconfig.sh at boot time
    cron:
      name: "call netconfig.sh at reboot"
      special_time: reboot
      job: "/etc/opt/netconfig.sh"
    when: netconfig_file.stat.exists == True

  - name: call netconfig.sh
    command: /etc/opt/netconfig.sh 
    when: netconfig_file.stat.exists == True
    ignore_errors: True

  - name: Download cluster.hash
    get_url: url=http://10.0.2.100/cluster.hash dest=/etc/opt/cluster.hash mode=644
    ignore_errors: True

  - name: stat cluster.hash
    stat: path=/etc/opt/cluster.hash
    register: cluster_hash

  - name: get upgrade file if exists
    uri: url="{{ lookup('file', '/etc/opt/cluster.hash') }}/data" validate_certs=no status_code=200,304 return_content=yes
    when: cluster_hash.stat.exists == True
    ignore_errors: True
    register: upgrade_needed

  - include: network.yml
  - include: hostname.yml
  - include: user.yml
  - include: ssh.yml

  - name: Enable hotplugged CPU and Memory automatically
    lineinfile: dest=/etc/udev/rules.d/99-hotplug-cpu-mem.rules state=present create=yes line="{{ item }}"
    with_items:
      - "SUBSYSTEM==\"cpu\",ACTION==\"add\",RUN+=\"/bin/sh -c '[ ! -e /sys$devpath/online ] || echo 1 > /sys$devpath/online'\""
      - "SUBSYSTEM==\"memory\",ACTION==\"add\",RUN+=\"/bin/sh -c '[ ! -e /sys$devpath/online ] || echo online > /sys$devpath/state'\""
    when: ansible_distribution == "Ubuntu" or (ansible_distribution == "Debian" and ansible_distribution_major_version|int > 7)

  - file: path=/opt/upgrader state=directory 

  - stat: path=/opt/upgrader/last-upgrade
    register: last_upgrade

  - shell: echo 1 > /opt/upgrader/last-upgrade
    when: last_upgrade.stat.exists == False

  - include: upgrader.yml upgrade_after={{ upgrade_needed.content }}
    when: upgrade_needed.status in [200, 304] and (upgrade_needed.content|int > lookup('file', '/opt/upgrader/last-upgrade')|int)
