---

- name: create a new ACL without rules
  consul_acl:
    host: "{{ acl_host }}"
    mgmt_token: "{{ mgmt_token }}"
    name: "{{ test_consul_acl_token_name }}"
  register: created_ruleless_acl

- name: verify ACL created without rules
  assert:
    that:
      - created_ruleless_acl.changed
      - created_ruleless_acl.operation == "create"
      - created_ruleless_acl.token | length == 36
      - created_ruleless_acl.rules == {}

- name: create same rule-less ACL
  consul_acl:
    host: "{{ acl_host }}"
    mgmt_token: "{{ mgmt_token }}"
    name: "{{ test_consul_acl_token_name }}"
  register: doubly_created_ruleless_acl

- name: verify idempotence when creating ruleless ACL tokens
  assert:
    that:
      - not doubly_created_ruleless_acl.changed

- name: clean up
  consul_acl:
    host: "{{ acl_host }}"
    mgmt_token: "{{ mgmt_token }}"
    token: "{{ doubly_created_ruleless_acl.token }}"
    state: absent
