summaryrefslogtreecommitdiffstats
path: root/ansible_collections/vultr/cloud/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'ansible_collections/vultr/cloud/plugins')
-rw-r--r--ansible_collections/vultr/cloud/plugins/doc_fragments/vultr_v2.py5
-rw-r--r--ansible_collections/vultr/cloud/plugins/module_utils/vultr_v2.py10
-rw-r--r--ansible_collections/vultr/cloud/plugins/modules/bare_metal.py7
-rw-r--r--ansible_collections/vultr/cloud/plugins/modules/instance.py49
4 files changed, 63 insertions, 8 deletions
diff --git a/ansible_collections/vultr/cloud/plugins/doc_fragments/vultr_v2.py b/ansible_collections/vultr/cloud/plugins/doc_fragments/vultr_v2.py
index 692103e8c..76eaa8c74 100644
--- a/ansible_collections/vultr/cloud/plugins/doc_fragments/vultr_v2.py
+++ b/ansible_collections/vultr/cloud/plugins/doc_fragments/vultr_v2.py
@@ -25,7 +25,10 @@ options:
default: 180
api_retries:
description:
- - Amount of retries in case of the Vultr API retuns an HTTP 503 code.
+ - Amount of retries in case of the Vultr API retuns an HTTP error code, such as
+ - 429 Too Many Requests
+ - 500 Internal Server Error
+ - 504 Gateway Time-out
- Fallback environment variable C(VULTR_API_RETRIES).
type: int
default: 5
diff --git a/ansible_collections/vultr/cloud/plugins/module_utils/vultr_v2.py b/ansible_collections/vultr/cloud/plugins/module_utils/vultr_v2.py
index 602e89605..db8eded0c 100644
--- a/ansible_collections/vultr/cloud/plugins/module_utils/vultr_v2.py
+++ b/ansible_collections/vultr/cloud/plugins/module_utils/vultr_v2.py
@@ -171,6 +171,11 @@ class AnsibleVultr:
# Vultr has a rate limiting requests per second, try to be polite
# Use exponential backoff plus a little bit of randomness
backoff(retry=retry, retry_max_delay=retry_max_delay)
+ else:
+ self.module.fail_json(
+ msg='Failure while calling the Vultr API v2 with %s for "%s" with %s retries' % (method, path, retry + 1),
+ fetch_url_info=info,
+ )
# Success with content
if info["status"] in (200, 201, 202):
@@ -270,7 +275,10 @@ class AnsibleVultr:
resources = self.api_query(path=path, query_params=query_params)
return resources[result_key] if resources else []
- def wait_for_state(self, resource, key, states, cmp="=", retries=60):
+ def wait_for_state(self, resource, key, states, cmp="=", retries=60, skip_wait=False):
+ if skip_wait:
+ return resource
+
resource_id = resource[self.resource_key_id]
for retry in range(0, retries):
resource = self.query_by_id(resource_id=resource_id, skip_transform=False)
diff --git a/ansible_collections/vultr/cloud/plugins/modules/bare_metal.py b/ansible_collections/vultr/cloud/plugins/modules/bare_metal.py
index d2ffe09ef..f700fb937 100644
--- a/ansible_collections/vultr/cloud/plugins/modules/bare_metal.py
+++ b/ansible_collections/vultr/cloud/plugins/modules/bare_metal.py
@@ -101,6 +101,12 @@ options:
- A list of VPCs (VPC 2.0) identified by their description to be assigned to the bare metal machine.
type: list
elements: str
+ skip_wait:
+ description:
+ - Whether to skip the wait for the instance to be completely ready for access.
+ type: bool
+ default: false
+ version_added: "1.13.0"
state:
description:
- State of the bare metal machine.
@@ -376,6 +382,7 @@ def main():
user_data=dict(type="str"),
ssh_keys=dict(type="list", elements="str", no_log=False),
region=dict(type="str", required=True),
+ skip_wait=dict(type="bool", default=False),
state=dict(
choices=[
"present",
diff --git a/ansible_collections/vultr/cloud/plugins/modules/instance.py b/ansible_collections/vultr/cloud/plugins/modules/instance.py
index 7eca359b4..c1165124a 100644
--- a/ansible_collections/vultr/cloud/plugins/modules/instance.py
+++ b/ansible_collections/vultr/cloud/plugins/modules/instance.py
@@ -120,6 +120,12 @@ options:
type: list
elements: str
version_added: "1.5.0"
+ skip_wait:
+ description:
+ - Whether to skip the wait for the instance to be completely ready for access.
+ type: bool
+ default: false
+ version_added: "1.13.0"
state:
description:
- State of the instance.
@@ -439,19 +445,49 @@ class AnsibleVultrInstance(AnsibleVultrCommonInstance):
path="%s/%s/%s" % (self.resource_path, resource[self.resource_key_id], action),
method="POST",
)
- if wait_for_state:
- resource = self.wait_for_state(resource=resource, key="power_status", states=[power_status])
+ resource = self.wait_for_state(
+ resource=resource,
+ key="power_status",
+ states=[power_status],
+ skip_wait=not wait_for_state,
+ )
return resource
def create_or_update(self):
resource = super(AnsibleVultrInstance, self).create_or_update()
if resource:
- resource = self.wait_for_state(resource=resource, key="server_status", states=["none", "locked"], cmp="!=")
+ if not self.module.check_mode and self.module.params.get("state") == "present":
+ resource = self.wait_for_state(
+ resource=resource,
+ key="server_status",
+ states=["none", "locked"],
+ cmp="!=",
+ skip_wait=self.module.params.get("skip_wait", False),
+ )
# Hanlde power status
- resource = self.handle_power_status(resource=resource, state="stopped", action="halt", power_status="stopped")
- resource = self.handle_power_status(resource=resource, state="started", action="start", power_status="running")
- resource = self.handle_power_status(resource=resource, state="restarted", action="reboot", power_status="running", force=True)
+ resource = self.handle_power_status(
+ resource=resource,
+ state="stopped",
+ action="halt",
+ power_status="stopped",
+ wait_for_state=not self.module.params.get("skip_wait", False),
+ )
+ resource = self.handle_power_status(
+ resource=resource,
+ state="started",
+ action="start",
+ power_status="running",
+ wait_for_state=not self.module.params.get("skip_wait", False),
+ )
+ resource = self.handle_power_status(
+ resource=resource,
+ state="restarted",
+ action="reboot",
+ power_status="running",
+ force=True,
+ wait_for_state=not self.module.params.get("skip_wait", False),
+ )
resource = self.handle_power_status(
resource=resource,
state="reinstalled",
@@ -505,6 +541,7 @@ def main():
ssh_keys=dict(type="list", elements="str", no_log=False),
region=dict(type="str", required=True),
user_scheme=dict(type="str", choices=["root", "limited"]),
+ skip_wait=dict(type="bool", default=False),
state=dict(
choices=[
"present",