- name: Perform pre-deployment validations
  hosts: localhost
  gather_facts: yes
  any_errors_fatal: true
  tasks:

      - name: "Install/Upgrade are mutually exclusive"
        fail:
            msg: "Options '--deploy' and '--upgrade' and '--ocupdate' are mutually exclusive"
        when:
            - ( install.deploy|default('') and install.upgrade|default('')) or
              ( install.deploy|default('') and install.ocupdate|default(False)) or
              ( install.upgrade|default('') and install.ocupdate|default(False))

      - name: validate storage nodes
        fail:
            msg: "To many storage nodes to discover storage backend. Provide --storage-backend cli option with the backend to use. "
        when:
            - install.deploy|default('')
            - not (install.storage|default({})).backend|default(False)
            - "'swift' in groups"
            - "'ceph' in groups"

- name: Perform pre-deployment validations on undercloud
  hosts: undercloud
  gather_facts: no
  any_errors_fatal: true
  tasks:

      - name: validate and copy environment plan file
        include_tasks: tasks/environment_plan.yml
        when: (install.environment|default({})).plan|default(false)

- name: Perform pre-deployment validations
  hosts: localhost
  gather_facts: yes
  any_errors_fatal: true
  tasks:

      - name: "Install/Upgrade are mutually exclusive"
        fail:
            msg: "Options '--deploy' and '--upgrade' and '--ocupdate' are mutually exclusive"
        when:
            - ( install.deploy|default('') and install.upgrade|default('')) or
              ( install.deploy|default('') and install.ocupdate|default(False)) or
              ( install.upgrade|default('') and install.ocupdate|default(False))

      - name: validate storage nodes
        fail:
            msg: "To many storage nodes to discover storage backend. Provide --storage-backend cli option with the backend to use. "
        when:
            - install.deploy|default('')
            - not (install.storage|default({})).backend|default(False)
            - "'swift' in groups"
            - "'ceph' in groups"

      - block:
          - name: validate storage-config option is provided
            fail:
                msg: "The --storage-config cli option should be provided for external storage backend when --storage-external is used. "
            when:
                - install.storage.config == 'internal'

          - name: check if user provided external storage config
            stat:
                path: "vars/storage/config/{{ install.storage.config }}.yml"
            register: install_storage_config_file

          - fail:
                msg: |
                    "The file for external storage config is not found.
                    Expected path: vars/storage/config/{{ install.storage.config }}.yml"
            when:
                - install_storage_config_file.stat.exists == False

        when:
            - install.deploy|default('')
            - install.storage.external

- name: Perform pre-deployment validations on undercloud
  hosts: undercloud
  gather_facts: no
  any_errors_fatal: true
  tasks:

      - name: validate and copy environment plan file
        include_tasks: tasks/environment_plan.yml
        when: (install.environment|default({})).plan|default(false)

Fix reverted patch "Netapp backend job should fail if no netapp backend is available"
Fix reverted patch "Netapp backend job should fail if no netapp backend is available"

RHOSINFRA-1487: Added validation step for external storage backend,
in case if --storage-external is enabled, --storage-config  should be
provided, otherwise 'tripleo-overcloud' ansible playbook will be failed.
Such verification is needed, because if user doesn't provide external
storage config, tripleo will deploy overcloud with a default storage
backend 'lvm' and that's not expected behavior.

Change-Id: Ib1669ccf3e78626586d81b86b5a10138edcc8d99
