---

- name: "Gathering current server infos for group {{ current_server_group.name }} from hetzner"
  hcloud_server_info:
    api_token: "{{ hetzner_authentication_ansible }}"
    label_selector: "{{ current_server_group.label_selector }}"
  register: current_server_infos
  delegate_to: 127.0.0.1
  become: false
  tags:
    - update_config

- name: "Setting server group as fact: server_group_infos_{{ current_server_group.name }}"
  set_fact:
    server_group_infos_{{ current_server_group.name }}: "{{ current_server_infos.hcloud_server_info | json_query(querystr) }}" # noqa var-naming
  vars:
    querystr: "[*].{id: id, name: name, ip: ipv4_address}"
  delegate_to: 127.0.0.1
  become: false
  tags:
    - update_config

- name: "Printing server group {{ current_server_group.name }}"
  debug:
    msg: "{{ lookup('vars', 'server_group_infos_' + current_server_group.name) }}"
  delegate_to: 127.0.0.1
  become: false
  tags:
    - update_config
  when:
   - debug
