---
- name: Test issuing certificate with nonexistent provider
  hosts: all
  vars:
    certificate_requests:
      - name: mycert_wrong_provider
        dns: www.example.com
        ca: self-sign
        provider: fake-provider

  tasks:
    - name: Run test
      vars:
        expected_error_msg: >-
          Chosen provider 'fake-provider' is not available.
      block:
        - name: Import certificate role
          import_role:
            name: linux-system-roles.certificate
        - name: Failed
          fail:
            msg: "Certificate issued with nonexistent provider 'fake-provider'."
      rescue:
        - name: Assert...
          assert:
            that:
              - ansible_failed_result.results.0.msg  == expected_error_msg
            fail_msg: >-
              '{{ ansible_failed_result.results.0.msg }}' !=
              '{{ expected_error_msg }}'
