Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,19 @@ Hostinger Collection Release Notes

.. contents:: Topics

v1.1.0
v2.0.0
======

Breaking Changes
----------------
- `hostinger_vps_ssh_key_binding` now calls `POST /virtual-machines/{id}/ssh-keys` because the old `public-keys/attach` endpoint is deprecated. It takes key text in the new `keys` option, which replaces `public_key_ids`, and no longer takes `wait` (the API returns the key list, not an action).
- The inventory plugin names every host `srv<id>.hstgr.cloud` instead of the VM hostname, which is now in the `hostinger_hostname` variable. Update playbooks and `host_vars` that target hosts by their VM hostname.
- Resource ID options (`virtual_machine_id`, `firewall_id`, `rule_id`, `backup_id`, `public_key_id`, `post_install_script_id`) are now integers, so a value can no longer change the API path a module calls.

Security Fixes
--------------
- The inventory plugin marks the values it reads from the API as unsafe, so ansible-core older than 2.19 no longer evaluates Jinja2 in them.
- A VM hostname can no longer make the inventory plugin redirect `localhost` or another inventory host to that VM, because hosts are named by VM ID.

v1.0.0
======
Expand Down
2 changes: 1 addition & 1 deletion galaxy.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace: hostinger
name: vps
version: 1.1.0
version: 2.0.0
authors: ["Hostinger Dev Team"]
description: Ansible collection to manage Hostinger VPS via Hostinger Public API.
license_file: GPL-3.0
Expand Down
4 changes: 2 additions & 2 deletions plugins/doc_fragments/action_wait.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ class ModuleDocFragment(object):
not finish within I(wait_timeout).
type: bool
default: false
version_added: 1.1.0
version_added: 2.0.0
wait_timeout:
description:
- Maximum number of seconds to wait when I(wait=true).
type: int
default: 600
version_added: 1.1.0
version_added: 2.0.0
'''
4 changes: 2 additions & 2 deletions plugins/doc_fragments/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ class ModuleDocFragment(object):
- Base URL of the Hostinger API.
type: str
default: https://developers.hostinger.com
version_added: 1.1.0
version_added: 2.0.0
api_timeout:
description:
- Timeout in seconds for each API request.
type: int
default: 60
version_added: 1.1.0
version_added: 2.0.0
'''
31 changes: 19 additions & 12 deletions plugins/inventory/inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
short_description: Hostinger VPS inventory plugin
description:
- Collects Hostinger VPS instances as dynamic Ansible inventory using the Hostinger VPS API.
- Each VM is added as C(srv<id>.hstgr.cloud), so its name is unique and cannot be chosen by whoever manages the VM.
The hostname set on the VM is available in the C(hostinger_hostname) variable.
options:
plugin:
description: Token to indicate this is a Hostinger inventory plugin
Expand All @@ -27,12 +29,12 @@
description: Base URL of the Hostinger API.
type: string
default: https://developers.hostinger.com
version_added: 1.1.0
version_added: 2.0.0
api_timeout:
description: Timeout in seconds for each API request.
type: integer
default: 60
version_added: 1.1.0
version_added: 2.0.0
'''

EXAMPLES = r'''
Expand All @@ -42,6 +44,7 @@

from ansible.errors import AnsibleError
from ansible.plugins.inventory import BaseInventoryPlugin
from ansible.utils.unsafe_proxy import wrap_var
from ansible_collections.hostinger.vps.plugins.module_utils.api import (
DEFAULT_API_URL,
DEFAULT_TIMEOUT,
Expand Down Expand Up @@ -75,20 +78,24 @@ def parse(self, inventory, loader, path, cache=True):
raise AnsibleError("Unexpected response format from Hostinger API. Expected a list of VMs.")

for vm in vms:
if not isinstance(vm, dict):
if not isinstance(vm, dict) or vm.get("id") is None:
continue

hostname = vm.get("hostname") or f"srv{vm.get('id', 'unknown')}.hstgr.cloud"
# The VM hostname is chosen by whoever manages the VM, so it could claim localhost or the name
# of another host; the ID-based name is unique and only the hostname variable is user-controlled.
hostname = wrap_var(f"srv{vm['id']}.hstgr.cloud")
self.inventory.add_host(hostname)

ipv4_list = vm.get("ipv4") or []
ip = ipv4_list[0]["address"] if ipv4_list and "address" in ipv4_list[0] else None
if ip:
self.inventory.set_variable(hostname, "ansible_host", ip)

self.inventory.set_variable(hostname, "hostinger_id", vm.get("id"))
self.inventory.set_variable(hostname, "plan", vm.get("plan"))
self.inventory.set_variable(hostname, "state", vm.get("state"))
self.inventory.set_variable(hostname, "cpus", vm.get("cpus"))
self.inventory.set_variable(hostname, "memory", vm.get("memory"))
self.inventory.set_variable(hostname, "disk", vm.get("disk"))
self._set_variable(hostname, "ansible_host", ip)

for name in ("plan", "state", "cpus", "memory", "disk"):
self._set_variable(hostname, name, vm.get(name))
self._set_variable(hostname, "hostinger_id", vm["id"])
self._set_variable(hostname, "hostinger_hostname", vm.get("hostname"))

def _set_variable(self, hostname, name, value):
# API values are data, never templates: mark them unsafe so Ansible does not evaluate Jinja2 in them.
self.inventory.set_variable(hostname, name, wrap_var(value))
2 changes: 1 addition & 1 deletion plugins/modules/hostinger_vps_action_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
---
module: hostinger_vps_action_info
short_description: List actions of a Hostinger virtual machine
version_added: 1.1.0
version_added: 2.0.0
description:
- Lists the actions (start, recreate, backup, and so on) performed on a virtual machine, newest first, or returns a
single action.
Expand Down
8 changes: 4 additions & 4 deletions plugins/modules/hostinger_vps_backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
virtual_machine_id:
description: ID of the VPS
required: true
type: str
type: int
state:
description:
- Desired operation.
Expand All @@ -27,7 +27,7 @@
type: str
backup_id:
description: Required for restore operations.
type: str
type: int
required: false
extends_documentation_fragment:
- hostinger.vps.api
Expand Down Expand Up @@ -73,9 +73,9 @@ def main():
module_args = api_argument_spec()
module_args.update(action_wait_argument_spec())
module_args.update(
virtual_machine_id=dict(type='str', required=True),
virtual_machine_id=dict(type='int', required=True),
state=dict(type='str', required=True, choices=["get", "delete", "restore"]),
backup_id=dict(type='str', required=False)
backup_id=dict(type='int', required=False)
)

module = AnsibleModule(argument_spec=module_args)
Expand Down
2 changes: 1 addition & 1 deletion plugins/modules/hostinger_vps_backup_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
---
module: hostinger_vps_backup_info
short_description: List backups of a Hostinger virtual machine
version_added: 1.1.0
version_added: 2.0.0
description:
- Lists the backups of a virtual machine, collected from all pages of results.
- Restore a backup with M(hostinger.vps.hostinger_vps_backup).
Expand Down
2 changes: 1 addition & 1 deletion plugins/modules/hostinger_vps_catalog_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
---
module: hostinger_vps_catalog_info
short_description: List products in the Hostinger catalog
version_added: 1.1.0
version_added: 2.0.0
description:
- Lists the products that can be purchased, with their prices.
- The C(id) of a price, for example C(hostingercom-vps-kvm2-usd-1m), is the I(item_id) used to purchase it.
Expand Down
2 changes: 1 addition & 1 deletion plugins/modules/hostinger_vps_data_center_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
---
module: hostinger_vps_data_center_info
short_description: List Hostinger VPS data centers
version_added: 1.1.0
version_added: 2.0.0
description:
- Lists the data centers a new virtual machine can be set up in.
extends_documentation_fragment:
Expand Down
4 changes: 2 additions & 2 deletions plugins/modules/hostinger_vps_firewall.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
firewall_id:
description: Firewall ID (required for get/delete)
required: false
type: str
type: int
name:
description: Name of the firewall (required for create)
required: false
Expand Down Expand Up @@ -78,7 +78,7 @@ def main():
module_args = api_argument_spec()
module_args.update(
state=dict(type='str', required=True, choices=['get', 'create', 'delete']),
firewall_id=dict(type='str', required=False),
firewall_id=dict(type='int', required=False),
name=dict(type='str', required=False)
)

Expand Down
8 changes: 4 additions & 4 deletions plugins/modules/hostinger_vps_firewall_binding.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
firewall_id:
description: Firewall ID
required: true
type: str
type: int
virtual_machine_id:
description: Virtual Machine ID
required: true
type: str
type: int
state:
description:
- Action to perform on the binding.
Expand Down Expand Up @@ -78,8 +78,8 @@ def main():
module_args = api_argument_spec()
module_args.update(action_wait_argument_spec())
module_args.update(
firewall_id=dict(type='str', required=True),
virtual_machine_id=dict(type='str', required=True),
firewall_id=dict(type='int', required=True),
virtual_machine_id=dict(type='int', required=True),
state=dict(type='str', required=True, choices=["activate", "deactivate", "sync"])
)

Expand Down
2 changes: 1 addition & 1 deletion plugins/modules/hostinger_vps_firewall_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
---
module: hostinger_vps_firewall_info
short_description: List Hostinger VPS firewalls
version_added: 1.1.0
version_added: 2.0.0
description:
- Lists the firewalls of the Hostinger account with their rules, or returns a single one.
options:
Expand Down
8 changes: 4 additions & 4 deletions plugins/modules/hostinger_vps_firewall_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
firewall_id:
description: ID of the firewall to manage rules for
required: true
type: str
type: int
rule_id:
description: Rule ID (required for update/delete)
required: false
type: str
type: int
rule:
description:
- Dictionary with rule parameters.
Expand Down Expand Up @@ -112,8 +112,8 @@ def is_valid_cidr(value):
def main():
module_args = api_argument_spec()
module_args.update(
firewall_id=dict(type='str', required=True),
rule_id=dict(type='str', required=False),
firewall_id=dict(type='int', required=True),
rule_id=dict(type='int', required=False),
rule=dict(type='dict', required=False),
state=dict(type='str', required=True, choices=["create", "update", "delete"])
)
Expand Down
4 changes: 2 additions & 2 deletions plugins/modules/hostinger_vps_get_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
virtual_machine_id:
description: ID of the virtual machine to retrieve
required: true
type: str
type: int
extends_documentation_fragment:
- hostinger.vps.api
author:
Expand Down Expand Up @@ -48,7 +48,7 @@
def main():
module_args = api_argument_spec()
module_args.update(
virtual_machine_id=dict(type='str', required=True),
virtual_machine_id=dict(type='int', required=True),
)

module = AnsibleModule(
Expand Down
2 changes: 1 addition & 1 deletion plugins/modules/hostinger_vps_malware_scanner_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
---
module: hostinger_vps_malware_scanner_info
short_description: Get Monarx malware scan results of a Hostinger virtual machine
version_added: 1.1.0
version_added: 2.0.0
description:
- Returns whether the Monarx malware scanner is installed on a virtual machine and the results of its last scan.
- Install or uninstall the scanner with M(hostinger.vps.hostinger_vps_malware_scanner).
Expand Down
4 changes: 2 additions & 2 deletions plugins/modules/hostinger_vps_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
virtual_machine_id:
description: ID of the VPS to retrieve metrics for
required: true
type: str
type: int
date_from:
description: ISO8601 start datetime (e.g., 2025-04-07T00:00:00Z)
required: true
Expand Down Expand Up @@ -59,7 +59,7 @@
def main():
module_args = api_argument_spec()
module_args.update(
virtual_machine_id=dict(type='str', required=True),
virtual_machine_id=dict(type='int', required=True),
date_from=dict(type='str', required=True),
date_to=dict(type='str', required=True)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
---
module: hostinger_vps_post_install_script_info
short_description: List post-install scripts of a Hostinger account
version_added: 1.1.0
version_added: 2.0.0
description:
- Lists the post-install scripts of the Hostinger account, or returns a single one.
options:
Expand Down
4 changes: 2 additions & 2 deletions plugins/modules/hostinger_vps_postinstall_delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
post_install_script_id:
description: ID of the post-install script to delete.
required: true
type: str
type: int
extends_documentation_fragment:
- hostinger.vps.api
"""
Expand Down Expand Up @@ -48,7 +48,7 @@
def main():
module_args = api_argument_spec()
module_args.update(
post_install_script_id=dict(type='str', required=True)
post_install_script_id=dict(type='int', required=True)
)

module = AnsibleModule(
Expand Down
4 changes: 2 additions & 2 deletions plugins/modules/hostinger_vps_power.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
description:
- The ID of the VPS instance to perform the action on.
required: true
type: str
type: int
action:
description:
- The power action to perform on the VPS.
Expand Down Expand Up @@ -73,7 +73,7 @@ def main():
module_args = api_argument_spec()
module_args.update(action_wait_argument_spec())
module_args.update(
virtual_machine_id=dict(type='str', required=True),
virtual_machine_id=dict(type='int', required=True),
action=dict(type='str', required=True, choices=['start', 'stop', 'restart'])
)

Expand Down
2 changes: 1 addition & 1 deletion plugins/modules/hostinger_vps_ptr.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
- Defaults to the only IPv4 address of the virtual machine. Required when it has more than one.
required: false
type: str
version_added: 1.1.0
version_added: 2.0.0
extends_documentation_fragment:
- hostinger.vps.api
- hostinger.vps.action_wait
Expand Down
Loading
Loading