snel.kubernetes-cluster/roles/hostbill_machine_name/tasks/main.yml

42 lines
1.7 KiB
YAML

---
- name: Lookup Hostbill account details by IP
become: false
delegate_to: "{{ hostbill_api_jumphost }}"
ansible.builtin.uri:
url: "https://{{ hostbill_api_ip }}/admin/api.php?api_id={{ hostbill_api_id }}&api_key={{ hostbill_api_key }}&call=searchServiceByIP&ip={{ ansible_host }}"
headers:
Host: "{{ hostbill_api_hostname }}" # We have to do it this way to force using IPv4
validate_certs: false
register: _get_account_details
- name: Verify we found exactly one Hostbill account
ansible.builtin.assert:
fail_msg: "We found {{ _get_account_details.json.services | length() }} hostbill accounts"
quiet: true
that:
- "1 == _get_account_details.json.services | length()"
- name: Filter account details
ansible.builtin.set_fact:
_hostbill_account_details: "{{ _get_account_details.json.services[_get_account_details.json.services.keys() | first] }}"
- name: Verify we found exactly one VPS
when: "_hostbill_account_details.source == 'proxmox'"
ansible.builtin.assert:
fail_msg: "We found {{ _get_account_details.json.services | length() }} VMs"
quiet: true
that:
- "1 == _hostbill_account_details.vms | length()"
- name: Set hostname
when: "_hostbill_account_details.domain != inventory_hostname"
become: false
delegate_to: "{{ hostbill_api_jumphost }}"
ansible.builtin.uri:
url: "https://{{ hostbill_api_ip }}/admin/api.php?api_id={{ hostbill_api_id }}&api_key={{ hostbill_api_key }}&call=editAccountDetails&id={{ _hostbill_account_details.id }}&domain={{ inventory_hostname }}"
headers:
Host: "{{ hostbill_api_hostname }}" # We have to do it this way to force using IPv4
validate_certs: false
changed_when: true