---
- name: check if the realm already exists
  command: "{{ container_exec_cmd }} radosgw-admin realm get --cluster={{ cluster }} --rgw-realm={{ item }}"
  delegate_to: "{{ groups[mon_group_name][0] }}"
  register: realmcheck
  failed_when: False
  changed_when: False
  check_mode: no
  run_once: True
  loop: "{{ realms }}"
  when: realms is defined

- name: check if the zonegroup already exists
  command: "{{ container_exec_cmd }} radosgw-admin zonegroup get --cluster={{ cluster }} --rgw-realm={{ item.realm }} --rgw-zonegroup={{ item.zonegroup }}"
  delegate_to: "{{ groups[mon_group_name][0] }}"
  register: zonegroupcheck
  failed_when: False
  changed_when: False
  check_mode: no
  run_once: True
  loop: "{{ zonegroups }}"
  when: zonegroups is defined

- name: check if the zone already exists
  command: "{{ container_exec_cmd }} radosgw-admin zone get --rgw-realm={{ item.realm }} --cluster={{ cluster }} --rgw-zonegroup={{ item.zonegroup }} --rgw-zone={{ item.zone }}"
  delegate_to: "{{ groups[mon_group_name][0] }}"
  register: zonecheck
  failed_when: False
  changed_when: False
  check_mode: no
  run_once: True
  loop: "{{ zones }}"
  when: zones is defined
