---
- name: Test location
  hosts: "{{ ipa_test_host | default('ipaserver') }}"
  become: true

  tasks:

  # CLEANUP TEST ITEMS

  - name: Ensure location my_location1 is absent
    ipalocation:
      ipaadmin_password: SomeADMINpassword
      ipaapi_context: "{{ ipa_context | default(omit) }}"
      name: my_location1
      state: absent

  # CREATE TEST ITEMS

  # TESTS

  - name: Ensure location my_location1 is present
    ipalocation:
      ipaadmin_password: SomeADMINpassword
      ipaapi_context: "{{ ipa_context | default(omit) }}"
      name: my_location1
    register: result
    failed_when: not result.changed or result.failed

  - name: Ensure location my_location1 is present again
    ipalocation:
      ipaadmin_password: SomeADMINpassword
      ipaapi_context: "{{ ipa_context | default(omit) }}"
      name: my_location1
    register: result
    failed_when: result.changed or result.failed

  - name: Ensure location my_location1 is present with description
    ipalocation:
      ipaadmin_password: SomeADMINpassword
      ipaapi_context: "{{ ipa_context | default(omit) }}"
      name: my_location1
      description: My Location 1
    register: result
    failed_when: not result.changed or result.failed

  - name: Ensure location my_location1 is present again with description
    ipalocation:
      ipaadmin_password: SomeADMINpassword
      ipaapi_context: "{{ ipa_context | default(omit) }}"
      name: my_location1
      description: My Location 1
    register: result
    failed_when: result.changed or result.failed

  - name: Ensure location my_location1 is absent
    ipalocation:
      ipaadmin_password: SomeADMINpassword
      ipaapi_context: "{{ ipa_context | default(omit) }}"
      name: my_location1
      state: absent
    register: result
    failed_when: not result.changed or result.failed

  - name: Ensure location my_location1 is absent again
    ipalocation:
      ipaadmin_password: SomeADMINpassword
      ipaapi_context: "{{ ipa_context | default(omit) }}"
      name: my_location1
      state: absent
    register: result
    failed_when: result.changed or result.failed

  # CLEANUP TEST ITEMS

  - name: Ensure location my_location1 is absent
    ipalocation:
      ipaadmin_password: SomeADMINpassword
      ipaapi_context: "{{ ipa_context | default(omit) }}"
      name: my_location1
      state: absent
