---
- name: Provision the server
  hosts: localhost
  tags: always
  vars_files:
    - config.cfg

  pre_tasks:
    - block:
      - name: Local pre-tasks
        import_tasks: playbooks/cloud-pre.yml
        tags: always
      rescue:
        - debug: var=fail_hint
          tags: always
        - fail:
          tags: always

  roles:
    - role: cloud-digitalocean
      when: algo_provider == "digitalocean"
    - role: cloud-ec2
      when: algo_provider == "ec2"
    - role: cloud-vultr
      when: algo_provider == "vultr"
    - role: cloud-gce
      when: algo_provider == "gce"
    - role: cloud-azure
      when: algo_provider == "azure"
    - role: cloud-lightsail
      when: algo_provider == "lightsail"
    - role: cloud-scaleway
      when: algo_provider == "scaleway"
    - role: cloud-openstack
      when: algo_provider == "openstack"
    - role: local
      when: algo_provider == "local"

  post_tasks:
    - block:
      - name: Local post-tasks
        import_tasks: playbooks/cloud-post.yml
        become: false
        tags: cloud
      rescue:
        - debug: var=fail_hint
          tags: always
        - fail:
          tags: always
