---
- name: Test simple bind and unbind
  hosts: all
  vars:
    nbde_client_bindings:
      - device: "{{ nbde_client_test_device }}"
        encryption_password: "{{ nbde_client_test_pass }}"
        servers:
          - http://localhost
      - device: "{{ nbde_client_test_device }}"
        encryption_password: "{{ nbde_client_test_pass }}"
        state: absent

  tasks:
    - name: Set up test environment
      include_tasks: tasks/setup_test.yml

    - name: Run the test
      block:
        - name: Use nbde_client role
          include_role:
            name: linux-system-roles.nbde_client

        - name: Attempt to unlock device
          include_tasks: tasks/verify_unlock_device.yml

        - name: Make sure the attempt to unlock failed
          assert:
            that:
              - nbde_client_unlock.failed
              - nbde_client_close.failed

        - name: Assert idempotency when trying to only unbind
          include_tasks: tasks/verify_idempotency.yml
          vars:
            nbde_client_bindings:
              - device: "{{ nbde_client_test_device }}"
                encryption_password: "{{ nbde_client_test_pass }}"
                state: absent

      always:
        - name: Clean up test environment
          include_tasks: tasks/cleanup_test.yml
# vim:set ts=2 sw=2 et:
