summaryrefslogtreecommitdiffstats
path: root/ansible_collections/vultr/cloud/tests
diff options
context:
space:
mode:
Diffstat (limited to 'ansible_collections/vultr/cloud/tests')
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/cloud-config-vultr.ini.template12
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/account_info/aliases2
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/account_info/tasks/main.yml27
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/block_storage/aliases3
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/block_storage/defaults/main.yml16
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/block_storage/tasks/failures.yml21
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/block_storage/tasks/main.yml16
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/block_storage/tasks/tests.yml165
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/block_storage/tasks/tests_attach_to_server.yml151
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/block_storage_info/aliases3
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/block_storage_info/defaults/main.yml7
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/block_storage_info/tasks/main.yml7
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/block_storage_info/tasks/tests.yml36
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/cleanup/aliases1
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/cleanup/defaults/main.yml3
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/cleanup/meta/main.yml3
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/cleanup/tasks/cleanup_block_storage.yml29
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/cleanup/tasks/cleanup_dns_domain.yml29
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/cleanup/tasks/cleanup_firewall_group.yml28
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/cleanup/tasks/cleanup_instance.yml29
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/cleanup/tasks/cleanup_network.yml29
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/cleanup/tasks/cleanup_reserved_ip.yml29
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/cleanup/tasks/cleanup_snapshot.yml29
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/cleanup/tasks/cleanup_ssh_key.yml29
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/cleanup/tasks/cleanup_startup_script.yml29
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/cleanup/tasks/cleanup_user.yml29
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/cleanup/tasks/cleanup_vpc.yml33
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/common/aliases1
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/common/default/main.yml4
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/dns_domain/aliases3
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/dns_domain/defaults/main.yml4
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/dns_domain/meta/main.yml3
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/dns_domain/tasks/main.yml13
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/dns_domain/tasks/tests.yml138
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/dns_domain_info/aliases3
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/dns_domain_info/defaults/main.yml3
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/dns_domain_info/meta/main.yml3
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/dns_domain_info/tasks/main.yml13
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/dns_domain_info/tasks/tests.yml27
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/dns_record/aliases3
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/dns_record/defaults/main.yml38
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/dns_record/meta/main.yml3
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/dns_record/tasks/create_record.yml62
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/dns_record/tasks/main.yml13
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/dns_record/tasks/record.yml6
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/dns_record/tasks/remove_record.yml114
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/dns_record/tasks/test_fail_multiple.yml78
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/dns_record/tasks/tests.yml12
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/dns_record/tasks/update_record.yml70
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/firewall_group/aliases3
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/firewall_group/defaults/main.yml4
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/firewall_group/meta/main.yml3
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/firewall_group/tasks/main.yml7
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/firewall_group/tasks/tests.yml86
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/firewall_group_info/aliases3
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/firewall_group_info/defaults/main.yml2
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/firewall_group_info/meta/main.yml3
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/firewall_group_info/tasks/main.yml7
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/firewall_group_info/tasks/tests.yml34
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/firewall_rule/aliases3
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/firewall_rule/defaults/main.yml40
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/firewall_rule/meta/main.yml3
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/firewall_rule/tasks/main.yml8
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/firewall_rule/tasks/rule_absent.yml62
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/firewall_rule/tasks/rule_present.yml62
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/firewall_rule/tasks/tests.yml28
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/firewall_rule_info/aliases3
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/firewall_rule_info/defaults/main.yml2
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/firewall_rule_info/meta/main.yml3
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/firewall_rule_info/tasks/main.yml7
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/firewall_rule_info/tasks/tests.yml45
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/instance/aliases3
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/instance/defaults/main.yml95
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/instance/meta/main.yml3
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/instance/tasks/absent.yml38
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/instance/tasks/failures.yml55
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/instance/tasks/main.yml16
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/instance/tasks/present.yml190
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/instance/tasks/reinstall.yml28
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/instance/tasks/stop-start.yml78
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/instance/tasks/tests.yml70
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/instance_info/aliases3
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/instance_info/defaults/main.yml23
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/instance_info/meta/main.yml3
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/instance_info/tasks/main.yml7
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/instance_info/tasks/tests.yml62
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/os_info/aliases1
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/os_info/tasks/main.yml22
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/plan_info/aliases1
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/plan_info/tasks/main.yml22
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/plan_metal_info/aliases1
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/plan_metal_info/tasks/main.yml23
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/region_info/aliases1
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/region_info/tasks/main.yml22
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/reserved_ip/aliases0
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/reserved_ip/defaults/main.yml9
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/reserved_ip/meta/main.yml3
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/reserved_ip/tasks/main.yml10
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/reserved_ip/tasks/tests.yml240
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/snapshot/aliases3
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/snapshot/defaults/main.yml15
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/snapshot/meta/main.yml3
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/snapshot/tasks/absent.yml35
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/snapshot/tasks/failures.yml33
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/snapshot/tasks/main.yml10
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/snapshot/tasks/present.yml36
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/snapshot/tasks/tests.yml35
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/snapshot_info/aliases3
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/snapshot_info/defaults/main.yml3
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/snapshot_info/meta/main.yml3
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/snapshot_info/tasks/main.yml7
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/snapshot_info/tasks/tests.yml34
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/ssh_key/aliases3
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/ssh_key/defaults/main.yml6
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/ssh_key/meta/main.yml3
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/ssh_key/tasks/main.yml7
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/ssh_key/tasks/tests.yml140
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/ssh_key_info/aliases3
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/ssh_key_info/defaults/main.yml3
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/ssh_key_info/meta/main.yml3
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/ssh_key_info/tasks/main.yml7
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/ssh_key_info/tasks/tests.yml44
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/startup_script/aliases3
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/startup_script/defaults/main.yml6
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/startup_script/meta/main.yml3
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/startup_script/tasks/main.yml7
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/startup_script/tasks/tests.yml140
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/startup_script_info/aliases3
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/startup_script_info/defaults/main.yml4
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/startup_script_info/meta/main.yml3
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/startup_script_info/tasks/main.yml7
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/startup_script_info/tasks/tests.yml35
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/user/aliases3
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/user/defaults/main.yml4
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/user/meta/main.yml3
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/user/tasks/main.yml7
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/user/tasks/tests.yml218
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/user_info/aliases3
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/user_info/defaults/main.yml10
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/user_info/meta/main.yml3
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/user_info/tasks/main.yml7
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/user_info/tasks/tests.yml34
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/vpc/aliases3
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/vpc/defaults/main.yml5
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/vpc/meta/main.yml3
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/vpc/tasks/main.yml7
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/vpc/tasks/tests.yml112
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/vpc_info/aliases3
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/vpc_info/defaults/main.yml5
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/vpc_info/meta/main.yml3
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/vpc_info/tasks/main.yml7
-rw-r--r--ansible_collections/vultr/cloud/tests/integration/targets/vpc_info/tasks/tests.yml36
-rw-r--r--ansible_collections/vultr/cloud/tests/unit/plugins/inventory/fixtures/empty_vultr_inventory.json10
-rw-r--r--ansible_collections/vultr/cloud/tests/unit/plugins/inventory/fixtures/unauthorized_vultr_inventory.json4
-rw-r--r--ansible_collections/vultr/cloud/tests/unit/plugins/inventory/fixtures/vultr_inventory.json275
-rw-r--r--ansible_collections/vultr/cloud/tests/unit/plugins/inventory/fixtures/vultr_inventory_page1.json179
-rw-r--r--ansible_collections/vultr/cloud/tests/unit/plugins/inventory/fixtures/vultr_inventory_page2.json116
-rw-r--r--ansible_collections/vultr/cloud/tests/unit/plugins/inventory/test_vultr.py233
158 files changed, 4799 insertions, 0 deletions
diff --git a/ansible_collections/vultr/cloud/tests/integration/cloud-config-vultr.ini.template b/ansible_collections/vultr/cloud/tests/integration/cloud-config-vultr.ini.template
new file mode 100644
index 000000000..bdd336278
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/cloud-config-vultr.ini.template
@@ -0,0 +1,12 @@
+# This is the configuration template for ansible-test Vultr integration tests.
+#
+# You do not need this template if you are:
+#
+# 1) Running integration tests without using ansible-test.
+#
+# If you want to test against the Vultr public API,
+# fill in the values below and save this file without the .template extension.
+# This will cause ansible-test to use the given configuration.
+
+[default]
+key = ...
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/account_info/aliases b/ansible_collections/vultr/cloud/tests/integration/targets/account_info/aliases
new file mode 100644
index 000000000..1e9555644
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/account_info/aliases
@@ -0,0 +1,2 @@
+cloud/vultr
+smoke/vultr
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/account_info/tasks/main.yml b/ansible_collections/vultr/cloud/tests/integration/targets/account_info/tasks/main.yml
new file mode 100644
index 000000000..51f4d0ed9
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/account_info/tasks/main.yml
@@ -0,0 +1,27 @@
+# Copyright (c) 2021, René Moser <mail@renemoser.net>
+# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
+---
+- name: test get vultr account infos in check mode
+ vultr.cloud.account_info:
+ check_mode: true
+ register: result
+
+- name: verify test get vultr account infos in check mode
+ ansible.builtin.assert:
+ that:
+ - result.vultr_account_info.balance is defined
+ - result.vultr_account_info.last_payment_amount is defined
+ - result.vultr_account_info.last_payment_date is defined
+ - result.vultr_account_info.last_payment_amount is defined
+
+- name: test get vultr account fact
+ vultr.cloud.account_info:
+ register: result
+
+- name: verify test get vultr account infos
+ ansible.builtin.assert:
+ that:
+ - result.vultr_account_info.balance is defined
+ - result.vultr_account_info.last_payment_amount is defined
+ - result.vultr_account_info.last_payment_date is defined
+ - result.vultr_account_info.last_payment_amount is defined
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/block_storage/aliases b/ansible_collections/vultr/cloud/tests/integration/targets/block_storage/aliases
new file mode 100644
index 000000000..c749ce7ca
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/block_storage/aliases
@@ -0,0 +1,3 @@
+cloud/vultr
+needs/target/common
+needs/target/cleanup
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/block_storage/defaults/main.yml b/ansible_collections/vultr/cloud/tests/integration/targets/block_storage/defaults/main.yml
new file mode 100644
index 000000000..b47b70cda
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/block_storage/defaults/main.yml
@@ -0,0 +1,16 @@
+---
+vultr_block_storage_name: "{{ vultr_resource_prefix }}-volume"
+vultr_block_storage_size: 10
+vultr_block_storage_size_2: 12
+vultr_block_storage_size_3: 14
+
+vultr_block_storage_region: ewr
+
+vultr_block_storage_block_type: high_perf
+
+vultr_instance_name: "{{ vultr_resource_prefix }}_vm_for_attachment"
+vultr_instance_ssh_keys:
+ - name: "{{ vultr_resource_prefix }}_key1"
+ key: "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAgEAyWYItY+3w5b8PdGRoz0oY5mufqydW96naE+VM3JSvJFAUS08rAjQQpQ03ymoALeHQy6JVZbcgecxn6p0pAOINQdqufn4udPtOPCtMjNiPGpkSM9ah/6X5+kvyWMNrvlf+Ld4OOoszP5sAkgQzIbrFQAm41XknBUha0zkewZwfrVhain4pnDjV7wCcChId/Q/Gbi4xMtXkisznWcAJcueBs3EEZDKhJ5q0VeWSJEhYJDLFN1sOxF0AIUnMrOhfKQ/LjgREXPB6uCl899INUTXRNNjRpeMXyJ2wMMmOAbua2qEd1r13Bu1n+6A823Hzb33fyMXuqWnJwBJ4DCvMlGuEsfuOK+xk7DaBfLHbcM6fsPk0/4psTE6YLgC41remr6+u5ZWsY/faMtSnNPie8Z8Ov0DIYGdhbJjUXk1HomxRV9+ZfZ2Ob8iCwlaAQAyEUM6fs3Kxt8pBD8dx1HOkhsfBWPvuDr5y+kqE7H8/MuPDTc0QgH2pjUMpmw/XBwNDHshVEjrZvtICOjOLUJxcowLO1ivNYwPwowQxfisMy56LfYdjsOslBiqsrkAqvNGm1zu8wKHeqVN9w5l3yUELpvubfm9NKIvYcl6yWF36T0c5vE+g0DU/Jy4XpTj0hZG9QV2mRQcLJnd2pxQtJT7cPFtrn/+tgRxzjEtbDXummDV4sE= mail@renemoser.net"
+
+vultr_instance_plan: vc2-1c-1gb
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/block_storage/tasks/failures.yml b/ansible_collections/vultr/cloud/tests/integration/targets/block_storage/tasks/failures.yml
new file mode 100644
index 000000000..e588b0401
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/block_storage/tasks/failures.yml
@@ -0,0 +1,21 @@
+---
+- name: test fail if missing label
+ vultr.cloud.block_storage:
+ register: result
+ ignore_errors: true
+- name: verify test fail if missing label
+ ansible.builtin.assert:
+ that:
+ - result is failed
+ - 'result.msg == "missing required arguments: label"'
+
+- name: test fail if missing params for state=present
+ vultr.cloud.block_storage:
+ name: "{{ vultr_block_storage_name }}"
+ register: result
+ ignore_errors: true
+- name: verify fail if missing params for state=present
+ ansible.builtin.assert:
+ that:
+ - result is failed
+ - 'result.msg == "state is present but all of the following are missing: size_gb, region"'
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/block_storage/tasks/main.yml b/ansible_collections/vultr/cloud/tests/integration/targets/block_storage/tasks/main.yml
new file mode 100644
index 000000000..a6b410965
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/block_storage/tasks/main.yml
@@ -0,0 +1,16 @@
+---
+- block:
+ - ansible.builtin.import_tasks: failures.yml
+ - ansible.builtin.import_tasks: tests.yml
+ # TODO: make test more reliable
+ # - ansible.builtin.import_tasks: tests_attach_to_server.yml
+ always:
+ - ansible.builtin.import_role:
+ name: cleanup
+ tasks_from: cleanup_instance
+ - ansible.builtin.import_role:
+ name: cleanup
+ tasks_from: cleanup_ssh_key
+ - ansible.builtin.import_role:
+ name: cleanup
+ tasks_from: cleanup_block_storage
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/block_storage/tasks/tests.yml b/ansible_collections/vultr/cloud/tests/integration/targets/block_storage/tasks/tests.yml
new file mode 100644
index 000000000..ea1de2439
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/block_storage/tasks/tests.yml
@@ -0,0 +1,165 @@
+# Copyright (c) 2018, Yanis Guenane <yanis+ansible@guenane.org>
+# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
+---
+- name: setup ensure volume absent
+ vultr.cloud.block_storage:
+ label: "{{ vultr_block_storage_name }}"
+ state: absent
+
+- name: test create block storage volume in check mode
+ vultr.cloud.block_storage:
+ name: "{{ vultr_block_storage_name }}"
+ size_gb: "{{ vultr_block_storage_size }}"
+ block_type: "{{ vultr_block_storage_block_type }}"
+ region: "{{ vultr_block_storage_region }}"
+ register: result
+ check_mode: true
+- name: verify test create block storage volume in check mode
+ ansible.builtin.assert:
+ that:
+ - result is changed
+
+- name: test create block storage volume
+ vultr.cloud.block_storage:
+ label: "{{ vultr_block_storage_name }}"
+ size_gb: "{{ vultr_block_storage_size }}"
+ block_type: "{{ vultr_block_storage_block_type }}"
+ region: "{{ vultr_block_storage_region }}"
+ register: result
+- name: verify test create block storage volume
+ ansible.builtin.assert:
+ that:
+ - result is changed
+ - result.vultr_block_storage.label == vultr_block_storage_name
+ - result.vultr_block_storage.region == vultr_block_storage_region
+ - result.vultr_block_storage.size_gb == 10
+ - result.vultr_block_storage.block_type == vultr_block_storage_block_type
+
+- name: test create block storage volume idempotence
+ vultr.cloud.block_storage:
+ label: "{{ vultr_block_storage_name }}"
+ size_gb: "{{ vultr_block_storage_size }}"
+ block_type: "{{ vultr_block_storage_block_type }}"
+ region: "{{ vultr_block_storage_region }}"
+ register: result
+- name: verify test create block storage volume idempotence
+ ansible.builtin.assert:
+ that:
+ - result is not changed
+ - result.vultr_block_storage.label == vultr_block_storage_name
+ - result.vultr_block_storage.region == vultr_block_storage_region
+ - result.vultr_block_storage.size_gb == vultr_block_storage_size
+ - result.vultr_block_storage.block_type == vultr_block_storage_block_type
+
+- name: test shrink block storage ignored
+ vultr.cloud.block_storage:
+ label: "{{ vultr_block_storage_name }}"
+ size_gb: "{{ vultr_block_storage_size - 1 }}"
+ block_type: "{{ vultr_block_storage_block_type }}"
+ region: "{{ vultr_block_storage_region }}"
+ register: result
+- name: verify test shrink block storage ignored
+ ansible.builtin.assert:
+ that:
+ - result is not changed
+ - result.vultr_block_storage.label == vultr_block_storage_name
+ - result.vultr_block_storage.region == vultr_block_storage_region
+ - result.vultr_block_storage.size_gb == vultr_block_storage_size
+ - result.vultr_block_storage.block_type == vultr_block_storage_block_type
+
+# volumes size can only be modified every 60s
+- name: wait about 60s before resizing volume
+ wait_for:
+ timeout: 61
+
+- name: test resize block storage volume in check mode
+ vultr.cloud.block_storage:
+ label: "{{ vultr_block_storage_name }}"
+ size_gb: "{{ vultr_block_storage_size_2 }}"
+ block_type: "{{ vultr_block_storage_block_type }}"
+ region: "{{ vultr_block_storage_region }}"
+ register: result
+ check_mode: true
+- name: verify test resize block storage volume in check mode
+ ansible.builtin.assert:
+ that:
+ - result is changed
+ - result.vultr_block_storage.size_gb == vultr_block_storage_size
+
+- name: test resize block storage volume
+ vultr.cloud.block_storage:
+ label: "{{ vultr_block_storage_name }}"
+ size_gb: "{{ vultr_block_storage_size_2 }}"
+ block_type: "{{ vultr_block_storage_block_type }}"
+ region: "{{ vultr_block_storage_region }}"
+ register: result
+- name: verify test resize block storage volume
+ ansible.builtin.assert:
+ that:
+ - result is changed
+ - result.vultr_block_storage.size_gb == vultr_block_storage_size_2
+
+- name: test resize block storage volume idempotency
+ vultr.cloud.block_storage:
+ label: "{{ vultr_block_storage_name }}"
+ size_gb: "{{ vultr_block_storage_size_2 }}"
+ block_type: "{{ vultr_block_storage_block_type }}"
+ region: "{{ vultr_block_storage_region }}"
+ register: result
+- name: verify test resize block storage volume idempotency
+ ansible.builtin.assert:
+ that:
+ - result is not changed
+ - result.vultr_block_storage.size_gb == vultr_block_storage_size_2
+
+- name: wait about 60s before resizing volume
+ wait_for:
+ timeout: 61
+
+- name: test shrinking warning block storage volume
+ vultr.cloud.block_storage:
+ label: "{{ vultr_block_storage_name }}"
+ size_gb: "{{ vultr_block_storage_size }}"
+ block_type: "{{ vultr_block_storage_block_type }}"
+ region: "{{ vultr_block_storage_region }}"
+ register: result
+- name: verify test shrinking warning block storage volume
+ ansible.builtin.assert:
+ that:
+ - result is not changed
+ - result.vultr_block_storage.size_gb == vultr_block_storage_size_2
+
+- name: test destroy block storage volume in check mode
+ vultr.cloud.block_storage:
+ label: "{{ vultr_block_storage_name }}"
+ state: absent
+ check_mode: true
+ register: result
+- name: verify test destroy block storage volume in check mode
+ ansible.builtin.assert:
+ that:
+ - result is changed
+ - result.vultr_block_storage.label == vultr_block_storage_name
+ - result.vultr_block_storage.block_type == vultr_block_storage_block_type
+
+- name: test destroy block storage volume
+ vultr.cloud.block_storage:
+ label: "{{ vultr_block_storage_name }}"
+ state: absent
+ register: result
+- name: verify test destroy block storage volume
+ ansible.builtin.assert:
+ that:
+ - result is changed
+ - result.vultr_block_storage.label == vultr_block_storage_name
+ - result.vultr_block_storage.block_type == vultr_block_storage_block_type
+
+- name: test destroy block storage volume idempotence
+ vultr.cloud.block_storage:
+ name: "{{ vultr_block_storage_name }}"
+ state: absent
+ register: result
+- name: verify test destroy block storage volume idempotence
+ ansible.builtin.assert:
+ that:
+ - result is not changed
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/block_storage/tasks/tests_attach_to_server.yml b/ansible_collections/vultr/cloud/tests/integration/targets/block_storage/tasks/tests_attach_to_server.yml
new file mode 100644
index 000000000..efb0ab558
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/block_storage/tasks/tests_attach_to_server.yml
@@ -0,0 +1,151 @@
+# Copyright (c) 2018, Yanis Guenane <yanis+ansible@guenane.org>
+# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
+---
+- name: setup create ssh keys
+ vultr.cloud.ssh_key:
+ name: "{{ item.name }}"
+ ssh_key: "{{ item.key }}"
+ loop: "{{ vultr_instance_ssh_keys }}"
+
+- name: setup create server
+ vultr.cloud.instance:
+ label: "{{ vultr_instance_name }}"
+ os: Debian 11 x64 (bullseye)
+ plan: "{{ vultr_instance_plan }}"
+ ssh_keys:
+ - "{{ vultr_resource_prefix }}_key1"
+ region: "{{ vultr_block_storage_region }}"
+ register: result_server_setup
+
+- name: wait some time
+ wait_for:
+ timeout: 20
+
+- name: setup block storage volume unattached
+ vultr.cloud.block_storage:
+ label: "{{ vultr_block_storage_name }}"
+ size_gb: "{{ vultr_block_storage_size }}"
+ block_type: "{{ vultr_block_storage_block_type }}"
+ region: "{{ vultr_block_storage_region }}"
+ attached_to_instance: ""
+ register: result
+- name: verify test create block storage volume
+ ansible.builtin.assert:
+ that:
+ - result is changed
+ - not result.vultr_block_storage.attached_to_instance
+ - result.vultr_block_storage.label == vultr_block_storage_name
+ - result.vultr_block_storage.region == vultr_block_storage_region
+ - result.vultr_block_storage.size_gb == 10
+
+- name: test attach block volume in check mode
+ vultr.cloud.block_storage:
+ label: "{{ vultr_block_storage_name }}"
+ size_gb: "{{ vultr_block_storage_size }}"
+ block_type: "{{ vultr_block_storage_block_type }}"
+ region: "{{ vultr_block_storage_region }}"
+ attached_to_instance: "{{ result_server_setup.vultr_instance.id }}"
+ register: result
+ check_mode: true
+- name: verify test attach block volume in check mode
+ ansible.builtin.assert:
+ that:
+ - result is changed
+ - not result.vultr_block_storage.attached_to_instance
+
+- name: test attach block volume
+ vultr.cloud.block_storage:
+ label: "{{ vultr_block_storage_name }}"
+ size_gb: "{{ vultr_block_storage_size }}"
+ block_type: "{{ vultr_block_storage_block_type }}"
+ region: "{{ vultr_block_storage_region }}"
+ attached_to_instance: "{{ result_server_setup.vultr_instance.id }}"
+ register: result
+ until: "'fetch_url_info' not in result or result.fetch_url_info.find('unable to attach') != -1"
+ retries: 3
+ delay: 10
+- name: verify test attach block volume
+ ansible.builtin.assert:
+ that:
+ - result.changed
+ - result.vultr_block_storage.attached_to_instance == result_server_setup.vultr_instance.id
+
+- name: test attach block volume idempotency
+ vultr.cloud.block_storage:
+ label: "{{ vultr_block_storage_name }}"
+ size_gb: "{{ vultr_block_storage_size }}"
+ block_type: "{{ vultr_block_storage_block_type }}"
+ region: "{{ vultr_block_storage_region }}"
+ attached_to_instance: "{{ result_server_setup.vultr_instance.id }}"
+ register: result
+- name: verify test attach block volume idempotency
+ ansible.builtin.assert:
+ that:
+ - not result.changed
+ - result.vultr_block_storage.attached_to_instance == result_server_setup.vultr_instance.id
+
+# volume size can only be modified every 60s
+- name: wait about 60s before resizing volume
+ wait_for:
+ timeout: 61
+
+- name: test resize block storage volume while attached
+ vultr.cloud.block_storage:
+ label: "{{ vultr_block_storage_name }}"
+ size_gb: "{{ vultr_block_storage_size_2 }}"
+ block_type: "{{ vultr_block_storage_block_type }}"
+ region: "{{ vultr_block_storage_region }}"
+ attached_to_instance: "{{ result_server_setup.vultr_instance.id }}"
+ register: result
+- name: verify test resize block storage volume while attached
+ ansible.builtin.assert:
+ that:
+ - result is changed
+ - result.vultr_block_storage.attached_to_instance == result_server_setup.vultr_instance.id
+
+- name: wait about 60s
+ wait_for:
+ timeout: 61
+
+- name: test detach block volume in check mode
+ vultr.cloud.block_storage:
+ label: "{{ vultr_block_storage_name }}"
+ size_gb: "{{ vultr_block_storage_size_2 }}"
+ block_type: "{{ vultr_block_storage_block_type }}"
+ region: "{{ vultr_block_storage_region }}"
+ attached_to_instance: ""
+ register: result
+ check_mode: true
+- name: verify test detach block volume in check mode
+ ansible.builtin.assert:
+ that:
+ - result is changed
+ - result.vultr_block_storage.attached_to_instance == result_server_setup.vultr_instance.id
+
+- name: test detach block volume
+ vultr.cloud.block_storage:
+ label: "{{ vultr_block_storage_name }}"
+ size_gb: "{{ vultr_block_storage_size_2 }}"
+ block_type: "{{ vultr_block_storage_block_type }}"
+ region: "{{ vultr_block_storage_region }}"
+ attached_to_instance: ""
+ register: result
+- name: verify test detach block volume
+ ansible.builtin.assert:
+ that:
+ - result is changed
+ - not result.vultr_block_storage.attached_to_instance
+
+- name: test detach block volume idempotency
+ vultr.cloud.block_storage:
+ label: "{{ vultr_block_storage_name }}"
+ size_gb: "{{ vultr_block_storage_size_2 }}"
+ block_type: "{{ vultr_block_storage_block_type }}"
+ region: "{{ vultr_block_storage_region }}"
+ attached_to_instance: ""
+ register: result
+- name: verify test detach block volume idempotency
+ ansible.builtin.assert:
+ that:
+ - result is not changed
+ - not result.vultr_block_storage.attached_to_instance
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/block_storage_info/aliases b/ansible_collections/vultr/cloud/tests/integration/targets/block_storage_info/aliases
new file mode 100644
index 000000000..c749ce7ca
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/block_storage_info/aliases
@@ -0,0 +1,3 @@
+cloud/vultr
+needs/target/common
+needs/target/cleanup
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/block_storage_info/defaults/main.yml b/ansible_collections/vultr/cloud/tests/integration/targets/block_storage_info/defaults/main.yml
new file mode 100644
index 000000000..8e433a2aa
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/block_storage_info/defaults/main.yml
@@ -0,0 +1,7 @@
+---
+vultr_resource_prefix: "vultr-test-prefix"
+vultr_block_storage_name: "{{ vultr_resource_prefix }}-volume"
+vultr_block_storage_size: 10
+vultr_block_storage_region: ewr
+
+vultr_block_storage_block_type: high_perf
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/block_storage_info/tasks/main.yml b/ansible_collections/vultr/cloud/tests/integration/targets/block_storage_info/tasks/main.yml
new file mode 100644
index 000000000..bb27c3b95
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/block_storage_info/tasks/main.yml
@@ -0,0 +1,7 @@
+---
+- block:
+ - ansible.builtin.import_tasks: tests.yml
+ always:
+ - ansible.builtin.import_role:
+ name: cleanup
+ tasks_from: cleanup_block_storage
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/block_storage_info/tasks/tests.yml b/ansible_collections/vultr/cloud/tests/integration/targets/block_storage_info/tasks/tests.yml
new file mode 100644
index 000000000..2f836ea09
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/block_storage_info/tasks/tests.yml
@@ -0,0 +1,36 @@
+# Copyright (c) 2018, Yanis Guenane <yanis+ansible@guenane.org>
+# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
+---
+- name: test gather vultr block storage volume info - empty resource
+ vultr.cloud.block_storage_info:
+
+- name: Create the block storage volume
+ vultr.cloud.block_storage:
+ label: "{{ vultr_block_storage_name }}"
+ size_gb: "{{ vultr_block_storage_size }}"
+ region: "{{ vultr_block_storage_region }}"
+ block_type: "{{ vultr_block_storage_block_type }}"
+
+- name: test gather vultr block storage volume info in check mode
+ vultr.cloud.block_storage_info:
+ check_mode: true
+ register: result
+
+- name: verify test gather vultr block storage volume info in check mode
+ ansible.builtin.assert:
+ that:
+ - result.vultr_block_storage_info|selectattr('label','equalto','{{ vultr_block_storage_name }}') | list | count == 1
+
+- name: test gather vultr block storage volume info
+ vultr.cloud.block_storage_info:
+ register: result
+
+- name: verify test gather vultr block storage volume info
+ ansible.builtin.assert:
+ that:
+ - result.vultr_block_storage_info|selectattr('label','equalto','{{ vultr_block_storage_name }}') | list | count == 1
+
+- name: Delete the block storage volume
+ vultr.cloud.block_storage:
+ label: "{{ vultr_block_storage_name }}"
+ state: absent
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/cleanup/aliases b/ansible_collections/vultr/cloud/tests/integration/targets/cleanup/aliases
new file mode 100644
index 000000000..136c05e0d
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/cleanup/aliases
@@ -0,0 +1 @@
+hidden
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/cleanup/defaults/main.yml b/ansible_collections/vultr/cloud/tests/integration/targets/cleanup/defaults/main.yml
new file mode 100644
index 000000000..02ff5e549
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/cleanup/defaults/main.yml
@@ -0,0 +1,3 @@
+---
+vultr_api_url: https://api.vultr.com/v2
+vultr_api_key: "{{ lookup('env', 'VULTR_API_KEY') }}"
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/cleanup/meta/main.yml b/ansible_collections/vultr/cloud/tests/integration/targets/cleanup/meta/main.yml
new file mode 100644
index 000000000..2083f0e12
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/cleanup/meta/main.yml
@@ -0,0 +1,3 @@
+---
+dependencies:
+ - common
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/cleanup/tasks/cleanup_block_storage.yml b/ansible_collections/vultr/cloud/tests/integration/targets/cleanup/tasks/cleanup_block_storage.yml
new file mode 100644
index 000000000..cc25e8076
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/cleanup/tasks/cleanup_block_storage.yml
@@ -0,0 +1,29 @@
+---
+- name: cleanup
+ when: vultr_api_key
+ block:
+ - name: List blocks
+ ansible.builtin.uri:
+ url: "{{ vultr_api_url }}/blocks"
+ headers:
+ Authorization: Bearer {{ vultr_api_key }}
+ status_code: 200
+ register: res
+ no_log: true
+
+ - name: Found resources
+ ansible.builtin.debug:
+ var: res.json
+
+ - name: Remove all blocks created by this test run
+ ansible.builtin.uri:
+ url: "{{ vultr_api_url }}/blocks/{{ item.id }}"
+ method: "DELETE"
+ headers:
+ Authorization: Bearer {{ vultr_api_key }}
+ status_code: 204
+ when: vultr_resource_prefix in item.label
+ with_items: "{{ res.json.blocks }}"
+ loop_control:
+ label: "{{ item.label }}"
+ no_log: true
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/cleanup/tasks/cleanup_dns_domain.yml b/ansible_collections/vultr/cloud/tests/integration/targets/cleanup/tasks/cleanup_dns_domain.yml
new file mode 100644
index 000000000..47eeefac5
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/cleanup/tasks/cleanup_dns_domain.yml
@@ -0,0 +1,29 @@
+---
+- name: cleanup
+ when: vultr_api_key
+ block:
+ - name: List dns domains
+ ansible.builtin.uri:
+ url: "{{ vultr_api_url }}/domains"
+ headers:
+ Authorization: Bearer {{ vultr_api_key }}
+ status_code: 200
+ register: res
+ no_log: true
+
+ - name: Found resources
+ ansible.builtin.debug:
+ var: res.json
+
+ - name: Remove all dns domains created by this test run
+ ansible.builtin.uri:
+ url: "{{ vultr_api_url }}/domains/{{ item.domain }}"
+ method: "DELETE"
+ headers:
+ Authorization: Bearer {{ vultr_api_key }}
+ status_code: 204
+ when: vultr_resource_prefix in item.domain
+ with_items: "{{ res.json.domains }}"
+ loop_control:
+ label: "{{ item.domain }}"
+ no_log: true
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/cleanup/tasks/cleanup_firewall_group.yml b/ansible_collections/vultr/cloud/tests/integration/targets/cleanup/tasks/cleanup_firewall_group.yml
new file mode 100644
index 000000000..74f9f4af4
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/cleanup/tasks/cleanup_firewall_group.yml
@@ -0,0 +1,28 @@
+---
+- name: cleanup
+ when: vultr_api_key
+ block:
+ - name: List firewall groups
+ ansible.builtin.uri:
+ url: "{{ vultr_api_url }}/firewalls"
+ headers:
+ Authorization: Bearer {{ vultr_api_key }}
+ status_code: 200
+ register: res
+ no_log: true
+
+ - name: Found resources
+ ansible.builtin.debug:
+ var: res.json
+
+ - name: Remove all firewall groups created by this test run
+ ansible.builtin.uri:
+ url: "{{ vultr_api_url }}/firewalls/{{ item.id }}"
+ method: "DELETE"
+ headers:
+ Authorization: Bearer {{ vultr_api_key }}
+ status_code: 204
+ when: vultr_resource_prefix in item.description
+ with_items: "{{ res.json.firewall_groups }}"
+ loop_control:
+ label: "{{ item.description }}"
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/cleanup/tasks/cleanup_instance.yml b/ansible_collections/vultr/cloud/tests/integration/targets/cleanup/tasks/cleanup_instance.yml
new file mode 100644
index 000000000..cad956b39
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/cleanup/tasks/cleanup_instance.yml
@@ -0,0 +1,29 @@
+---
+- name: cleanup
+ when: vultr_api_key
+ block:
+ - name: List instances
+ ansible.builtin.uri:
+ url: "{{ vultr_api_url }}/instances"
+ headers:
+ Authorization: Bearer {{ vultr_api_key }}
+ status_code: 200
+ register: res
+ no_log: true
+
+ - name: Found resources
+ ansible.builtin.debug:
+ var: res.json
+
+ - name: Remove all instances created by this test run
+ ansible.builtin.uri:
+ url: "{{ vultr_api_url }}/instances/{{ item.id }}"
+ method: "DELETE"
+ headers:
+ Authorization: Bearer {{ vultr_api_key }}
+ status_code: 204
+ when: vultr_resource_prefix in item.label
+ with_items: "{{ res.json.instances }}"
+ loop_control:
+ label: "{{ item.label }}"
+ no_log: true
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/cleanup/tasks/cleanup_network.yml b/ansible_collections/vultr/cloud/tests/integration/targets/cleanup/tasks/cleanup_network.yml
new file mode 100644
index 000000000..3d82d93e5
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/cleanup/tasks/cleanup_network.yml
@@ -0,0 +1,29 @@
+---
+- name: cleanup
+ when: vultr_api_key
+ block:
+ - name: List networks
+ ansible.builtin.uri:
+ url: "{{ vultr_api_url }}/private-networks"
+ headers:
+ Authorization: Bearer {{ vultr_api_key }}
+ status_code: 200
+ register: res
+ no_log: true
+
+ - name: Found resources
+ ansible.builtin.debug:
+ var: res.json
+
+ - name: Remove all networks created by this test run
+ ansible.builtin.uri:
+ url: "{{ vultr_api_url }}/private-networks/{{ item.id }}"
+ method: "DELETE"
+ headers:
+ Authorization: Bearer {{ vultr_api_key }}
+ status_code: 204
+ when: vultr_resource_prefix in item.description
+ with_items: "{{ res.json.networks }}"
+ loop_control:
+ label: "{{ item.description }}"
+ no_log: true
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/cleanup/tasks/cleanup_reserved_ip.yml b/ansible_collections/vultr/cloud/tests/integration/targets/cleanup/tasks/cleanup_reserved_ip.yml
new file mode 100644
index 000000000..7be9c46f4
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/cleanup/tasks/cleanup_reserved_ip.yml
@@ -0,0 +1,29 @@
+---
+- name: cleanup
+ when: vultr_api_key
+ block:
+ - name: List reserved-ips
+ ansible.builtin.uri:
+ url: "{{ vultr_api_url }}/reserved-ips"
+ headers:
+ Authorization: Bearer {{ vultr_api_key }}
+ status_code: 200
+ register: res
+ no_log: true
+
+ - name: Found resources
+ ansible.builtin.debug:
+ var: res.json
+
+ - name: Remove all reserved-ips created by this test run
+ ansible.builtin.uri:
+ url: "{{ vultr_api_url }}/reserved-ips/{{ item.id }}"
+ method: "DELETE"
+ headers:
+ Authorization: Bearer {{ vultr_api_key }}
+ status_code: 204
+ when: vultr_resource_prefix in item.label
+ with_items: "{{ res.json.reserved_ips }}"
+ loop_control:
+ label: "{{ item.label }}"
+ no_log: true
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/cleanup/tasks/cleanup_snapshot.yml b/ansible_collections/vultr/cloud/tests/integration/targets/cleanup/tasks/cleanup_snapshot.yml
new file mode 100644
index 000000000..90200bbcd
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/cleanup/tasks/cleanup_snapshot.yml
@@ -0,0 +1,29 @@
+---
+- name: cleanup
+ when: vultr_api_key
+ block:
+ - name: List snapshots
+ ansible.builtin.uri:
+ url: "{{ vultr_api_url }}/snapshots"
+ headers:
+ Authorization: Bearer {{ vultr_api_key }}
+ status_code: 200
+ register: res
+ no_log: true
+
+ - name: Found resources
+ ansible.builtin.debug:
+ var: res.json
+
+ - name: Remove all snapshots created by this test run
+ ansible.builtin.uri:
+ url: "{{ vultr_api_url }}/snapshots/{{ item.id }}"
+ method: "DELETE"
+ headers:
+ Authorization: Bearer {{ vultr_api_key }}
+ status_code: 204
+ when: vultr_resource_prefix in item.description
+ with_items: "{{ res.json.snapshots }}"
+ loop_control:
+ label: "{{ item.description }}"
+ no_log: true
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/cleanup/tasks/cleanup_ssh_key.yml b/ansible_collections/vultr/cloud/tests/integration/targets/cleanup/tasks/cleanup_ssh_key.yml
new file mode 100644
index 000000000..c217d4f39
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/cleanup/tasks/cleanup_ssh_key.yml
@@ -0,0 +1,29 @@
+---
+- name: cleanup
+ when: vultr_api_key
+ block:
+ - name: List ssh-keys
+ ansible.builtin.uri:
+ url: "{{ vultr_api_url }}/ssh-keys"
+ headers:
+ Authorization: Bearer {{ vultr_api_key }}
+ status_code: 200
+ register: res
+ no_log: true
+
+ - name: Found resources
+ ansible.builtin.debug:
+ var: res.json
+
+ - name: Remove all ssh-keys created by this test run
+ ansible.builtin.uri:
+ url: "{{ vultr_api_url }}/ssh-keys/{{ item.id }}"
+ method: "DELETE"
+ headers:
+ Authorization: Bearer {{ vultr_api_key }}
+ status_code: 204
+ when: vultr_resource_prefix in item.name
+ with_items: "{{ res.json.ssh_keys }}"
+ loop_control:
+ label: "{{ item.name }}"
+ no_log: true
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/cleanup/tasks/cleanup_startup_script.yml b/ansible_collections/vultr/cloud/tests/integration/targets/cleanup/tasks/cleanup_startup_script.yml
new file mode 100644
index 000000000..3201dbdcb
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/cleanup/tasks/cleanup_startup_script.yml
@@ -0,0 +1,29 @@
+---
+- name: cleanup
+ when: vultr_api_key
+ block:
+ - name: List startup-scripts
+ ansible.builtin.uri:
+ url: "{{ vultr_api_url }}/startup-scripts"
+ headers:
+ Authorization: Bearer {{ vultr_api_key }}
+ status_code: 200
+ register: res
+ no_log: true
+
+ - name: Found resources
+ ansible.builtin.debug:
+ var: res.json
+
+ - name: Remove all startup-scripts created by this test run
+ ansible.builtin.uri:
+ url: "{{ vultr_api_url }}/startup-scripts/{{ item.id }}"
+ method: "DELETE"
+ headers:
+ Authorization: Bearer {{ vultr_api_key }}
+ status_code: 204
+ when: vultr_resource_prefix in item.name
+ with_items: "{{ res.json.startup_scripts }}"
+ loop_control:
+ label: "{{ item.name }}"
+ no_log: true
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/cleanup/tasks/cleanup_user.yml b/ansible_collections/vultr/cloud/tests/integration/targets/cleanup/tasks/cleanup_user.yml
new file mode 100644
index 000000000..cd3173efa
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/cleanup/tasks/cleanup_user.yml
@@ -0,0 +1,29 @@
+---
+- name: cleanup
+ when: vultr_api_key
+ block:
+ - name: List users
+ ansible.builtin.uri:
+ url: "{{ vultr_api_url }}/users"
+ headers:
+ Authorization: Bearer {{ vultr_api_key }}
+ status_code: 200
+ register: res
+ no_log: true
+
+ - name: Found resources
+ ansible.builtin.debug:
+ var: res.json
+
+ - name: Remove all users created by this test run
+ ansible.builtin.uri:
+ url: "{{ vultr_api_url }}/users/{{ item.id }}"
+ method: "DELETE"
+ headers:
+ Authorization: Bearer {{ vultr_api_key }}
+ status_code: 204
+ when: vultr_resource_prefix in item.name
+ with_items: "{{ res.json.users }}"
+ loop_control:
+ label: "{{ item.name }}"
+ no_log: true
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/cleanup/tasks/cleanup_vpc.yml b/ansible_collections/vultr/cloud/tests/integration/targets/cleanup/tasks/cleanup_vpc.yml
new file mode 100644
index 000000000..f0c8e2b5c
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/cleanup/tasks/cleanup_vpc.yml
@@ -0,0 +1,33 @@
+---
+- name: cleanup
+ when: vultr_api_key
+ block:
+ - name: List vpcs
+ ansible.builtin.uri:
+ url: "{{ vultr_api_url }}/vpcs"
+ headers:
+ Authorization: Bearer {{ vultr_api_key }}
+ status_code: 200
+ register: res
+ no_log: true
+
+ - name: Found resources
+ ansible.builtin.debug:
+ var: res.json
+
+ - name: Remove all vpcs created by this test run
+ ansible.builtin.uri:
+ url: "{{ vultr_api_url }}/vpcs/{{ item.id }}"
+ method: "DELETE"
+ headers:
+ Authorization: Bearer {{ vultr_api_key }}
+ status_code: 204
+ when: vultr_resource_prefix in item.description
+ with_items: "{{ res.json.vpcs }}"
+ loop_control:
+ label: "{{ item.description }}"
+ pause: 2
+ retries: 5
+ delay: 3
+ register: result
+ until: result is not failed
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/common/aliases b/ansible_collections/vultr/cloud/tests/integration/targets/common/aliases
new file mode 100644
index 000000000..136c05e0d
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/common/aliases
@@ -0,0 +1 @@
+hidden
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/common/default/main.yml b/ansible_collections/vultr/cloud/tests/integration/targets/common/default/main.yml
new file mode 100644
index 000000000..1885f66e2
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/common/default/main.yml
@@ -0,0 +1,4 @@
+# Copyright (c) 2022, René Moser <mail@renemoser.net>
+# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
+---
+vultr_resource_prefix: "{{ lookup('env', 'VULTR_RESOURCE_PREFIX') }}"
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/dns_domain/aliases b/ansible_collections/vultr/cloud/tests/integration/targets/dns_domain/aliases
new file mode 100644
index 000000000..c749ce7ca
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/dns_domain/aliases
@@ -0,0 +1,3 @@
+cloud/vultr
+needs/target/common
+needs/target/cleanup
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/dns_domain/defaults/main.yml b/ansible_collections/vultr/cloud/tests/integration/targets/dns_domain/defaults/main.yml
new file mode 100644
index 000000000..1f2f9a16a
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/dns_domain/defaults/main.yml
@@ -0,0 +1,4 @@
+# Copyright (c) 2018, René Moser <mail@renemoser.net>
+# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
+---
+vultr_dns_domain_name: "{{ vultr_resource_prefix }}-t1-vultr.com"
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/dns_domain/meta/main.yml b/ansible_collections/vultr/cloud/tests/integration/targets/dns_domain/meta/main.yml
new file mode 100644
index 000000000..2083f0e12
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/dns_domain/meta/main.yml
@@ -0,0 +1,3 @@
+---
+dependencies:
+ - common
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/dns_domain/tasks/main.yml b/ansible_collections/vultr/cloud/tests/integration/targets/dns_domain/tasks/main.yml
new file mode 100644
index 000000000..b26b845b3
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/dns_domain/tasks/main.yml
@@ -0,0 +1,13 @@
+---
+- block:
+ - ansible.builtin.import_tasks: tests.yml
+ always:
+ - name: cleanup dns domain
+ vultr.cloud.dns_domain:
+ name: "{{ vultr_dns_domain_name }}"
+ state: absent
+ ignore_errors: true
+
+ - ansible.builtin.import_role:
+ name: cleanup
+ tasks_from: cleanup_dns_domain
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/dns_domain/tasks/tests.yml b/ansible_collections/vultr/cloud/tests/integration/targets/dns_domain/tasks/tests.yml
new file mode 100644
index 000000000..d688ad12d
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/dns_domain/tasks/tests.yml
@@ -0,0 +1,138 @@
+# Copyright (c) 2021, René Moser <mail@renemoser.net>
+# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
+---
+- name: setup
+ vultr.cloud.dns_domain:
+ name: "{{ vultr_dns_domain_name }}"
+ state: absent
+
+- name: test fail if missing name
+ vultr.cloud.dns_domain:
+ register: result
+ ignore_errors: true
+- name: verify test fail if missing name
+ ansible.builtin.assert:
+ that:
+ - result is failed
+ - 'result.msg == "missing required arguments: domain"'
+
+- name: test fail if missing params for state=present
+ vultr.cloud.dns_domain:
+ name: "{{ vultr_dns_domain_name }}"
+ register: result
+ ignore_errors: true
+- name: verify fail if missing params for state=present
+ ansible.builtin.assert:
+ that:
+ - result is failed
+ - 'result.msg == "state is present but all of the following are missing: ip"'
+
+- name: test create dns domain in check mode
+ vultr.cloud.dns_domain:
+ name: "{{ vultr_dns_domain_name }}"
+ dns_sec: enabled
+ server_ip: 10.10.10.10
+ register: result
+ check_mode: true
+- name: verify test create dns domain in check mode
+ ansible.builtin.assert:
+ that:
+ - result is changed
+
+- name: test create dns domain
+ vultr.cloud.dns_domain:
+ name: "{{ vultr_dns_domain_name }}"
+ dns_sec: enabled
+ server_ip: 10.10.10.10
+ register: result
+- name: verify test create dns domain
+ ansible.builtin.assert:
+ that:
+ - result is changed
+ - result.vultr_dns_domain.domain == vultr_dns_domain_name
+ - result.vultr_dns_domain.dns_sec == 'enabled'
+
+- name: test create dns domain idempotence
+ vultr.cloud.dns_domain:
+ name: "{{ vultr_dns_domain_name }}"
+ dns_sec: enabled
+ server_ip: 10.10.10.10
+ register: result
+- name: verify test create dns domain idempotence
+ ansible.builtin.assert:
+ that:
+ - result is not changed
+ - result.vultr_dns_domain.domain == vultr_dns_domain_name
+ - result.vultr_dns_domain.dns_sec == 'enabled'
+
+- name: test update dns domain in check mode
+ vultr.cloud.dns_domain:
+ name: "{{ vultr_dns_domain_name }}"
+ dns_sec: disabled
+ server_ip: 10.10.10.10
+ register: result
+ check_mode: true
+- name: verify test create dns domain in check mode
+ ansible.builtin.assert:
+ that:
+ - result is changed
+ - result.vultr_dns_domain.dns_sec == 'enabled'
+
+- name: test update dns domain
+ vultr.cloud.dns_domain:
+ name: "{{ vultr_dns_domain_name }}"
+ dns_sec: disabled
+ server_ip: 10.10.10.10
+ register: result
+- name: verify test create dns domain
+ ansible.builtin.assert:
+ that:
+ - result is changed
+ - result.vultr_dns_domain.domain == vultr_dns_domain_name
+ - result.vultr_dns_domain.dns_sec == 'disabled'
+
+- name: test update dns domain idempotence
+ vultr.cloud.dns_domain:
+ name: "{{ vultr_dns_domain_name }}"
+ dns_sec: disabled
+ server_ip: 10.10.10.10
+ register: result
+- name: verify test create dns domain idempotence
+ ansible.builtin.assert:
+ that:
+ - result is not changed
+ - result.vultr_dns_domain.domain == vultr_dns_domain_name
+ - result.vultr_dns_domain.dns_sec == 'disabled'
+
+- name: test absent dns domain in check mode
+ vultr.cloud.dns_domain:
+ name: "{{ vultr_dns_domain_name }}"
+ state: absent
+ register: result
+ check_mode: true
+- name: verify test absent dns domain in check mode
+ ansible.builtin.assert:
+ that:
+ - result is changed
+ - result.vultr_dns_domain.domain == vultr_dns_domain_name
+
+- name: test absent dns domain
+ vultr.cloud.dns_domain:
+ name: "{{ vultr_dns_domain_name }}"
+ state: absent
+ register: result
+- name: verify test absent dns domain
+ ansible.builtin.assert:
+ that:
+ - result is changed
+ - result.vultr_dns_domain.domain == vultr_dns_domain_name
+
+- name: test absent dns domain idempotence
+ vultr.cloud.dns_domain:
+ name: "{{ vultr_dns_domain_name }}"
+ state: absent
+ register: result
+- name: verify test absent dns domain idempotence
+ ansible.builtin.assert:
+ that:
+ - result is not changed
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/dns_domain_info/aliases b/ansible_collections/vultr/cloud/tests/integration/targets/dns_domain_info/aliases
new file mode 100644
index 000000000..c749ce7ca
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/dns_domain_info/aliases
@@ -0,0 +1,3 @@
+cloud/vultr
+needs/target/common
+needs/target/cleanup
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/dns_domain_info/defaults/main.yml b/ansible_collections/vultr/cloud/tests/integration/targets/dns_domain_info/defaults/main.yml
new file mode 100644
index 000000000..23d527820
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/dns_domain_info/defaults/main.yml
@@ -0,0 +1,3 @@
+---
+dns_domain_name: "{{ vultr_resource_prefix }}-t2-vultr.com"
+dns_domain_server_ip: 104.24.16.59
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/dns_domain_info/meta/main.yml b/ansible_collections/vultr/cloud/tests/integration/targets/dns_domain_info/meta/main.yml
new file mode 100644
index 000000000..2083f0e12
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/dns_domain_info/meta/main.yml
@@ -0,0 +1,3 @@
+---
+dependencies:
+ - common
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/dns_domain_info/tasks/main.yml b/ansible_collections/vultr/cloud/tests/integration/targets/dns_domain_info/tasks/main.yml
new file mode 100644
index 000000000..3f65737a7
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/dns_domain_info/tasks/main.yml
@@ -0,0 +1,13 @@
+---
+- block:
+ - ansible.builtin.import_tasks: tests.yml
+ always:
+ - name: cleanup the domain
+ vultr.cloud.dns_domain:
+ name: "{{ dns_domain_name }}"
+ state: absent
+ ignore_errors: true
+
+ - ansible.builtin.import_role:
+ name: cleanup
+ tasks_from: cleanup_dns_domain
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/dns_domain_info/tasks/tests.yml b/ansible_collections/vultr/cloud/tests/integration/targets/dns_domain_info/tasks/tests.yml
new file mode 100644
index 000000000..f772ab637
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/dns_domain_info/tasks/tests.yml
@@ -0,0 +1,27 @@
+# Copyright (c) 2018, Yanis Guenane <yanis+ansible@guenane.org>
+# Copyright (c) 2021, René Moser <mail@renemoser.net>
+# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
+---
+- name: Create a domain
+ vultr.cloud.dns_domain:
+ name: "{{ dns_domain_name }}"
+ server_ip: "{{ dns_domain_server_ip }}"
+
+- name: test gather vultr dns domain info in check mode
+ vultr.cloud.dns_domain_info:
+ check_mode: true
+ register: result
+
+- name: verify test gather vultr dns domain info in check mode
+ ansible.builtin.assert:
+ that:
+ - result.vultr_dns_domain_info|selectattr('domain','equalto','{{ dns_domain_name }}') | list | count == 1
+
+- name: test gather vultr dns domain info
+ vultr.cloud.dns_domain_info:
+ register: result
+
+- name: verify test gather vultr dns domain info
+ ansible.builtin.assert:
+ that:
+ - result.vultr_dns_domain_info|selectattr('domain','equalto','{{ dns_domain_name }}') | list | count == 1
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/dns_record/aliases b/ansible_collections/vultr/cloud/tests/integration/targets/dns_record/aliases
new file mode 100644
index 000000000..c749ce7ca
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/dns_record/aliases
@@ -0,0 +1,3 @@
+cloud/vultr
+needs/target/common
+needs/target/cleanup
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/dns_record/defaults/main.yml b/ansible_collections/vultr/cloud/tests/integration/targets/dns_record/defaults/main.yml
new file mode 100644
index 000000000..e979dc89b
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/dns_record/defaults/main.yml
@@ -0,0 +1,38 @@
+# Copyright (c) 2021 René Moser <mail@renemoser.net>
+# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
+---
+vultr_dns_domain_name: "{{ vultr_resource_prefix }}-t3-vultr.com"
+
+vultr_dns_record_items:
+ # Single A record
+ - name: test-www
+ data: 10.10.10.10
+ ttl: 400
+ update_data: 10.10.10.11
+ update_ttl: 200
+
+ # Multiple A records
+ - name: test-www-multiple
+ data: 10.10.11.10
+ update_data: 10.10.11.11
+ multiple: true
+
+ # CNAME
+ - name: test-cname
+ data: www.ansible.com
+ update_data: www.ansible.ch
+ record_type: CNAME
+
+ # Single Multiple MX record
+ - data: mx1.example-ansible.com
+ priority: 10
+ update_priority: 20
+ record_type: MX
+
+ # Multiple MX records
+ - data: mx2.example-ansible.com
+ priority: 10
+ update_data: mx1.example-ansible.com
+ update_priority: 20
+ record_type: MX
+ multiple: true
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/dns_record/meta/main.yml b/ansible_collections/vultr/cloud/tests/integration/targets/dns_record/meta/main.yml
new file mode 100644
index 000000000..2083f0e12
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/dns_record/meta/main.yml
@@ -0,0 +1,3 @@
+---
+dependencies:
+ - common
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/dns_record/tasks/create_record.yml b/ansible_collections/vultr/cloud/tests/integration/targets/dns_record/tasks/create_record.yml
new file mode 100644
index 000000000..39964c138
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/dns_record/tasks/create_record.yml
@@ -0,0 +1,62 @@
+# Copyright (c) 2021, René Moser <mail@renemoser.net>
+# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
+---
+- name: setup dns record absent
+ vultr.cloud.dns_record:
+ name: "{{ item.name | default(omit) }}"
+ domain: "{{ vultr_dns_domain_name }}"
+ record_type: "{{ item.record_type | default(omit) }}"
+ state: absent
+
+- name: test create a dns record in check mode
+ vultr.cloud.dns_record:
+ name: "{{ item.name | default(omit) }}"
+ domain: "{{ vultr_dns_domain_name }}"
+ data: "{{ item.data }}"
+ ttl: "{{ item.ttl | default(omit) }}"
+ record_type: "{{ item.record_type | default(omit) }}"
+ priority: "{{ item.priority | default(omit) }}"
+ check_mode: True
+ register: result
+- name: verify test create a dns record in check mode
+ ansible.builtin.assert:
+ that:
+ - result is changed
+
+- name: test create a dns record
+ vultr.cloud.dns_record:
+ name: "{{ item.name | default(omit) }}"
+ domain: "{{ vultr_dns_domain_name }}"
+ data: "{{ item.data }}"
+ ttl: "{{ item.ttl | default(omit) }}"
+ record_type: "{{ item.record_type | default(omit) }}"
+ priority: "{{ item.priority | default(omit) }}"
+ register: result
+- name: verify test create a dns record
+ ansible.builtin.assert:
+ that:
+ - result is changed
+ - result.vultr_dns_record.data == "{{ item.data }}"
+ - result.vultr_dns_record.name == "{{ item.name | default("") }}"
+ - result.vultr_dns_record.type == "{{ item.record_type | default('A') }}"
+ - result.vultr_dns_record.ttl == {{ item.ttl | default(300) }}
+ - result.vultr_dns_record.priority == {{ item.priority | default(-1) }}
+
+- name: test create a dns record idempotence
+ vultr.cloud.dns_record:
+ name: "{{ item.name | default(omit) }}"
+ domain: "{{ vultr_dns_domain_name }}"
+ data: "{{ item.data }}"
+ ttl: "{{ item.ttl | default(omit) }}"
+ record_type: "{{ item.record_type | default(omit) }}"
+ priority: "{{ item.priority | default(omit) }}"
+ register: result
+- name: verify test create a dns record idempotence
+ ansible.builtin.assert:
+ that:
+ - result is not changed
+ - result.vultr_dns_record.data == "{{ item.data }}"
+ - result.vultr_dns_record.name == "{{ item.name | default("") }}"
+ - result.vultr_dns_record.type == "{{ item.record_type | default('A') }}"
+ - result.vultr_dns_record.ttl == {{ item.ttl | default(300) }}
+ - result.vultr_dns_record.priority == {{ item.priority | default(-1) }}
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/dns_record/tasks/main.yml b/ansible_collections/vultr/cloud/tests/integration/targets/dns_record/tasks/main.yml
new file mode 100644
index 000000000..b26b845b3
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/dns_record/tasks/main.yml
@@ -0,0 +1,13 @@
+---
+- block:
+ - ansible.builtin.import_tasks: tests.yml
+ always:
+ - name: cleanup dns domain
+ vultr.cloud.dns_domain:
+ name: "{{ vultr_dns_domain_name }}"
+ state: absent
+ ignore_errors: true
+
+ - ansible.builtin.import_role:
+ name: cleanup
+ tasks_from: cleanup_dns_domain
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/dns_record/tasks/record.yml b/ansible_collections/vultr/cloud/tests/integration/targets/dns_record/tasks/record.yml
new file mode 100644
index 000000000..6426d4bcf
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/dns_record/tasks/record.yml
@@ -0,0 +1,6 @@
+# Copyright (c) 2021, René Moser <mail@renemoser.net>
+# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
+---
+- ansible.builtin.import_tasks: create_record.yml
+- ansible.builtin.import_tasks: update_record.yml
+- ansible.builtin.import_tasks: remove_record.yml
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/dns_record/tasks/remove_record.yml b/ansible_collections/vultr/cloud/tests/integration/targets/dns_record/tasks/remove_record.yml
new file mode 100644
index 000000000..1207ea250
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/dns_record/tasks/remove_record.yml
@@ -0,0 +1,114 @@
+# Copyright (c) 2021, René Moser <mail@renemoser.net>
+# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
+---
+- name: test remove a dns record in check mode
+ vultr.cloud.dns_record:
+ name: "{{ item.name | default(omit) }}"
+ domain: "{{ vultr_dns_domain_name }}"
+ data: "{{ item.update_data | default(item.data) }}"
+ record_type: "{{ item.record_type | default(omit) }}"
+ multiple: "{{ item.multiple | default(omit) }}"
+ state: absent
+ check_mode: true
+ register: result
+- name: verify test remove a dns record in check mode
+ ansible.builtin.assert:
+ that:
+ - result is changed
+ - result.vultr_dns_record.data == "{{ item.update_data | default(item.data) }}"
+ - result.vultr_dns_record.name == "{{ item.name | default("") }}"
+ - result.vultr_dns_record.type == "{{ item.record_type | default('A') }}"
+ - result.vultr_dns_record.ttl == {{ item.update_ttl | default(300) }}
+ - result.vultr_dns_record.priority == {{ item.update_priority | default(item.priority | default(-1)) }}
+
+- name: test remove second dns record in check mode
+ vultr.cloud.dns_record:
+ name: "{{ item.name | default(omit) }}"
+ domain: "{{ vultr_dns_domain_name }}"
+ data: "{{ item.data | default(item.data) }}"
+ record_type: "{{ item.record_type | default(omit) }}"
+ multiple: "{{ item.multiple | default(omit) }}"
+ state: absent
+ check_mode: true
+ register: result
+ when: item.multiple is defined and item.multiple == true
+- name: verify test remove a dns record in check mode
+ ansible.builtin.assert:
+ that:
+ - result is changed
+ - result.vultr_dns_record.data == "{{ item.data | default(item.data) }}"
+ - result.vultr_dns_record.name == "{{ item.name | default("") }}"
+ - result.vultr_dns_record.type == "{{ item.record_type | default('A') }}"
+ - result.vultr_dns_record.ttl == {{ item.ttl | default(300) }}
+ - result.vultr_dns_record.priority == {{ item.priority | default(-1) }}
+ when: item.multiple is defined and item.multiple == true
+
+- name: test remove a dns record
+ vultr.cloud.dns_record:
+ name: "{{ item.name | default(omit) }}"
+ domain: "{{ vultr_dns_domain_name }}"
+ data: "{{ item.update_data | default(item.data) }}"
+ record_type: "{{ item.record_type | default(omit) }}"
+ multiple: "{{ item.multiple | default(omit) }}"
+ state: absent
+ register: result
+- name: verify test remove a dns record
+ ansible.builtin.assert:
+ that:
+ - result is changed
+ - result.vultr_dns_record.data == "{{ item.update_data | default(item.data) }}"
+ - result.vultr_dns_record.name == "{{ item.name | default("") }}"
+ - result.vultr_dns_record.type == "{{ item.record_type | default('A') }}"
+ - result.vultr_dns_record.ttl == {{ item.update_ttl | default(300) }}
+ - result.vultr_dns_record.priority == {{ item.update_priority | default(item.priority | default(-1)) }}
+
+- name: test remove second dns record
+ vultr.cloud.dns_record:
+ name: "{{ item.name | default(omit) }}"
+ domain: "{{ vultr_dns_domain_name }}"
+ data: "{{ item.data }}"
+ record_type: "{{ item.record_type | default(omit) }}"
+ multiple: "{{ item.multiple | default(omit) }}"
+ state: absent
+ register: result
+ when: item.multiple is defined and item.multiple == true
+- name: verify test remove a dns record
+ ansible.builtin.assert:
+ that:
+ - result is changed
+ - result.vultr_dns_record.data == "{{ item.data }}"
+ - result.vultr_dns_record.name == "{{ item.name | default("") }}"
+ - result.vultr_dns_record.type == "{{ item.record_type | default('A') }}"
+ - result.vultr_dns_record.ttl == {{ item.ttl | default(300) }}
+ - result.vultr_dns_record.priority == {{ item.priority | default(-1) }}
+ when: item.multiple is defined and item.multiple == true
+
+- name: test remove a dns record idempotence
+ vultr.cloud.dns_record:
+ name: "{{ item.name | default(omit) }}"
+ domain: "{{ vultr_dns_domain_name }}"
+ data: "{{ item.update_data | default(item.data) }}"
+ record_type: "{{ item.record_type | default(omit) }}"
+ multiple: "{{ item.multiple | default(omit) }}"
+ state: absent
+ register: result
+- name: verify test remove a dns record idempotence
+ ansible.builtin.assert:
+ that:
+ - result is not changed
+
+- name: test remove second dns record idempotence
+ vultr.cloud.dns_record:
+ name: "{{ item.name | default(omit) }}"
+ domain: "{{ vultr_dns_domain_name }}"
+ data: "{{ item.data }}"
+ record_type: "{{ item.record_type | default(omit) }}"
+ multiple: "{{ item.multiple | default(omit) }}"
+ state: absent
+ register: result
+ when: item.multiple is defined and item.multiple == true
+- name: verify test remove a dns record idempotence
+ ansible.builtin.assert:
+ that:
+ - result is not changed
+ when: item.multiple is defined and item.multiple == true
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/dns_record/tasks/test_fail_multiple.yml b/ansible_collections/vultr/cloud/tests/integration/targets/dns_record/tasks/test_fail_multiple.yml
new file mode 100644
index 000000000..9d18c5b47
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/dns_record/tasks/test_fail_multiple.yml
@@ -0,0 +1,78 @@
+# Copyright (c) 2021, René Moser <mail@renemoser.net>
+# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
+---
+- name: setup first dns record
+ vultr.cloud.dns_record:
+ name: test-multiple
+ domain: "{{ vultr_dns_domain_name }}"
+ data: 1.2.3.4
+ multiple: true
+ register: result
+- name: verify setup a dns record
+ ansible.builtin.assert:
+ that:
+ - result is successful
+
+- name: setup second dns record
+ vultr.cloud.dns_record:
+ name: test-multiple
+ domain: "{{ vultr_dns_domain_name }}"
+ data: 1.2.3.5
+ multiple: true
+ register: result
+- name: verify setup second dns record
+ ansible.builtin.assert:
+ that:
+ - result is successful
+
+- name: test-multiple fail multiple identical records found
+ vultr.cloud.dns_record:
+ name: test-multiple
+ domain: "{{ vultr_dns_domain_name }}"
+ state: absent
+ register: result
+ ignore_errors: true
+- name: verify test fail multiple identical records found
+ ansible.builtin.assert:
+ that:
+ - result is failed
+
+- name: test-multiple fail absent multiple identical records but not data
+ vultr.cloud.dns_record:
+ name: test-multiple
+ domain: "{{ vultr_dns_domain_name }}"
+ state: absent
+ multiple: true
+ register: result
+ ignore_errors: true
+- name: verify test-multiple success absent multiple identical records found
+ ansible.builtin.assert:
+ that:
+ - result is failed
+ - "result.msg == 'multiple is True but all of the following are missing: data'"
+
+- name: test-multiple success absent multiple identical records second found
+ vultr.cloud.dns_record:
+ name: test-multiple
+ domain: "{{ vultr_dns_domain_name }}"
+ data: 1.2.3.5
+ state: absent
+ multiple: true
+ register: result
+- name: verify test-multiple success absent multiple identical records second found
+ ansible.builtin.assert:
+ that:
+ - result is changed
+
+- name: test-multiple success absent multiple identical records first found
+ vultr.cloud.dns_record:
+ name: test-multiple
+ domain: "{{ vultr_dns_domain_name }}"
+ data: 1.2.3.4
+ state: absent
+ multiple: true
+ register: result
+- name: verify test-multiple success absent multiple identical records firstfound
+ ansible.builtin.assert:
+ that:
+ - result is changed
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/dns_record/tasks/tests.yml b/ansible_collections/vultr/cloud/tests/integration/targets/dns_record/tasks/tests.yml
new file mode 100644
index 000000000..0251942d7
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/dns_record/tasks/tests.yml
@@ -0,0 +1,12 @@
+# Copyright (c) 2021, René Moser <mail@renemoser.net>
+# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
+---
+- name: setup dns domain
+ vultr.cloud.dns_domain:
+ name: "{{ vultr_dns_domain_name }}"
+ server_ip: 10.10.10.10
+
+- ansible.builtin.import_tasks: test_fail_multiple.yml
+
+- ansible.builtin.include_tasks: record.yml
+ with_items: "{{ vultr_dns_record_items }}"
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/dns_record/tasks/update_record.yml b/ansible_collections/vultr/cloud/tests/integration/targets/dns_record/tasks/update_record.yml
new file mode 100644
index 000000000..f79beccf5
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/dns_record/tasks/update_record.yml
@@ -0,0 +1,70 @@
+# Copyright (c) 2021, René Moser <mail@renemoser.net>
+# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
+---
+- name: test update or add another dns record in check mode
+ vultr.cloud.dns_record:
+ name: "{{ item.name | default(omit) }}"
+ domain: "{{ vultr_dns_domain_name }}"
+ data: "{{ item.update_data | default(item.data) }}"
+ ttl: "{{ item.update_ttl | default(omit) }}"
+ record_type: "{{ item.record_type | default(omit) }}"
+ priority: "{{ item.update_priority | default(omit) }}"
+ multiple: "{{ item.multiple | default(omit) }}"
+ check_mode: true
+ register: result
+- name: verify test update or add another dns record in check mode
+ ansible.builtin.assert:
+ that:
+ - result is changed
+ - result.vultr_dns_record.data == "{{ item.data }}"
+ - result.vultr_dns_record.name == "{{ item.name | default("") }}"
+ - result.vultr_dns_record.type == "{{ item.record_type | default('A') }}"
+ - result.vultr_dns_record.ttl == {{ item.ttl | default(300) }}
+ - result.vultr_dns_record.priority == {{ item.priority | default(-1) }}
+ when: item.multiple is undefined or item.multiple == false
+- name: verify test add another dns record in check mode
+ ansible.builtin.assert:
+ that:
+ - result is changed
+ - not result.vultr_dns_record
+ when: item.multiple is defined and item.multiple == true
+
+- name: test update or add another dns record
+ vultr.cloud.dns_record:
+ name: "{{ item.name | default(omit) }}"
+ domain: "{{ vultr_dns_domain_name }}"
+ data: "{{ item.update_data | default(item.data) }}"
+ ttl: "{{ item.update_ttl | default(omit) }}"
+ record_type: "{{ item.record_type | default(omit) }}"
+ priority: "{{ item.update_priority | default(omit) }}"
+ multiple: "{{ item.multiple | default(omit) }}"
+ register: result
+- name: verify test update a dns record
+ ansible.builtin.assert:
+ that:
+ - result is changed
+ - result.vultr_dns_record.data == "{{ item.update_data | default(item.data) }}"
+ - result.vultr_dns_record.name == "{{ item.name | default("") }}"
+ - result.vultr_dns_record.ttl == {{ item.update_ttl | default(300) }}
+ - result.vultr_dns_record.type == "{{ item.record_type | default('A') }}"
+ - result.vultr_dns_record.priority == {{ item.update_priority | default(-1) }}
+
+- name: test update or add another dns record idempotence
+ vultr.cloud.dns_record:
+ name: "{{ item.name | default(omit) }}"
+ domain: "{{ vultr_dns_domain_name }}"
+ data: "{{ item.update_data | default(item.data) }}"
+ ttl: "{{ item.update_ttl | default(omit) }}"
+ record_type: "{{ item.record_type | default(omit) }}"
+ priority: "{{ item.update_priority | default(omit) }}"
+ multiple: "{{ item.multiple | default(omit) }}"
+ register: result
+- name: verify test update a dns record idempotence
+ ansible.builtin.assert:
+ that:
+ - result is not changed
+ - result.vultr_dns_record.data == "{{ item.update_data | default(item.data) }}"
+ - result.vultr_dns_record.name == "{{ item.name | default("") }}"
+ - result.vultr_dns_record.ttl == {{ item.update_ttl | default(300) }}
+ - result.vultr_dns_record.type == "{{ item.record_type | default('A') }}"
+ - result.vultr_dns_record.priority == {{ item.update_priority | default(-1) }}
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/firewall_group/aliases b/ansible_collections/vultr/cloud/tests/integration/targets/firewall_group/aliases
new file mode 100644
index 000000000..c749ce7ca
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/firewall_group/aliases
@@ -0,0 +1,3 @@
+cloud/vultr
+needs/target/common
+needs/target/cleanup
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/firewall_group/defaults/main.yml b/ansible_collections/vultr/cloud/tests/integration/targets/firewall_group/defaults/main.yml
new file mode 100644
index 000000000..a5e9c5576
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/firewall_group/defaults/main.yml
@@ -0,0 +1,4 @@
+# Copyright (c) 2018, René Moser <mail@renemoser.net>
+# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
+---
+vultr_firewall_group_name: "{{ vultr_resource_prefix }}_firewall-group"
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/firewall_group/meta/main.yml b/ansible_collections/vultr/cloud/tests/integration/targets/firewall_group/meta/main.yml
new file mode 100644
index 000000000..2083f0e12
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/firewall_group/meta/main.yml
@@ -0,0 +1,3 @@
+---
+dependencies:
+ - common
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/firewall_group/tasks/main.yml b/ansible_collections/vultr/cloud/tests/integration/targets/firewall_group/tasks/main.yml
new file mode 100644
index 000000000..29ddee8e1
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/firewall_group/tasks/main.yml
@@ -0,0 +1,7 @@
+---
+- block:
+ - ansible.builtin.import_tasks: tests.yml
+ always:
+ - ansible.builtin.import_role:
+ name: cleanup
+ tasks_from: cleanup_firewall_group
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/firewall_group/tasks/tests.yml b/ansible_collections/vultr/cloud/tests/integration/targets/firewall_group/tasks/tests.yml
new file mode 100644
index 000000000..578fc6efb
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/firewall_group/tasks/tests.yml
@@ -0,0 +1,86 @@
+# Copyright (c) 2018, René Moser <mail@renemoser.net>
+# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
+---
+- name: setup
+ vultr.cloud.firewall_group:
+ name: "{{ vultr_firewall_group_name }}"
+ state: absent
+ register: result
+- name: verify setup
+ ansible.builtin.assert:
+ that:
+ - result is success
+
+- name: test fail if missing name
+ vultr.cloud.firewall_group:
+ register: result
+ ignore_errors: true
+- name: verify test fail if missing description
+ ansible.builtin.assert:
+ that:
+ - result is failed
+ - 'result.msg == "missing required arguments: description"'
+
+- name: test create firewall group in check mode
+ vultr.cloud.firewall_group:
+ name: "{{ vultr_firewall_group_name }}"
+ register: result
+ check_mode: true
+- name: verify test create firewall group in check mode
+ ansible.builtin.assert:
+ that:
+ - result is changed
+
+- name: test create firewall group
+ vultr.cloud.firewall_group:
+ name: "{{ vultr_firewall_group_name }}"
+ register: result
+- name: verify test create firewall group
+ ansible.builtin.assert:
+ that:
+ - result is changed
+ - result.vultr_firewall_group.description == vultr_firewall_group_name
+
+- name: test create firewall group idempotence
+ vultr.cloud.firewall_group:
+ name: "{{ vultr_firewall_group_name }}"
+
+ register: result
+- name: verify test create firewall group idempotence
+ ansible.builtin.assert:
+ that:
+ - result is not changed
+ - result.vultr_firewall_group.description == vultr_firewall_group_name
+
+- name: test absent firewall group in check mode
+ vultr.cloud.firewall_group:
+ name: "{{ vultr_firewall_group_name }}"
+ state: absent
+ register: result
+ check_mode: true
+- name: verify test absent firewall group in check mode
+ ansible.builtin.assert:
+ that:
+ - result is changed
+ - result.vultr_firewall_group.description == vultr_firewall_group_name
+
+- name: test absent firewall group
+ vultr.cloud.firewall_group:
+ name: "{{ vultr_firewall_group_name }}"
+ state: absent
+ register: result
+- name: verify test absent firewall group
+ ansible.builtin.assert:
+ that:
+ - result is changed
+ - result.vultr_firewall_group.description == vultr_firewall_group_name
+
+- name: test absent firewall group idempotence
+ vultr.cloud.firewall_group:
+ name: "{{ vultr_firewall_group_name }}"
+ state: absent
+ register: result
+- name: verify test absent firewall group idempotence
+ ansible.builtin.assert:
+ that:
+ - result is not changed
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/firewall_group_info/aliases b/ansible_collections/vultr/cloud/tests/integration/targets/firewall_group_info/aliases
new file mode 100644
index 000000000..c749ce7ca
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/firewall_group_info/aliases
@@ -0,0 +1,3 @@
+cloud/vultr
+needs/target/common
+needs/target/cleanup
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/firewall_group_info/defaults/main.yml b/ansible_collections/vultr/cloud/tests/integration/targets/firewall_group_info/defaults/main.yml
new file mode 100644
index 000000000..a420cc51b
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/firewall_group_info/defaults/main.yml
@@ -0,0 +1,2 @@
+---
+firewall_group_name: "{{ vultr_resource_prefix }}_firewall-group"
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/firewall_group_info/meta/main.yml b/ansible_collections/vultr/cloud/tests/integration/targets/firewall_group_info/meta/main.yml
new file mode 100644
index 000000000..2083f0e12
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/firewall_group_info/meta/main.yml
@@ -0,0 +1,3 @@
+---
+dependencies:
+ - common
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/firewall_group_info/tasks/main.yml b/ansible_collections/vultr/cloud/tests/integration/targets/firewall_group_info/tasks/main.yml
new file mode 100644
index 000000000..29ddee8e1
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/firewall_group_info/tasks/main.yml
@@ -0,0 +1,7 @@
+---
+- block:
+ - ansible.builtin.import_tasks: tests.yml
+ always:
+ - ansible.builtin.import_role:
+ name: cleanup
+ tasks_from: cleanup_firewall_group
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/firewall_group_info/tasks/tests.yml b/ansible_collections/vultr/cloud/tests/integration/targets/firewall_group_info/tasks/tests.yml
new file mode 100644
index 000000000..390150418
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/firewall_group_info/tasks/tests.yml
@@ -0,0 +1,34 @@
+# Copyright (c) 2018, Yanis Guenane <yanis+ansible@guenane.org>
+# Copyright (c) 2021, René Moser <mail@renemoser.net>
+# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
+---
+- name: test gather vultr firewall group info - empty resources
+ vultr.cloud.firewall_group_info:
+
+- name: Create the firewall group
+ vultr.cloud.firewall_group:
+ name: "{{ firewall_group_name }}"
+
+- name: test gather vultr firewall group info in check mode
+ vultr.cloud.firewall_group_info:
+ check_mode: true
+ register: result
+
+- name: verify test gather vultr firewall group info in check mode
+ ansible.builtin.assert:
+ that:
+ - result.vultr_firewall_group_info|selectattr('description','equalto','{{ firewall_group_name }}') | list | count == 1
+
+- name: test gather vultr firewall group info
+ vultr.cloud.firewall_group_info:
+ register: result
+
+- name: verify test gather vultr firewall group info
+ ansible.builtin.assert:
+ that:
+ - result.vultr_firewall_group_info|selectattr('description','equalto','{{ firewall_group_name }}') | list | count == 1
+
+- name: Delete the firewall group
+ vultr.cloud.firewall_group:
+ name: "{{ firewall_group_name }}"
+ state: absent
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/firewall_rule/aliases b/ansible_collections/vultr/cloud/tests/integration/targets/firewall_rule/aliases
new file mode 100644
index 000000000..c749ce7ca
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/firewall_rule/aliases
@@ -0,0 +1,3 @@
+cloud/vultr
+needs/target/common
+needs/target/cleanup
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/firewall_rule/defaults/main.yml b/ansible_collections/vultr/cloud/tests/integration/targets/firewall_rule/defaults/main.yml
new file mode 100644
index 000000000..7e96b1f83
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/firewall_rule/defaults/main.yml
@@ -0,0 +1,40 @@
+# Copyright (c) 2018, René Moser <mail@renemoser.net>
+# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
+---
+vultr_firewall_group_name: "{{ vultr_resource_prefix }}_firewall-group"
+vultr_firewall_rules:
+ - notes: DNS TCP v4
+ port: "53"
+ subnet: "0.0.0.0"
+ subnet_size: 0
+
+ - notes: DNS UDP v4
+ port: "53"
+ protocol: udp
+ subnet: "0.0.0.0"
+ subnet_size: 0
+
+ - notes: DNS tcp v6
+ port: "53"
+ port_update: "5353"
+ protocol: tcp
+ ip_type: v6
+ subnet: "::"
+ subnet_size: 0
+
+ - notes: DNS UDP v6
+ port: "53"
+ protocol: udp
+ ip_type: v6
+ subnet: "::"
+ subnet_size: 0
+
+ - notes: allow ICMP
+ protocol: icmp
+ subnet: "0.0.0.0"
+ subnet_size: 0
+
+ - notes: web app
+ port: "8000:8080"
+ subnet: "192.168.23.0"
+ subnet_size: 24
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/firewall_rule/meta/main.yml b/ansible_collections/vultr/cloud/tests/integration/targets/firewall_rule/meta/main.yml
new file mode 100644
index 000000000..2083f0e12
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/firewall_rule/meta/main.yml
@@ -0,0 +1,3 @@
+---
+dependencies:
+ - common
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/firewall_rule/tasks/main.yml b/ansible_collections/vultr/cloud/tests/integration/targets/firewall_rule/tasks/main.yml
new file mode 100644
index 000000000..66fd850fa
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/firewall_rule/tasks/main.yml
@@ -0,0 +1,8 @@
+---
+- block:
+ - ansible.builtin.import_tasks: tests.yml
+ always:
+ - name: cleanup firewall group and rules
+ vultr.cloud.firewall_group:
+ name: "{{ vultr_firewall_group_name }}"
+ state: absent
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/firewall_rule/tasks/rule_absent.yml b/ansible_collections/vultr/cloud/tests/integration/targets/firewall_rule/tasks/rule_absent.yml
new file mode 100644
index 000000000..a8fe6f60a
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/firewall_rule/tasks/rule_absent.yml
@@ -0,0 +1,62 @@
+---
+- name: rule info
+ ansible.builtin.debug:
+ var: rule
+
+- name: test absent firewall rule in check mode
+ vultr.cloud.firewall_rule:
+ group: "{{ vultr_firewall_group_name }}"
+ ip_type: "{{ rule.ip_type | default('v4') }}"
+ port: "{{ rule.port | default(omit) }}"
+ protocol: "{{ rule.protocol | default(omit) }}"
+ subnet: "{{ rule.subnet | default(omit) }}"
+ subnet_size: "{{ rule.subnet_size | default(omit) }}"
+ state: absent
+ register: result
+ check_mode: true
+- name: verify test absent firewall rule in check mode
+ ansible.builtin.assert:
+ that:
+ - result is changed
+ - result.vultr_firewall_rule.action == "accept"
+ - result.vultr_firewall_rule.protocol == "{{ rule.protocol | default('tcp') }}"
+ - result.vultr_firewall_rule.port == "{{ rule.port | default('') }}"
+ - result.vultr_firewall_rule.subnet == "{{ rule.subnet | default('') }}"
+ - result.vultr_firewall_rule.subnet_size == {{ rule.subnet_size | default(0) }}
+ - result.vultr_firewall_rule.ip_type == "{{ rule.ip_type | default('v4') }}"
+
+- name: test absent firewall rule
+ vultr.cloud.firewall_rule:
+ group: "{{ vultr_firewall_group_name }}"
+ ip_type: "{{ rule.ip_type | default('v4') }}"
+ port: "{{ rule.port | default(omit) }}"
+ protocol: "{{ rule.protocol | default(omit) }}"
+ subnet: "{{ rule.subnet | default(omit) }}"
+ subnet_size: "{{ rule.subnet_size | default(omit) }}"
+ state: absent
+ register: result
+- name: verify test absent firewall rule
+ ansible.builtin.assert:
+ that:
+ - result is changed
+ - result.vultr_firewall_rule.action == "accept"
+ - result.vultr_firewall_rule.protocol == "{{ rule.protocol | default('tcp') }}"
+ - result.vultr_firewall_rule.port == "{{ rule.port | default('') }}"
+ - result.vultr_firewall_rule.subnet == "{{ rule.subnet | default('') }}"
+ - result.vultr_firewall_rule.subnet_size == {{ rule.subnet_size | default(0) }}
+ - result.vultr_firewall_rule.ip_type == "{{ rule.ip_type | default('v4') }}"
+
+- name: test absent firewall rule idempotence
+ vultr.cloud.firewall_rule:
+ group: "{{ vultr_firewall_group_name }}"
+ ip_type: "{{ rule.ip_type | default('v4') }}"
+ port: "{{ rule.port | default(omit) }}"
+ protocol: "{{ rule.protocol | default(omit) }}"
+ subnet: "{{ rule.subnet | default(omit) }}"
+ subnet_size: "{{ rule.subnet_size | default(omit) }}"
+ state: absent
+ register: result
+- name: verify test absent firewall rule idempotence
+ ansible.builtin.assert:
+ that:
+ - result is not changed
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/firewall_rule/tasks/rule_present.yml b/ansible_collections/vultr/cloud/tests/integration/targets/firewall_rule/tasks/rule_present.yml
new file mode 100644
index 000000000..9093b6aaf
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/firewall_rule/tasks/rule_present.yml
@@ -0,0 +1,62 @@
+---
+- name: rule info
+ ansible.builtin.debug:
+ var: rule
+
+- name: test create firewall rule in check mode
+ vultr.cloud.firewall_rule:
+ group: "{{ vultr_firewall_group_name }}"
+ ip_type: "{{ rule.ip_type | default('v4') }}"
+ port: "{{ rule.port | default(omit) }}"
+ protocol: "{{ rule.protocol | default(omit) }}"
+ subnet: "{{ rule.subnet | default(omit) }}"
+ subnet_size: "{{ rule.subnet_size | default(omit) }}"
+ notes: "{{ rule.notes }}"
+ register: result
+ check_mode: true
+- name: verify test create firewall rule in check mode
+ ansible.builtin.assert:
+ that:
+ - result is changed
+
+- name: test create firewall rule
+ vultr.cloud.firewall_rule:
+ group: "{{ vultr_firewall_group_name }}"
+ ip_type: "{{ rule.ip_type | default('v4') }}"
+ port: "{{ rule.port | default(omit) }}"
+ protocol: "{{ rule.protocol | default(omit) }}"
+ subnet: "{{ rule.subnet | default(omit) }}"
+ subnet_size: "{{ rule.subnet_size | default(omit) }}"
+ notes: "{{ rule.notes }}"
+ register: result
+- name: verify test create firewall rule
+ ansible.builtin.assert:
+ that:
+ - result is changed
+ - result.vultr_firewall_rule.action == "accept"
+ - result.vultr_firewall_rule.protocol == "{{ rule.protocol | default('tcp') }}"
+ - result.vultr_firewall_rule.port == "{{ rule.port | default('') }}"
+ - result.vultr_firewall_rule.subnet == "{{ rule.subnet | default('') }}"
+ - result.vultr_firewall_rule.subnet_size == {{ rule.subnet_size | default(0) }}
+ - result.vultr_firewall_rule.ip_type == "{{ rule.ip_type | default('v4') }}"
+
+- name: test create firewall rule idempotence
+ vultr.cloud.firewall_rule:
+ group: "{{ vultr_firewall_group_name }}"
+ ip_type: "{{ rule.ip_type | default('v4') }}"
+ port: "{{ rule.port | default(omit) }}"
+ protocol: "{{ rule.protocol | default(omit) }}"
+ subnet: "{{ rule.subnet | default(omit) }}"
+ subnet_size: "{{ rule.subnet_size | default(omit) }}"
+ notes: "{{ rule.notes }}"
+ register: result
+- name: verify test create firewall rule idempotence
+ ansible.builtin.assert:
+ that:
+ - result is not changed
+ - result.vultr_firewall_rule.action == "accept"
+ - result.vultr_firewall_rule.protocol == "{{ rule.protocol | default('tcp') }}"
+ - result.vultr_firewall_rule.port == "{{ rule.port | default('') }}"
+ - result.vultr_firewall_rule.subnet == "{{ rule.subnet | default('') }}"
+ - result.vultr_firewall_rule.subnet_size == {{ rule.subnet_size | default(0) }}
+ - result.vultr_firewall_rule.ip_type == "{{ rule.ip_type | default('v4') }}"
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/firewall_rule/tasks/tests.yml b/ansible_collections/vultr/cloud/tests/integration/targets/firewall_rule/tasks/tests.yml
new file mode 100644
index 000000000..b823f689c
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/firewall_rule/tasks/tests.yml
@@ -0,0 +1,28 @@
+# Copyright (c) 2022, René Moser <mail@renemoser.net>
+# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
+---
+- name: setup firewall group
+ vultr.cloud.firewall_group:
+ name: "{{ vultr_firewall_group_name }}"
+
+- name: test fail if missing group
+ vultr.cloud.firewall_rule:
+ register: result
+ ignore_errors: true
+- name: verify test fail if missing group
+ ansible.builtin.assert:
+ that:
+ - result is failed
+ - 'result.msg == "missing required arguments: group"'
+
+- ansible.builtin.include_tasks: rule_present.yml
+ with_items: "{{ vultr_firewall_rules }}"
+ loop_control:
+ loop_var: rule
+ label: "{{ rule.notes }}"
+
+- ansible.builtin.include_tasks: rule_absent.yml
+ with_items: "{{ vultr_firewall_rules }}"
+ loop_control:
+ loop_var: rule
+ label: "{{ rule.notes }}"
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/firewall_rule_info/aliases b/ansible_collections/vultr/cloud/tests/integration/targets/firewall_rule_info/aliases
new file mode 100644
index 000000000..c749ce7ca
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/firewall_rule_info/aliases
@@ -0,0 +1,3 @@
+cloud/vultr
+needs/target/common
+needs/target/cleanup
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/firewall_rule_info/defaults/main.yml b/ansible_collections/vultr/cloud/tests/integration/targets/firewall_rule_info/defaults/main.yml
new file mode 100644
index 000000000..a420cc51b
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/firewall_rule_info/defaults/main.yml
@@ -0,0 +1,2 @@
+---
+firewall_group_name: "{{ vultr_resource_prefix }}_firewall-group"
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/firewall_rule_info/meta/main.yml b/ansible_collections/vultr/cloud/tests/integration/targets/firewall_rule_info/meta/main.yml
new file mode 100644
index 000000000..2083f0e12
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/firewall_rule_info/meta/main.yml
@@ -0,0 +1,3 @@
+---
+dependencies:
+ - common
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/firewall_rule_info/tasks/main.yml b/ansible_collections/vultr/cloud/tests/integration/targets/firewall_rule_info/tasks/main.yml
new file mode 100644
index 000000000..29ddee8e1
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/firewall_rule_info/tasks/main.yml
@@ -0,0 +1,7 @@
+---
+- block:
+ - ansible.builtin.import_tasks: tests.yml
+ always:
+ - ansible.builtin.import_role:
+ name: cleanup
+ tasks_from: cleanup_firewall_group
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/firewall_rule_info/tasks/tests.yml b/ansible_collections/vultr/cloud/tests/integration/targets/firewall_rule_info/tasks/tests.yml
new file mode 100644
index 000000000..96bca9803
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/firewall_rule_info/tasks/tests.yml
@@ -0,0 +1,45 @@
+# Copyright (c) 2018, Yanis Guenane <yanis+ansible@guenane.org>
+# Copyright (c) 2021, René Moser <mail@renemoser.net>
+# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
+---
+- name: setup the firewall group
+ vultr.cloud.firewall_group:
+ name: "{{ firewall_group_name }}"
+
+- name: test gather vultr firewall rule info - empty resources
+ vultr.cloud.firewall_rule_info:
+ group: "{{ firewall_group_name }}"
+
+- name: setup create firewall rule
+ vultr.cloud.firewall_rule:
+ group: "{{ firewall_group_name }}"
+ ip_type: v4
+ port: "80"
+ protocol: tcp
+ subnet: "0.0.0.0"
+ subnet_size: 0
+ notes: "{{ firewall_group_name }}"
+
+- name: test gather vultr firewall rule info in check mode
+ vultr.cloud.firewall_rule_info:
+ group: "{{ firewall_group_name }}"
+ check_mode: true
+ register: result
+- name: verify test gather vultr firewall rule info in check mode
+ ansible.builtin.assert:
+ that:
+ - result.vultr_firewall_rule_info|selectattr('notes','equalto','{{ firewall_group_name }}') | list | count == 1
+
+- name: test gather vultr firewall rule info
+ vultr.cloud.firewall_rule_info:
+ group: "{{ firewall_group_name }}"
+ register: result
+- name: verify test gather vultr firewall rule info
+ ansible.builtin.assert:
+ that:
+ - result.vultr_firewall_rule_info|selectattr('notes','equalto','{{ firewall_group_name }}') | list | count == 1
+
+- name: Delete the firewall group
+ vultr.cloud.firewall_group:
+ name: "{{ firewall_group_name }}"
+ state: absent
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/instance/aliases b/ansible_collections/vultr/cloud/tests/integration/targets/instance/aliases
new file mode 100644
index 000000000..c749ce7ca
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/instance/aliases
@@ -0,0 +1,3 @@
+cloud/vultr
+needs/target/common
+needs/target/cleanup
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/instance/defaults/main.yml b/ansible_collections/vultr/cloud/tests/integration/targets/instance/defaults/main.yml
new file mode 100644
index 000000000..6683b5e85
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/instance/defaults/main.yml
@@ -0,0 +1,95 @@
+# Copyright (c) 2022, René Moser <mail@renemoser.net>
+# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
+---
+vultr_instance_firewall_group: "{{ vultr_resource_prefix }}_instance_fw_group"
+vultr_instance_ssh_key_name: "{{ vultr_resource_prefix }}_instance_sshkey"
+vultr_instance_ssh_key: "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAgEAyWYItY+3w5b8PdGRoz0oY5mufqydW96naE+VM3JSvJFAUS08rAjQQpQ03ymoALeHQy6JVZbcgecxn6p0pAOINQdqufn4udPtOPCtMjNiPGpkSM9ah/6X5+kvyWMNrvlf+Ld4OOoszP5sAkgQzIbrFQAm41XknBUha0zkewZwfrVhain4pnDjV7wCcChId/Q/Gbi4xMtXkisznWcAJcueBs3EEZDKhJ5q0VeWSJEhYJDLFN1sOxF0AIUnMrOhfKQ/LjgREXPB6uCl899INUTXRNNjRpeMXyJ2wMMmOAbua2qEd1r13Bu1n+6A823Hzb33fyMXuqWnJwBJ4DCvMlGuEsfuOK+xk7DaBfLHbcM6fsPk0/4psTE6YLgC41remr6+u5ZWsY/faMtSnNPie8Z8Ov0DIYGdhbJjUXk1HomxRV9+ZfZ2Ob8iCwlaAQAyEUM6fs3Kxt8pBD8dx1HOkhsfBWPvuDr5y+kqE7H8/MuPDTc0QgH2pjUMpmw/XBwNDHshVEjrZvtICOjOLUJxcowLO1ivNYwPwowQxfisMy56LfYdjsOslBiqsrkAqvNGm1zu8wKHeqVN9w5l3yUELpvubfm9NKIvYcl6yWF36T0c5vE+g0DU/Jy4XpTj0hZG9QV2mRQcLJnd2pxQtJT7cPFtrn/+tgRxzjEtbDXummDV4sE= ansible@example.com"
+
+vutr_instance_vpcs:
+ - description: "{{ vultr_resource_prefix }}_instance_vpc_1"
+ v4_subnet: 192.168.42.0
+ v4_subnet_mask: 24
+ region: ams
+ - description: "{{ vultr_resource_prefix }}_instance_vpc_2"
+ v4_subnet: 192.168.23.0
+ v4_subnet_mask: 24
+ region: ams
+ - description: "{{ vultr_resource_prefix }}_instance_vpc_3"
+ v4_subnet: 192.168.98.0
+ v4_subnet_mask: 24
+ region: ams
+
+vultr_instances:
+ - label: "{{ vultr_resource_prefix }}_os1"
+ hostname: myhostname
+ user_data: |
+ #cloud-config
+ packages:
+ - htop
+ user_data_update: |
+ #cloud-config
+ packages:
+ - htop
+ - vim
+ plan: vc2-1c-1gb
+ plan_update: vc2-1c-2gb
+ ssh_keys:
+ - "{{ vultr_instance_ssh_key_name }}"
+ tags:
+ - one
+ - two
+ tags_update:
+ - three
+ - four
+ region: ams
+ os: Debian 11 x64 (bullseye)
+ backups: true
+ backups_update: false
+ ddos_protection: true
+ ddos_protection_update: false
+ enable_ipv6: false
+ enable_ipv6_update: true
+ vpcs:
+ - "{{ vultr_resource_prefix }}_instance_vpc_1"
+ - "{{ vultr_resource_prefix }}_instance_vpc_2"
+ vpcs_update:
+ - "{{ vultr_resource_prefix }}_instance_vpc_1"
+ - "{{ vultr_resource_prefix }}_instance_vpc_3"
+
+ #TODO: Disabled, this app does not exist anymore, find a new app
+ # - label: "{{ vultr_resource_prefix }}_app1"
+ # plan: vc2-1c-1gb
+ # plan_update: vc2-1c-2gb
+ # region: ams
+ # app: Docker on Ubuntu 20.04 x64
+ # backups: false
+ # backups_update: false
+ # ddos_protection: false
+ # ddos_protection_update: false
+ # enable_ipv6: false
+ # enable_ipv6_update: false
+ # vpcs:
+ # - "{{ vultr_resource_prefix }}_instance_vpc_1"
+ # - "{{ vultr_resource_prefix }}_instance_vpc_2"
+ # vpcs_update:
+ # - "{{ vultr_resource_prefix }}_instance_vpc_1"
+ # - "{{ vultr_resource_prefix }}_instance_vpc_3"
+
+ - label: "{{ vultr_resource_prefix }}_img1"
+ plan: vc2-1c-1gb
+ plan_update: vc2-1c-2gb
+ region: ams
+ image: NodeJS on Ubuntu 22.04
+ backups: false
+ backups_update: true
+ ddos_protection: false
+ ddos_protection_update: true
+ enable_ipv6: true
+ # API does not disable IPv6 once enabled.
+ enable_ipv6_update: true
+ vpcs:
+ - "{{ vultr_resource_prefix }}_instance_vpc_1"
+ - "{{ vultr_resource_prefix }}_instance_vpc_2"
+ vpcs_update:
+ - "{{ vultr_resource_prefix }}_instance_vpc_1"
+ - "{{ vultr_resource_prefix }}_instance_vpc_3"
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/instance/meta/main.yml b/ansible_collections/vultr/cloud/tests/integration/targets/instance/meta/main.yml
new file mode 100644
index 000000000..2083f0e12
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/instance/meta/main.yml
@@ -0,0 +1,3 @@
+---
+dependencies:
+ - common
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/instance/tasks/absent.yml b/ansible_collections/vultr/cloud/tests/integration/targets/instance/tasks/absent.yml
new file mode 100644
index 000000000..828f7f97e
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/instance/tasks/absent.yml
@@ -0,0 +1,38 @@
+---
+- name: instance info
+ ansible.builtin.debug:
+ var: instance
+
+- name: test absent instance in check mode
+ vultr.cloud.instance:
+ label: "{{ instance.label }}"
+ region: "{{ instance.region }}"
+ state: absent
+ register: result
+ check_mode: true
+- name: verify test absent instance in check mode
+ ansible.builtin.assert:
+ that:
+ - result is changed
+
+- name: test absent instance
+ vultr.cloud.instance:
+ label: "{{ instance.label }}"
+ region: "{{ instance.region }}"
+ state: absent
+ register: result
+- name: verify test absent instance
+ ansible.builtin.assert:
+ that:
+ - result is changed
+
+- name: test absent instance idempotence
+ vultr.cloud.instance:
+ label: "{{ instance.label }}"
+ region: "{{ instance.region }}"
+ state: absent
+ register: result
+- name: verify test absent instance idempotence
+ ansible.builtin.assert:
+ that:
+ - result is not changed
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/instance/tasks/failures.yml b/ansible_collections/vultr/cloud/tests/integration/targets/instance/tasks/failures.yml
new file mode 100644
index 000000000..f22616901
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/instance/tasks/failures.yml
@@ -0,0 +1,55 @@
+---
+- name: test fail if missing arguments
+ vultr.cloud.instance:
+ register: result
+ ignore_errors: true
+- name: verify test fail if missing arguments
+ ansible.builtin.assert:
+ that:
+ - result is failed
+ - 'result.msg == "missing required arguments: label, region"'
+
+- name: test fail if missing arguments required one of
+ vultr.cloud.instance:
+ label: my label
+ plan: a plan
+ region: a region
+ register: result
+ ignore_errors: true
+- name: verify test fail if missing arguments required one of
+ ansible.builtin.assert:
+ that:
+ - result is failed
+ - '"one of the following required" in result.msg'
+
+- name: test fail if ssh key not found
+ vultr.cloud.instance:
+ label: my label
+ plan: a plan
+ region: a region
+ os: Debian 11 x64 (bullseye)
+ ssh_keys:
+ - does-not-exist
+ register: result
+ ignore_errors: true
+- name: verify test fail if ssh key not found
+ ansible.builtin.assert:
+ that:
+ - result is failed
+ - '"SSH key names not found: does-not-exist" in result.msg'
+
+- name: test fail if vpc not found
+ vultr.cloud.instance:
+ label: my label
+ plan: a plan
+ region: a region
+ os: Debian 11 x64 (bullseye)
+ vpcs:
+ - does-not-exist
+ register: result
+ ignore_errors: true
+- name: verify test fail if vpc not found
+ ansible.builtin.assert:
+ that:
+ - result is failed
+ - '"VPCs not found: does-not-exist" in result.msg'
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/instance/tasks/main.yml b/ansible_collections/vultr/cloud/tests/integration/targets/instance/tasks/main.yml
new file mode 100644
index 000000000..3a1fba6e0
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/instance/tasks/main.yml
@@ -0,0 +1,16 @@
+---
+- block:
+ - ansible.builtin.import_tasks: tests.yml
+ always:
+ - ansible.builtin.import_role:
+ name: cleanup
+ tasks_from: cleanup_instance
+ - ansible.builtin.import_role:
+ name: cleanup
+ tasks_from: cleanup_firewall_group
+ - ansible.builtin.import_role:
+ name: cleanup
+ tasks_from: cleanup_ssh_key
+ - ansible.builtin.import_role:
+ name: cleanup
+ tasks_from: cleanup_vpc
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/instance/tasks/present.yml b/ansible_collections/vultr/cloud/tests/integration/targets/instance/tasks/present.yml
new file mode 100644
index 000000000..004a9c732
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/instance/tasks/present.yml
@@ -0,0 +1,190 @@
+---
+- name: instance info
+ ansible.builtin.debug:
+ var: instance
+
+- name: test create instance in check mode
+ vultr.cloud.instance:
+ label: "{{ instance.label }}"
+ hostname: "{{ instance.hostname | default(omit) }}"
+ user_data: "{{ instance.user_data | default(omit) }}"
+ firewall_group: "{{ vultr_instance_firewall_group }}"
+ ssh_keys: "{{ instance.ssh_keys | default(omit) }}"
+ plan: "{{ instance.plan }}"
+ ddos_protection: "{{ instance.ddos_protection | default(omit) }}"
+ backups: "{{ instance.backups | default(omit) }}"
+ enable_ipv6: "{{ instance.enable_ipv6 | default(omit) }}"
+ tags: "{{ instance.tags | default(omit) }}"
+ region: "{{ instance.region }}"
+ os: "{{ instance.os | default(omit) }}"
+ app: "{{ instance.app | default(omit) }}"
+ image: "{{ instance.image | default(omit) }}"
+ snapshot: "{{ instance.snapshot | default(omit) }}"
+ vpcs: "{{ instance.vpcs | default(omit) }}"
+ register: result
+ check_mode: true
+- name: verify test create instance in check mode
+ ansible.builtin.assert:
+ that:
+ - result is changed
+
+- name: test create instance
+ vultr.cloud.instance:
+ label: "{{ instance.label }}"
+ hostname: "{{ instance.hostname | default(omit) }}"
+ user_data: "{{ instance.user_data | default(omit) }}"
+ firewall_group: "{{ vultr_instance_firewall_group }}"
+ ssh_keys: "{{ instance.ssh_keys | default(omit) }}"
+ plan: "{{ instance.plan }}"
+ ddos_protection: "{{ instance.ddos_protection | default(omit) }}"
+ backups: "{{ instance.backups | default(omit) }}"
+ enable_ipv6: "{{ instance.enable_ipv6 | default(omit) }}"
+ tags: "{{ instance.tags | default(omit) }}"
+ region: "{{ instance.region }}"
+ os: "{{ instance.os | default(omit) }}"
+ app: "{{ instance.app | default(omit) }}"
+ image: "{{ instance.image | default(omit) }}"
+ snapshot: "{{ instance.snapshot | default(omit) }}"
+ vpcs: "{{ instance.vpcs | default(omit) }}"
+ register: result
+- name: verify test create instance
+ ansible.builtin.assert:
+ that:
+ - result is changed
+ - result.vultr_instance.plan == instance.plan
+ - result.vultr_instance.region == instance.region
+ - "result.vultr_instance.backups == '{{ 'enabled' if instance.backups else 'disabled' }}'"
+ - result.vultr_instance.ddos_protection == instance.ddos_protection
+ - result.vultr_instance.enable_ipv6 == instance.enable_ipv6
+ - result.vultr_instance.vpcs | selectattr('description','equalto','{{ vultr_resource_prefix }}_instance_vpc_1') | list | count == 1
+ - result.vultr_instance.vpcs | selectattr('description','equalto','{{ vultr_resource_prefix }}_instance_vpc_2') | list | count == 1
+ - result.vultr_instance.vpcs | list | count == 2
+
+- name: test create instance idempotence
+ vultr.cloud.instance:
+ label: "{{ instance.label }}"
+ hostname: "{{ instance.hostname | default(omit) }}"
+ user_data: "{{ instance.user_data | default(omit) }}"
+ firewall_group: "{{ vultr_instance_firewall_group }}"
+ ssh_keys: "{{ instance.ssh_keys | default(omit) }}"
+ plan: "{{ instance.plan }}"
+ ddos_protection: "{{ instance.ddos_protection | default(omit) }}"
+ backups: "{{ instance.backups | default(omit) }}"
+ enable_ipv6: "{{ instance.enable_ipv6 | default(omit) }}"
+ tags: "{{ instance.tags | default(omit) }}"
+ region: "{{ instance.region }}"
+ os: "{{ instance.os | default(omit) }}"
+ app: "{{ instance.app | default(omit) }}"
+ image: "{{ instance.image | default(omit) }}"
+ snapshot: "{{ instance.snapshot | default(omit) }}"
+ vpcs: "{{ instance.vpcs | default(omit) }}"
+ register: result
+- name: verify test create instance idempotence
+ ansible.builtin.assert:
+ that:
+ - result is not changed
+ - result.vultr_instance.plan == instance.plan
+ - result.vultr_instance.region == instance.region
+ - "result.vultr_instance.backups == '{{ 'enabled' if instance.backups else 'disabled' }}'"
+ - result.vultr_instance.ddos_protection == instance.ddos_protection
+ - result.vultr_instance.enable_ipv6 == instance.enable_ipv6
+ - result.vultr_instance.vpcs | selectattr('description','equalto','{{ vultr_resource_prefix }}_instance_vpc_1') | list | count == 1
+ - result.vultr_instance.vpcs | selectattr('description','equalto','{{ vultr_resource_prefix }}_instance_vpc_2') | list | count == 1
+ - result.vultr_instance.vpcs | list | count == 2
+
+- name: test update instance in check mode
+ vultr.cloud.instance:
+ label: "{{ instance.label }}"
+ hostname: "{{ instance.hostname | default(omit) }}"
+ user_data: "{{ instance.user_data_update | default(omit) }}"
+ firewall_group: "{{ vultr_instance_firewall_group }}"
+ ssh_keys: "{{ instance.ssh_keys | default(omit) }}"
+ plan: "{{ instance.plan_update }}"
+ ddos_protection: "{{ instance.ddos_protection_update | default(omit) }}"
+ backups: "{{ instance.backups_update | default(omit) }}"
+ enable_ipv6: "{{ instance.enable_ipv6_update | default(omit) }}"
+ tags: "{{ instance.tags_update | default(omit) }}"
+ region: "{{ instance.region }}"
+ os: "{{ instance.os | default(omit) }}"
+ app: "{{ instance.app | default(omit) }}"
+ image: "{{ instance.image | default(omit) }}"
+ snapshot: "{{ instance.snapshot | default(omit) }}"
+ vpcs: "{{ instance.vpcs_update | default(omit) }}"
+ register: result
+ check_mode: true
+- name: verify test update instance in check mode
+ ansible.builtin.assert:
+ that:
+ - result is changed
+ - result.vultr_instance.plan == instance.plan
+ - result.vultr_instance.region == instance.region
+ - "result.vultr_instance.backups == '{{ 'enabled' if instance.backups else 'disabled' }}'"
+ - result.vultr_instance.ddos_protection == instance.ddos_protection
+ - result.vultr_instance.enable_ipv6 == instance.enable_ipv6
+ - result.vultr_instance.vpcs | selectattr('description','equalto','{{ vultr_resource_prefix }}_instance_vpc_1') | list | count == 1
+ - result.vultr_instance.vpcs | selectattr('description','equalto','{{ vultr_resource_prefix }}_instance_vpc_2') | list | count == 1
+ - result.vultr_instance.vpcs | list | count == 2
+
+- name: test update instance
+ vultr.cloud.instance:
+ label: "{{ instance.label }}"
+ hostname: "{{ instance.hostname | default(omit) }}"
+ user_data: "{{ instance.user_data_update | default(omit) }}"
+ firewall_group: "{{ vultr_instance_firewall_group }}"
+ ssh_keys: "{{ instance.ssh_keys | default(omit) }}"
+ plan: "{{ instance.plan_update }}"
+ ddos_protection: "{{ instance.ddos_protection_update | default(omit) }}"
+ backups: "{{ instance.backups_update | default(omit) }}"
+ enable_ipv6: "{{ instance.enable_ipv6_update | default(omit) }}"
+ tags: "{{ instance.tags_update | default(omit) }}"
+ region: "{{ instance.region }}"
+ os: "{{ instance.os | default(omit) }}"
+ app: "{{ instance.app | default(omit) }}"
+ image: "{{ instance.image | default(omit) }}"
+ snapshot: "{{ instance.snapshot | default(omit) }}"
+ vpcs: "{{ instance.vpcs_update | default(omit) }}"
+ register: result
+- name: verify test update instance
+ ansible.builtin.assert:
+ that:
+ - result is changed
+ - result.vultr_instance.plan == instance.plan_update
+ - result.vultr_instance.region == instance.region
+ - "result.vultr_instance.backups == '{{ 'enabled' if instance.backups_update else 'disabled' }}'"
+ - result.vultr_instance.ddos_protection == instance.ddos_protection_update
+ - result.vultr_instance.enable_ipv6 == instance.enable_ipv6_update
+ - result.vultr_instance.vpcs | selectattr('description','equalto','{{ vultr_resource_prefix }}_instance_vpc_1') | list | count == 1
+ - result.vultr_instance.vpcs | selectattr('description','equalto','{{ vultr_resource_prefix }}_instance_vpc_3') | list | count == 1
+ - result.vultr_instance.vpcs | list | count == 2
+
+- name: test update instance idempotence
+ vultr.cloud.instance:
+ label: "{{ instance.label }}"
+ hostname: "{{ instance.hostname | default(omit) }}"
+ user_data: "{{ instance.user_data_update | default(omit) }}"
+ firewall_group: "{{ vultr_instance_firewall_group }}"
+ ssh_keys: "{{ instance.ssh_keys | default(omit) }}"
+ plan: "{{ instance.plan_update }}"
+ ddos_protection: "{{ instance.ddos_protection_update | default(omit) }}"
+ backups: "{{ instance.backups_update | default(omit) }}"
+ enable_ipv6: "{{ instance.enable_ipv6_update | default(omit) }}"
+ tags: "{{ instance.tags_update | default(omit) }}"
+ region: "{{ instance.region }}"
+ os: "{{ instance.os | default(omit) }}"
+ app: "{{ instance.app | default(omit) }}"
+ image: "{{ instance.image | default(omit) }}"
+ snapshot: "{{ instance.snapshot | default(omit) }}"
+ vpcs: "{{ instance.vpcs_update | default(omit) }}"
+ register: result
+- name: verify test update instance idempotence
+ ansible.builtin.assert:
+ that:
+ - result is not changed
+ - result.vultr_instance.plan == instance.plan_update
+ - result.vultr_instance.region == instance.region
+ - "result.vultr_instance.backups == '{{ 'enabled' if instance.backups_update else 'disabled' }}'"
+ - result.vultr_instance.ddos_protection == instance.ddos_protection_update
+ - result.vultr_instance.enable_ipv6 == instance.enable_ipv6_update
+ - result.vultr_instance.vpcs | selectattr('description','equalto','{{ vultr_resource_prefix }}_instance_vpc_1') | list | count == 1
+ - result.vultr_instance.vpcs | selectattr('description','equalto','{{ vultr_resource_prefix }}_instance_vpc_3') | list | count == 1
+ - result.vultr_instance.vpcs | list | count == 2
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/instance/tasks/reinstall.yml b/ansible_collections/vultr/cloud/tests/integration/targets/instance/tasks/reinstall.yml
new file mode 100644
index 000000000..6365ac0f5
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/instance/tasks/reinstall.yml
@@ -0,0 +1,28 @@
+---
+- name: instance info
+ ansible.builtin.debug:
+ var: instance
+
+- name: test reinstall instance in check mode
+ vultr.cloud.instance:
+ label: "{{ instance.label }}"
+ region: "{{ instance.region }}"
+ state: reinstalled
+ register: result
+ check_mode: true
+- name: verify test reinstall instance in check mode
+ ansible.builtin.assert:
+ that:
+ - result is changed
+ - result.vultr_instance.power_status == "running"
+
+- name: test reinstall instance
+ vultr.cloud.instance:
+ label: "{{ instance.label }}"
+ region: "{{ instance.region }}"
+ state: reinstalled
+ register: result
+- name: verify test reinstall instance
+ ansible.builtin.assert:
+ that:
+ - result is changed
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/instance/tasks/stop-start.yml b/ansible_collections/vultr/cloud/tests/integration/targets/instance/tasks/stop-start.yml
new file mode 100644
index 000000000..23cc3cd56
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/instance/tasks/stop-start.yml
@@ -0,0 +1,78 @@
+---
+- name: instance info
+ ansible.builtin.debug:
+ var: instance
+
+- name: test stop instance in check mode
+ vultr.cloud.instance:
+ label: "{{ instance.label }}"
+ region: "{{ instance.region }}"
+ state: stopped
+ register: result
+ check_mode: true
+- name: verify test stop instance in check mode
+ ansible.builtin.assert:
+ that:
+ - result is changed
+ - result.vultr_instance.power_status == "running"
+
+- name: test stop instance
+ vultr.cloud.instance:
+ label: "{{ instance.label }}"
+ region: "{{ instance.region }}"
+ state: stopped
+ register: result
+- name: verify test stop instance
+ ansible.builtin.assert:
+ that:
+ - result is changed
+ - result.vultr_instance.power_status == "stopped"
+
+- name: test stop instance idempotence
+ vultr.cloud.instance:
+ label: "{{ instance.label }}"
+ region: "{{ instance.region }}"
+ state: stopped
+ register: result
+- name: verify test stop instance idempotence
+ ansible.builtin.assert:
+ that:
+ - result is not changed
+ - result.vultr_instance.power_status == "stopped"
+
+- name: test start instance in check mode
+ vultr.cloud.instance:
+ label: "{{ instance.label }}"
+ region: "{{ instance.region }}"
+ state: started
+ register: result
+ check_mode: true
+- name: verify test start instance in check mode
+ ansible.builtin.assert:
+ that:
+ - result is changed
+ - result.vultr_instance.power_status == "stopped"
+
+- name: test start instance
+ vultr.cloud.instance:
+ label: "{{ instance.label }}"
+ region: "{{ instance.region }}"
+ state: started
+ register: result
+- name: verify test start instance
+ ansible.builtin.assert:
+ that:
+ - result is changed
+ - result.vultr_instance.power_status == "running"
+
+- name: test start instance idempotence
+ vultr.cloud.instance:
+ label: "{{ instance.label }}"
+ region: "{{ instance.region }}"
+ state: started
+ register: result
+- name: verify test start instance idempotence
+ ansible.builtin.assert:
+ that:
+ - result is not changed
+ - result.vultr_instance.power_status == "running"
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/instance/tasks/tests.yml b/ansible_collections/vultr/cloud/tests/integration/targets/instance/tasks/tests.yml
new file mode 100644
index 000000000..e35c426de
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/instance/tasks/tests.yml
@@ -0,0 +1,70 @@
+# Copyright (c) 2022, René Moser <mail@renemoser.net>
+# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
+---
+- name: setup
+ vultr.cloud.instance:
+ label: "{{ instance.label }}"
+ region: "{{ instance.region }}"
+ state: absent
+ with_items: "{{ vultr_instances }}"
+ loop_control:
+ loop_var: instance
+
+- ansible.builtin.import_tasks: failures.yml
+
+- name: setup firewall group
+ vultr.cloud.firewall_group:
+ name: "{{ vultr_instance_firewall_group }}"
+
+- name: setup ssh key
+ vultr.cloud.ssh_key:
+ name: "{{ vultr_instance_ssh_key_name }}"
+ ssh_key: "{{ vultr_instance_ssh_key }}"
+
+- name: setup vpcs
+ vultr.cloud.vpc:
+ description: "{{ item.description }}"
+ v4_subnet: "{{ item.v4_subnet }}"
+ v4_subnet_mask: "{{ item.v4_subnet_mask }}"
+ region: "{{ item.region }}"
+ with_items: "{{ vutr_instance_vpcs }}"
+
+- ansible.builtin.include_tasks: present.yml
+ with_items: "{{ vultr_instances }}"
+ loop_control:
+ loop_var: instance
+
+- ansible.builtin.include_tasks: stop-start.yml
+ with_items: "{{ vultr_instances }}"
+ loop_control:
+ loop_var: instance
+
+- ansible.builtin.include_tasks: reinstall.yml
+ vars:
+ instance: "{{ vultr_instances | first }}"
+
+- ansible.builtin.include_tasks: absent.yml
+ with_items: "{{ vultr_instances }}"
+ loop_control:
+ loop_var: instance
+
+- name: cleanup firewall group
+ vultr.cloud.firewall_group:
+ name: "{{ vultr_instance_firewall_group }}"
+ state: absent
+
+- name: cleanup ssh key
+ vultr.cloud.ssh_key:
+ name: "{{ vultr_instance_ssh_key_name }}"
+ state: absent
+
+- name: cleanup vpcs
+ vultr.cloud.vpc:
+ description: "{{ item.description }}"
+ region: "{{ item.region }}"
+ state: absent
+ with_items: "{{ vutr_instance_vpcs }}"
+ retries: 5
+ delay: 3
+ register: result
+ until: result is not failed
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/instance_info/aliases b/ansible_collections/vultr/cloud/tests/integration/targets/instance_info/aliases
new file mode 100644
index 000000000..c749ce7ca
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/instance_info/aliases
@@ -0,0 +1,3 @@
+cloud/vultr
+needs/target/common
+needs/target/cleanup
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/instance_info/defaults/main.yml b/ansible_collections/vultr/cloud/tests/integration/targets/instance_info/defaults/main.yml
new file mode 100644
index 000000000..463a901ed
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/instance_info/defaults/main.yml
@@ -0,0 +1,23 @@
+# Copyright (c) 2022, René Moser <mail@renemoser.net>
+# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
+---
+vultr_region1: ams
+vultr_region2: cdg
+
+vultr_instances:
+ - label: "{{ vultr_resource_prefix }}_info1"
+ hostname: info1
+ plan: vc2-1c-1gb
+ tags:
+ - one
+ - two
+ region: "{{ vultr_region1 }}"
+ os: Debian 11 x64 (bullseye)
+ - label: "{{ vultr_resource_prefix }}_info2"
+ hostname: info2
+ plan: vc2-1c-1gb
+ tags:
+ - three
+ - four
+ region: "{{ vultr_region2 }}"
+ os: Debian 11 x64 (bullseye)
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/instance_info/meta/main.yml b/ansible_collections/vultr/cloud/tests/integration/targets/instance_info/meta/main.yml
new file mode 100644
index 000000000..2083f0e12
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/instance_info/meta/main.yml
@@ -0,0 +1,3 @@
+---
+dependencies:
+ - common
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/instance_info/tasks/main.yml b/ansible_collections/vultr/cloud/tests/integration/targets/instance_info/tasks/main.yml
new file mode 100644
index 000000000..352cfa20a
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/instance_info/tasks/main.yml
@@ -0,0 +1,7 @@
+---
+- block:
+ - ansible.builtin.import_tasks: tests.yml
+ always:
+ - ansible.builtin.import_role:
+ name: cleanup
+ tasks_from: cleanup_instance
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/instance_info/tasks/tests.yml b/ansible_collections/vultr/cloud/tests/integration/targets/instance_info/tasks/tests.yml
new file mode 100644
index 000000000..204d071af
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/instance_info/tasks/tests.yml
@@ -0,0 +1,62 @@
+# Copyright (c) 2022, René Moser <mail@renemoser.net>
+# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
+---
+- name: setup
+ vultr.cloud.instance:
+ label: "{{ instance.label }}"
+ hostname: "{{ instance.hostname }}"
+ plan: "{{ instance.plan }}"
+ tags: "{{ instance.tags }}"
+ region: "{{ instance.region }}"
+ os: "{{ instance.os }}"
+ register: result
+ with_items: "{{ vultr_instances }}"
+ loop_control:
+ loop_var: instance
+
+- name: test gather vultr instance info in check mode
+ vultr.cloud.instance_info:
+ check_mode: true
+ register: result
+- name: verify test gather vultr instance info in check mode
+ ansible.builtin.assert:
+ that:
+ - result.vultr_instance_info|selectattr('label','search','^{{ vultr_resource_prefix }}') | list | count == 2
+ - result.vultr_instance_info|selectattr('label','equalto','{{ vultr_resource_prefix }}_info1') | list | count == 1
+
+- name: test gather vultr instance info
+ vultr.cloud.instance_info:
+ register: result
+- name: verify test gather vultr instance info
+ ansible.builtin.assert:
+ that:
+ - result.vultr_instance_info|selectattr('label','search','^{{ vultr_resource_prefix }}') | list | count == 2
+ - result.vultr_instance_info|selectattr('label','equalto','{{ vultr_resource_prefix }}_info1') | list | count == 1
+
+- name: test gather vultr instance info filter region
+ vultr.cloud.instance_info:
+ region: "{{ vultr_region1 }}"
+ register: result
+- name: verify test gather vultr instance info filter region
+ ansible.builtin.assert:
+ that:
+ - result.vultr_instance_info|selectattr('label','search','^{{ vultr_resource_prefix }}') | list | count == 1
+
+- name: test gather vultr instance info filter label
+ vultr.cloud.instance_info:
+ label: "{{ vultr_resource_prefix }}_info2"
+ register: result
+- name: verify test gather vultr instance info
+ ansible.builtin.assert:
+ that:
+ - result.vultr_instance_info|selectattr('label','search','^{{ vultr_resource_prefix }}') | list | count == 1
+ - result.vultr_instance_info|selectattr('label','equalto','{{ vultr_resource_prefix }}_info2') | list | count == 1
+
+- name: cleanup
+ vultr.cloud.instance:
+ label: "{{ instance.label }}"
+ region: "{{ instance.region }}"
+ state: absent
+ with_items: "{{ vultr_instances }}"
+ loop_control:
+ loop_var: instance
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/os_info/aliases b/ansible_collections/vultr/cloud/tests/integration/targets/os_info/aliases
new file mode 100644
index 000000000..bf469bb90
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/os_info/aliases
@@ -0,0 +1 @@
+cloud/vultr
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/os_info/tasks/main.yml b/ansible_collections/vultr/cloud/tests/integration/targets/os_info/tasks/main.yml
new file mode 100644
index 000000000..0bcdf2728
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/os_info/tasks/main.yml
@@ -0,0 +1,22 @@
+# Copyright (c) 2018, Yanis Guenane <yanis+ansible@guenane.org>
+# Copyright (c) 2021, René Moser <mail@renemoser.net>
+# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
+---
+- name: test get vultr os infos in check mode
+ vultr.cloud.os_info:
+ check_mode: true
+ register: result
+
+- name: verify test get vultr os infos in check mode
+ ansible.builtin.assert:
+ that:
+ - result.vultr_os_info|selectattr('name','equalto', 'CentOS 7 x64') | list | count == 1
+
+- name: test get vultr os fact
+ vultr.cloud.os_info:
+ register: result
+
+- name: verify test get vultr os infos
+ ansible.builtin.assert:
+ that:
+ - result.vultr_os_info|selectattr('name','equalto', 'CentOS 7 x64') | list | count == 1
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/plan_info/aliases b/ansible_collections/vultr/cloud/tests/integration/targets/plan_info/aliases
new file mode 100644
index 000000000..bf469bb90
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/plan_info/aliases
@@ -0,0 +1 @@
+cloud/vultr
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/plan_info/tasks/main.yml b/ansible_collections/vultr/cloud/tests/integration/targets/plan_info/tasks/main.yml
new file mode 100644
index 000000000..e0050803c
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/plan_info/tasks/main.yml
@@ -0,0 +1,22 @@
+# Copyright (c) 2018, Yanis Guenane <yanis+ansible@guenane.org>
+# Copyright (c) 2021, René Moser <mail@renemoser.net>
+# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
+---
+- name: test gather vultr plan info in check mode
+ vultr.cloud.plan_info:
+ check_mode: true
+ register: result
+
+- name: verify test gather vultr plan info in check mode
+ ansible.builtin.assert:
+ that:
+ - result.vultr_plan_info|selectattr('id','equalto','vhf-8c-32gb') | list | count == 1
+
+- name: test gather vultr plan info
+ vultr.cloud.plan_info:
+ register: result
+
+- name: verify test gather vultr plan info
+ ansible.builtin.assert:
+ that:
+ - result.vultr_plan_info|selectattr('id','equalto','vhf-8c-32gb') | list | count == 1
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/plan_metal_info/aliases b/ansible_collections/vultr/cloud/tests/integration/targets/plan_metal_info/aliases
new file mode 100644
index 000000000..bf469bb90
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/plan_metal_info/aliases
@@ -0,0 +1 @@
+cloud/vultr
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/plan_metal_info/tasks/main.yml b/ansible_collections/vultr/cloud/tests/integration/targets/plan_metal_info/tasks/main.yml
new file mode 100644
index 000000000..59824faa7
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/plan_metal_info/tasks/main.yml
@@ -0,0 +1,23 @@
+# Copyright (c) 2018, Yanis Guenane <yanis+ansible@guenane.org>
+# Copyright (c) 2020, Simon Bärlocher <s.baerlocher@sbaerlocher.ch>
+# Copyright (c) 2021, René Moser <mail@renemoser.net>
+# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
+---
+- name: test gather vultr plan bare metal info in check mode
+ vultr.cloud.plan_metal_info:
+ check_mode: true
+ register: result
+
+- name: verify test gather vultr plan bare metal info in check mode
+ ansible.builtin.assert:
+ that:
+ - result.vultr_plan_metal_info|selectattr('id','equalto','vbm-4c-32gb') | list | count == 1
+
+- name: test gather vultr plan baremetal info
+ vultr.cloud.plan_metal_info:
+ register: result
+
+- name: verify test gather vultr plan bare metal info
+ ansible.builtin.assert:
+ that:
+ - result.vultr_plan_metal_info|selectattr('id','equalto','vbm-4c-32gb') | list | count == 1
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/region_info/aliases b/ansible_collections/vultr/cloud/tests/integration/targets/region_info/aliases
new file mode 100644
index 000000000..bf469bb90
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/region_info/aliases
@@ -0,0 +1 @@
+cloud/vultr
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/region_info/tasks/main.yml b/ansible_collections/vultr/cloud/tests/integration/targets/region_info/tasks/main.yml
new file mode 100644
index 000000000..117ae24cc
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/region_info/tasks/main.yml
@@ -0,0 +1,22 @@
+# Copyright (c) 2018, Yanis Guenane <yanis+ansible@guenane.org>
+# Copyright (c) 2021, René Moser <mail@renemoser.net>
+# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
+---
+- name: test gather vultr region info in check mode
+ vultr.cloud.region_info:
+ check_mode: true
+ register: result
+
+- name: verify test gather vultr region info in check mode
+ ansible.builtin.assert:
+ that:
+ - result.vultr_region_info|selectattr('city','equalto','Atlanta') | list | count == 1
+
+- name: test gather vultr region info
+ vultr.cloud.region_info:
+ register: result
+
+- name: verify test gather vultr region info
+ ansible.builtin.assert:
+ that:
+ - result.vultr_region_info|selectattr('city','equalto','Atlanta') | list | count == 1
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/reserved_ip/aliases b/ansible_collections/vultr/cloud/tests/integration/targets/reserved_ip/aliases
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/reserved_ip/aliases
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/reserved_ip/defaults/main.yml b/ansible_collections/vultr/cloud/tests/integration/targets/reserved_ip/defaults/main.yml
new file mode 100644
index 000000000..60634dbeb
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/reserved_ip/defaults/main.yml
@@ -0,0 +1,9 @@
+# Copyright (c) 2021, René Moser <mail@renemoser.net>
+# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
+---
+vultr_reserved_ip_name: "{{ vultr_resource_prefix }}-ip"
+
+# TODO: topic of changes
+vultr_server_name: "{{ vultr_resource_prefix }}_vm"
+vultr_server_os: CentOS 7 x64
+vultr_server_plan: 1024 MB RAM,25 GB SSD,1.00 TB BW
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/reserved_ip/meta/main.yml b/ansible_collections/vultr/cloud/tests/integration/targets/reserved_ip/meta/main.yml
new file mode 100644
index 000000000..2083f0e12
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/reserved_ip/meta/main.yml
@@ -0,0 +1,3 @@
+---
+dependencies:
+ - common
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/reserved_ip/tasks/main.yml b/ansible_collections/vultr/cloud/tests/integration/targets/reserved_ip/tasks/main.yml
new file mode 100644
index 000000000..22af95139
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/reserved_ip/tasks/main.yml
@@ -0,0 +1,10 @@
+---
+- block:
+ - ansible.builtin.import_tasks: tests.yml
+ always:
+ - ansible.builtin.import_role:
+ name: cleanup
+ tasks_from: cleanup_reserved_ip
+ - ansible.builtin.import_role:
+ name: cleanup
+ tasks_from: cleanup_instance
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/reserved_ip/tasks/tests.yml b/ansible_collections/vultr/cloud/tests/integration/targets/reserved_ip/tasks/tests.yml
new file mode 100644
index 000000000..a46b56366
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/reserved_ip/tasks/tests.yml
@@ -0,0 +1,240 @@
+# Copyright (c) 2021, René Moser <mail@renemoser.net>
+# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
+---
+- name: setup
+ vultr.cloud.reserved_ip:
+ label: "{{ vultr_reserved_ip_name }}"
+ ip_type: v4
+ region: ewr
+ state: absent
+ register: result
+- name: verify setup
+ ansible.builtin.assert:
+ that:
+ - result is success
+
+- name: test fail if missing args
+ vultr.cloud.reserved_ip:
+ register: result
+ ignore_errors: true
+- name: verify test fail if missing args
+ ansible.builtin.assert:
+ that:
+ - result is failed
+ - 'result.msg == "missing required arguments: ip_type, label, region"'
+
+# TODO: topic of changes
+- name: setup create the server
+ ngine_io.vultr.vultr_server:
+ name: "{{ vultr_server_name }}"
+ os: "{{ vultr_server_os }}"
+ plan: "{{ vultr_server_plan }}"
+ region: New Jersey
+ register: server
+
+- name: test create reserved ip in check mode
+ vultr.cloud.reserved_ip:
+ label: "{{ vultr_reserved_ip_name }}"
+ ip_type: v4
+ region: ewr
+ register: result
+ check_mode: true
+- name: verify test create reserved ip in check mode
+ ansible.builtin.assert:
+ that:
+ - result is changed
+
+- name: test create reserved ip
+ vultr.cloud.reserved_ip:
+ label: "{{ vultr_reserved_ip_name }}"
+ ip_type: v4
+ region: ewr
+ register: result
+- name: verify test create reserved ip
+ ansible.builtin.assert:
+ that:
+ - result is changed
+ - result.vultr_reserved_ip.label == vultr_reserved_ip_name
+ - not result.vultr_reserved_ip.instance_id
+ - result.vultr_reserved_ip.subnet is defined
+ - result.vultr_reserved_ip.ip_type == 'v4'
+
+- name: test create reserved ip idempotence
+ vultr.cloud.reserved_ip:
+ label: "{{ vultr_reserved_ip_name }}"
+ ip_type: v4
+ region: ewr
+ register: result
+- name: verify test create reserved ip idempotence
+ ansible.builtin.assert:
+ that:
+ - result is not changed
+ - result.vultr_reserved_ip.label == vultr_reserved_ip_name
+ - not result.vultr_reserved_ip.instance_id
+ - result.vultr_reserved_ip.subnet is defined
+ - result.vultr_reserved_ip.ip_type == 'v4'
+
+- name: test attach instance of reserved ip in check mode
+ vultr.cloud.reserved_ip:
+ label: "{{ vultr_reserved_ip_name }}"
+ ip_type: v4
+ region: ewr
+ instance_name: "{{ vultr_server_name }}"
+ register: result
+ check_mode: true
+- name: verify test detach instance of reserved ip in check mode
+ ansible.builtin.assert:
+ that:
+ - result is changed
+ - result.vultr_reserved_ip.label == vultr_reserved_ip_name
+ - not result.vultr_reserved_ip.instance_id
+ - result.vultr_reserved_ip.subnet
+ - result.vultr_reserved_ip.ip_type == 'v4'
+
+- name: test attach instance of reserved ip
+ vultr.cloud.reserved_ip:
+ label: "{{ vultr_reserved_ip_name }}"
+ ip_type: v4
+ region: ewr
+ instance_name: "{{ vultr_server_name }}"
+ register: result
+- name: verify test attach instance of reserved ip
+ ansible.builtin.assert:
+ that:
+ - result is changed
+ - result.vultr_reserved_ip.label == vultr_reserved_ip_name
+ - result.vultr_reserved_ip.instance_id
+ - result.vultr_reserved_ip.subnet
+ - result.vultr_reserved_ip.ip_type == 'v4'
+
+- name: test attach instance of reserved ip idempotence
+ vultr.cloud.reserved_ip:
+ label: "{{ vultr_reserved_ip_name }}"
+ ip_type: v4
+ region: ewr
+ instance_name: "{{ vultr_server_name }}"
+ register: result
+- name: verify test attach instance of reserved ip idempotence
+ ansible.builtin.assert:
+ that:
+ - result is not changed
+ - result.vultr_reserved_ip.label == vultr_reserved_ip_name
+ - result.vultr_reserved_ip.instance_id
+ - result.vultr_reserved_ip.subnet
+ - result.vultr_reserved_ip.ip_type == 'v4'
+
+- name: test ignore instance attached reserved ip idempotence
+ vultr.cloud.reserved_ip:
+ label: "{{ vultr_reserved_ip_name }}"
+ ip_type: v4
+ region: ewr
+ register: result
+- name: verify test test ignore instance attached reserved ip idempotence
+ ansible.builtin.assert:
+ that:
+ - result is not changed
+ - result.vultr_reserved_ip.label == vultr_reserved_ip_name
+ - result.vultr_reserved_ip.instance_id
+ - result.vultr_reserved_ip.subnet
+ - result.vultr_reserved_ip.ip_type == 'v4'
+
+- name: test detach instance of reserved ip in check mode
+ vultr.cloud.reserved_ip:
+ label: "{{ vultr_reserved_ip_name }}"
+ ip_type: v4
+ region: ewr
+ instance_id: ""
+ register: result
+ check_mode: true
+- name: verify test detach instance of reserved ip in check mode
+ ansible.builtin.assert:
+ that:
+ - result is changed
+ - result.vultr_reserved_ip.label == vultr_reserved_ip_name
+ - result.vultr_reserved_ip.instance_id
+ - result.vultr_reserved_ip.subnet
+ - result.vultr_reserved_ip.ip_type == 'v4'
+
+- name: test detach instance of reserved ip
+ vultr.cloud.reserved_ip:
+ label: "{{ vultr_reserved_ip_name }}"
+ ip_type: v4
+ region: ewr
+ instance_id: ""
+ register: result
+- name: verify test detach instance of reserved ip
+ ansible.builtin.assert:
+ that:
+ - result is changed
+ - result.vultr_reserved_ip.label == vultr_reserved_ip_name
+ - not result.vultr_reserved_ip.instance_id
+ - result.vultr_reserved_ip.subnet
+ - result.vultr_reserved_ip.ip_type == 'v4'
+
+- name: test detach instance of reserved ip idempotence
+ vultr.cloud.reserved_ip:
+ label: "{{ vultr_reserved_ip_name }}"
+ ip_type: v4
+ region: ewr
+ instance_id: ""
+ register: result
+- name: verify test detach instance of reserved ip idempotence
+ ansible.builtin.assert:
+ that:
+ - result is not changed
+ - result.vultr_reserved_ip.label == vultr_reserved_ip_name
+ - not result.vultr_reserved_ip.instance_id
+ - result.vultr_reserved_ip.subnet
+ - result.vultr_reserved_ip.ip_type == 'v4'
+
+- name: test absent reserved ip in check mode
+ vultr.cloud.reserved_ip:
+ label: "{{ vultr_reserved_ip_name }}"
+ ip_type: v4
+ region: ewr
+ state: absent
+ register: result
+ check_mode: true
+- name: verify test absent reserved ip in check mode
+ ansible.builtin.assert:
+ that:
+ - result is changed
+ - result.vultr_reserved_ip.label == vultr_reserved_ip_name
+ - not result.vultr_reserved_ip.instance_id
+ - result.vultr_reserved_ip.subnet
+ - result.vultr_reserved_ip.ip_type == 'v4'
+
+- name: test absent reserved ip
+ vultr.cloud.reserved_ip:
+ label: "{{ vultr_reserved_ip_name }}"
+ ip_type: v4
+ region: ewr
+ state: absent
+ register: result
+- name: verify test absent reserved ip
+ ansible.builtin.assert:
+ that:
+ - result is changed
+ - result.vultr_reserved_ip.label == vultr_reserved_ip_name
+ - result.vultr_reserved_ip.label == vultr_reserved_ip_name
+ - not result.vultr_reserved_ip.instance_id
+ - result.vultr_reserved_ip.subnet
+ - result.vultr_reserved_ip.ip_type == 'v4'
+
+- name: test absent reserved ip idempotence
+ vultr.cloud.reserved_ip:
+ label: "{{ vultr_reserved_ip_name }}"
+ ip_type: v4
+ region: ewr
+ state: absent
+ register: result
+- name: verify test absent reserved ip idempotence
+ ansible.builtin.assert:
+ that:
+ - result is not changed
+
+# TODO: topic of changes
+- name: cleanup the server
+ ngine_io.vultr.vultr_server:
+ name: "{{ vultr_server_name }}"
+ state: absent
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/snapshot/aliases b/ansible_collections/vultr/cloud/tests/integration/targets/snapshot/aliases
new file mode 100644
index 000000000..c749ce7ca
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/snapshot/aliases
@@ -0,0 +1,3 @@
+cloud/vultr
+needs/target/common
+needs/target/cleanup
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/snapshot/defaults/main.yml b/ansible_collections/vultr/cloud/tests/integration/targets/snapshot/defaults/main.yml
new file mode 100644
index 000000000..d6566f839
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/snapshot/defaults/main.yml
@@ -0,0 +1,15 @@
+# Copyright (c) 2023, René Moser <mail@renemoser.net>
+# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
+---
+vultr_instance:
+ label: "snap1"
+ plan: vc2-1c-1gb
+ region: ams
+ os: Debian 11 x64 (bullseye)
+
+vultr_snapshots:
+ - description: "{{ vultr_resource_prefix }}_desc1"
+ instance: "{{ vultr_instance.label }}"
+
+ - description: "{{ vultr_resource_prefix }}_desc2"
+ url: https://cloud.debian.org/images/cloud/bullseye/latest/debian-11-generic-amd64.raw
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/snapshot/meta/main.yml b/ansible_collections/vultr/cloud/tests/integration/targets/snapshot/meta/main.yml
new file mode 100644
index 000000000..2083f0e12
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/snapshot/meta/main.yml
@@ -0,0 +1,3 @@
+---
+dependencies:
+ - common
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/snapshot/tasks/absent.yml b/ansible_collections/vultr/cloud/tests/integration/targets/snapshot/tasks/absent.yml
new file mode 100644
index 000000000..ee0ac4e6b
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/snapshot/tasks/absent.yml
@@ -0,0 +1,35 @@
+---
+- name: snapshot info
+ ansible.builtin.debug:
+ var: snapshot
+
+- name: test absent snapshot in check mode
+ vultr.cloud.snapshot:
+ description: "{{ snapshot.description }}"
+ state: absent
+ register: result
+ check_mode: true
+- name: verify test absent snapshot in check mode
+ ansible.builtin.assert:
+ that:
+ - result is changed
+
+- name: test absent snapshot
+ vultr.cloud.snapshot:
+ description: "{{ snapshot.description }}"
+ state: absent
+ register: result
+- name: verify test absent snapshot
+ ansible.builtin.assert:
+ that:
+ - result is changed
+
+- name: test absent snapshot idempotence
+ vultr.cloud.snapshot:
+ description: "{{ snapshot.description }}"
+ state: absent
+ register: result
+- name: verify test absent snapshot idempotence
+ ansible.builtin.assert:
+ that:
+ - result is not changed
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/snapshot/tasks/failures.yml b/ansible_collections/vultr/cloud/tests/integration/targets/snapshot/tasks/failures.yml
new file mode 100644
index 000000000..d186fc67a
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/snapshot/tasks/failures.yml
@@ -0,0 +1,33 @@
+---
+- name: test fail if missing arguments
+ vultr.cloud.snapshot:
+ register: result
+ ignore_errors: true
+- name: verify test fail if missing arguments
+ ansible.builtin.assert:
+ that:
+ - result is failed
+ - 'result.msg == "missing required arguments: description"'
+
+- name: test fail if missing arguments required one of
+ vultr.cloud.snapshot:
+ description: my snapshot
+ register: result
+ ignore_errors: true
+- name: verify test fail if missing arguments required one of
+ ansible.builtin.assert:
+ that:
+ - result is failed
+ - '"one of the following required" in result.msg'
+
+- name: test fail if instance not found
+ vultr.cloud.snapshot:
+ description: my snapshot
+ instance: does-not-exist
+ register: result
+ ignore_errors: true
+- name: verify test fail if instance not found
+ ansible.builtin.assert:
+ that:
+ - result is failed
+ - '"No Resource /instances with label found: does-not-exist" in result.msg'
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/snapshot/tasks/main.yml b/ansible_collections/vultr/cloud/tests/integration/targets/snapshot/tasks/main.yml
new file mode 100644
index 000000000..aa29bdb94
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/snapshot/tasks/main.yml
@@ -0,0 +1,10 @@
+---
+- block:
+ - ansible.builtin.import_tasks: tests.yml
+ always:
+ - ansible.builtin.import_role:
+ name: cleanup
+ tasks_from: cleanup_snapshot
+ - ansible.builtin.import_role:
+ name: cleanup
+ tasks_from: cleanup_instance
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/snapshot/tasks/present.yml b/ansible_collections/vultr/cloud/tests/integration/targets/snapshot/tasks/present.yml
new file mode 100644
index 000000000..ee2aed1d4
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/snapshot/tasks/present.yml
@@ -0,0 +1,36 @@
+---
+- name: test create snapshot in check mode
+ vultr.cloud.snapshot:
+ description: "{{ snapshot.description }}"
+ instance: "{{ snapshot.instance | default(omit) }}"
+ url: "{{ snapshot.url | default(omit) }}"
+ register: result
+ check_mode: true
+- name: verify test create snapshot in check mode
+ ansible.builtin.assert:
+ that:
+ - result is changed
+
+- name: test create snapshot
+ vultr.cloud.snapshot:
+ description: "{{ snapshot.description }}"
+ instance: "{{ snapshot.instance | default(omit) }}"
+ url: "{{ snapshot.url | default(omit) }}"
+ register: result
+- name: verify test create snapshot
+ ansible.builtin.assert:
+ that:
+ - result is changed
+ - result.vultr_snapshot.description == snapshot.description
+
+- name: test create snapshot idempotence
+ vultr.cloud.snapshot:
+ description: "{{ snapshot.description }}"
+ instance: "{{ snapshot.instance | default(omit) }}"
+ url: "{{ snapshot.url | default(omit) }}"
+ register: result
+- name: verify test create snapshot idempotence
+ ansible.builtin.assert:
+ that:
+ - result is not changed
+ - result.vultr_snapshot.description == snapshot.description
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/snapshot/tasks/tests.yml b/ansible_collections/vultr/cloud/tests/integration/targets/snapshot/tasks/tests.yml
new file mode 100644
index 000000000..6ed8a5a98
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/snapshot/tasks/tests.yml
@@ -0,0 +1,35 @@
+# Copyright (c) 2023, René Moser <mail@renemoser.net>
+# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
+---
+- name: setup
+ vultr.cloud.snapshot:
+ description: "{{ snapshot.description }}"
+ state: absent
+ with_items: "{{ vultr_snapshots }}"
+ loop_control:
+ loop_var: snapshot
+
+- ansible.builtin.import_tasks: failures.yml
+
+- name: setup instance
+ vultr.cloud.instance:
+ label: "{{ vultr_instance.label }}"
+ plan: "{{ vultr_instance.plan }}"
+ region: "{{ vultr_instance.region }}"
+ os: "{{ vultr_instance.os }}"
+
+- ansible.builtin.include_tasks: present.yml
+ with_items: "{{ vultr_snapshots }}"
+ loop_control:
+ loop_var: snapshot
+
+- ansible.builtin.include_tasks: absent.yml
+ with_items: "{{ vultr_snapshots }}"
+ loop_control:
+ loop_var: snapshot
+
+- name: cleanup instance
+ vultr.cloud.instance:
+ label: "{{ vultr_instance.label }}"
+ region: "{{ vultr_instance.region }}"
+ state: absent
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/snapshot_info/aliases b/ansible_collections/vultr/cloud/tests/integration/targets/snapshot_info/aliases
new file mode 100644
index 000000000..c749ce7ca
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/snapshot_info/aliases
@@ -0,0 +1,3 @@
+cloud/vultr
+needs/target/common
+needs/target/cleanup
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/snapshot_info/defaults/main.yml b/ansible_collections/vultr/cloud/tests/integration/targets/snapshot_info/defaults/main.yml
new file mode 100644
index 000000000..d79abfafd
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/snapshot_info/defaults/main.yml
@@ -0,0 +1,3 @@
+---
+vultr_snapshot_description: "{{ vultr_resource_prefix }}_snap_info"
+vultr_snapshot_url: https://cloud.debian.org/images/cloud/bullseye/latest/debian-11-generic-amd64.raw
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/snapshot_info/meta/main.yml b/ansible_collections/vultr/cloud/tests/integration/targets/snapshot_info/meta/main.yml
new file mode 100644
index 000000000..2083f0e12
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/snapshot_info/meta/main.yml
@@ -0,0 +1,3 @@
+---
+dependencies:
+ - common
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/snapshot_info/tasks/main.yml b/ansible_collections/vultr/cloud/tests/integration/targets/snapshot_info/tasks/main.yml
new file mode 100644
index 000000000..55bffd3ee
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/snapshot_info/tasks/main.yml
@@ -0,0 +1,7 @@
+---
+- block:
+ - ansible.builtin.import_tasks: tests.yml
+ always:
+ - ansible.builtin.import_role:
+ name: cleanup
+ tasks_from: cleanup_snapshot
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/snapshot_info/tasks/tests.yml b/ansible_collections/vultr/cloud/tests/integration/targets/snapshot_info/tasks/tests.yml
new file mode 100644
index 000000000..fe7a195ce
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/snapshot_info/tasks/tests.yml
@@ -0,0 +1,34 @@
+# Copyright (c) 2023, René Moser <mail@renemoser.net>
+# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
+---
+- name: test gather snapshot info - empty resources
+ vultr.cloud.snapshot_info:
+
+- name: Create the snapshot
+ vultr.cloud.snapshot:
+ description: "{{ vultr_snapshot_description }}"
+ url: "{{ vultr_snapshot_url }}"
+
+- name: test gather snapshot info in check mode
+ vultr.cloud.snapshot_info:
+ check_mode: true
+ register: result
+
+- name: verify test gather vultr snapshot info in check mode
+ ansible.builtin.assert:
+ that:
+ - result.vultr_snapshot_info|selectattr('description','equalto','{{ vultr_snapshot_description }}') | list | count == 1
+
+- name: test gather snapshot info
+ vultr.cloud.snapshot_info:
+ register: result
+
+- name: verify test gather vultr snapshot info
+ ansible.builtin.assert:
+ that:
+ - result.vultr_snapshot_info|selectattr('description','equalto','{{ vultr_snapshot_description }}') | list | count == 1
+
+- name: Delete the snapshot
+ vultr.cloud.snapshot:
+ name: "{{ vultr_snapshot_description }}"
+ state: absent
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/ssh_key/aliases b/ansible_collections/vultr/cloud/tests/integration/targets/ssh_key/aliases
new file mode 100644
index 000000000..c749ce7ca
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/ssh_key/aliases
@@ -0,0 +1,3 @@
+cloud/vultr
+needs/target/common
+needs/target/cleanup
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/ssh_key/defaults/main.yml b/ansible_collections/vultr/cloud/tests/integration/targets/ssh_key/defaults/main.yml
new file mode 100644
index 000000000..14ed4d86e
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/ssh_key/defaults/main.yml
@@ -0,0 +1,6 @@
+# Copyright (c) 2021, René Moser <mail@renemoser.net>
+# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
+---
+vultr_ssh_key_name: "{{ vultr_resource_prefix }}_ansible-ssh-key"
+vultr_ssh_key: "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAgEAyWYItY+3w5b8PdGRoz0oY5mufqydW96naE+VM3JSvJFAUS08rAjQQpQ03ymoALeHQy6JVZbcgecxn6p0pAOINQdqufn4udPtOPCtMjNiPGpkSM9ah/6X5+kvyWMNrvlf+Ld4OOoszP5sAkgQzIbrFQAm41XknBUha0zkewZwfrVhain4pnDjV7wCcChId/Q/Gbi4xMtXkisznWcAJcueBs3EEZDKhJ5q0VeWSJEhYJDLFN1sOxF0AIUnMrOhfKQ/LjgREXPB6uCl899INUTXRNNjRpeMXyJ2wMMmOAbua2qEd1r13Bu1n+6A823Hzb33fyMXuqWnJwBJ4DCvMlGuEsfuOK+xk7DaBfLHbcM6fsPk0/4psTE6YLgC41remr6+u5ZWsY/faMtSnNPie8Z8Ov0DIYGdhbJjUXk1HomxRV9+ZfZ2Ob8iCwlaAQAyEUM6fs3Kxt8pBD8dx1HOkhsfBWPvuDr5y+kqE7H8/MuPDTc0QgH2pjUMpmw/XBwNDHshVEjrZvtICOjOLUJxcowLO1ivNYwPwowQxfisMy56LfYdjsOslBiqsrkAqvNGm1zu8wKHeqVN9w5l3yUELpvubfm9NKIvYcl6yWF36T0c5vE+g0DU/Jy4XpTj0hZG9QV2mRQcLJnd2pxQtJT7cPFtrn/+tgRxzjEtbDXummDV4sE= ansible@example.com"
+vultr_ssh_key2: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCoQ9S7V+CufAgwoehnf2TqsJ9LTsu8pUA3FgpS2mdVwcMcTs++8P5sQcXHLtDmNLpWN4k7NQgxaY1oXy5e25x/4VhXaJXWEt3luSw+Phv/PB2+aGLvqCUirsLTAD2r7ieMhd/pcVf/HlhNUQgnO1mupdbDyqZoGD/uCcJiYav8i/V7nJWJouHA8yq31XS2yqXp9m3VC7UZZHzUsVJA9Us5YqF0hKYeaGruIHR2bwoDF9ZFMss5t6/pzxMljU/ccYwvvRDdI7WX4o4+zLuZ6RWvsU6LGbbb0pQdB72tlV41fSefwFsk4JRdKbyV3Xjf25pV4IXOTcqhy+4JTB/jXxrF torwalds@github.com"
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/ssh_key/meta/main.yml b/ansible_collections/vultr/cloud/tests/integration/targets/ssh_key/meta/main.yml
new file mode 100644
index 000000000..2083f0e12
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/ssh_key/meta/main.yml
@@ -0,0 +1,3 @@
+---
+dependencies:
+ - common
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/ssh_key/tasks/main.yml b/ansible_collections/vultr/cloud/tests/integration/targets/ssh_key/tasks/main.yml
new file mode 100644
index 000000000..44b1abf0b
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/ssh_key/tasks/main.yml
@@ -0,0 +1,7 @@
+---
+- block:
+ - ansible.builtin.import_tasks: tests.yml
+ always:
+ - ansible.builtin.import_role:
+ name: cleanup
+ tasks_from: cleanup_ssh_key
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/ssh_key/tasks/tests.yml b/ansible_collections/vultr/cloud/tests/integration/targets/ssh_key/tasks/tests.yml
new file mode 100644
index 000000000..4b9ba76bd
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/ssh_key/tasks/tests.yml
@@ -0,0 +1,140 @@
+# Copyright (c) 2021, René Moser <mail@renemoser.net>
+# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
+---
+- name: setup
+ vultr.cloud.ssh_key:
+ name: "{{ vultr_ssh_key_name }}"
+ state: absent
+ register: result
+- name: verify setup
+ ansible.builtin.assert:
+ that:
+ - result is success
+
+- name: test fail if missing name
+ vultr.cloud.ssh_key:
+ register: result
+ ignore_errors: true
+- name: verify test fail if missing name
+ ansible.builtin.assert:
+ that:
+ - result is failed
+ - 'result.msg == "missing required arguments: name"'
+
+- name: test fail if missing params for state=present
+ vultr.cloud.ssh_key:
+ name: "{{ vultr_ssh_key_name }}"
+ register: result
+ ignore_errors: true
+- name: verify fail if missing params for state=present
+ ansible.builtin.assert:
+ that:
+ - result is failed
+ - 'result.msg == "state is present but all of the following are missing: ssh_key"'
+
+- name: test create ssh key in check mode
+ vultr.cloud.ssh_key:
+ name: "{{ vultr_ssh_key_name }}"
+ ssh_key: "{{ vultr_ssh_key }}"
+ register: result
+ check_mode: true
+- name: verify test create ssh key in check mode
+ ansible.builtin.assert:
+ that:
+ - result is changed
+
+- name: test create ssh key
+ vultr.cloud.ssh_key:
+ name: "{{ vultr_ssh_key_name }}"
+ ssh_key: "{{ vultr_ssh_key }}"
+ register: result
+- name: verify test create ssh key
+ ansible.builtin.assert:
+ that:
+ - result is changed
+ - result.vultr_ssh_key.name == vultr_ssh_key_name
+ - result.vultr_ssh_key.ssh_key == vultr_ssh_key
+
+- name: test create ssh key idempotence
+ vultr.cloud.ssh_key:
+ name: "{{ vultr_ssh_key_name }}"
+ ssh_key: "{{ vultr_ssh_key }}"
+ register: result
+- name: verify test create ssh key idempotence
+ ansible.builtin.assert:
+ that:
+ - result is not changed
+ - result.vultr_ssh_key.name == vultr_ssh_key_name
+ - result.vultr_ssh_key.ssh_key == vultr_ssh_key
+
+- name: test update ssh key in check mode
+ vultr.cloud.ssh_key:
+ name: "{{ vultr_ssh_key_name }}"
+ ssh_key: "{{ vultr_ssh_key2 }}"
+ register: result
+ check_mode: true
+- name: verify test update ssh key in check mode
+ ansible.builtin.assert:
+ that:
+ - result is changed
+ - result.vultr_ssh_key.name == vultr_ssh_key_name
+ - result.vultr_ssh_key.ssh_key == vultr_ssh_key
+
+- name: test update ssh key
+ vultr.cloud.ssh_key:
+ name: "{{ vultr_ssh_key_name }}"
+ ssh_key: "{{ vultr_ssh_key2 }}"
+ register: result
+- name: verify test update ssh key
+ ansible.builtin.assert:
+ that:
+ - result is changed
+ - result.vultr_ssh_key.name == vultr_ssh_key_name
+ - result.vultr_ssh_key.ssh_key == vultr_ssh_key2
+
+- name: test update ssh key idempotence
+ vultr.cloud.ssh_key:
+ name: "{{ vultr_ssh_key_name }}"
+ ssh_key: "{{ vultr_ssh_key2 }}"
+ register: result
+- name: verify test update ssh key idempotence
+ ansible.builtin.assert:
+ that:
+ - result is not changed
+ - result.vultr_ssh_key.name == vultr_ssh_key_name
+ - result.vultr_ssh_key.ssh_key == vultr_ssh_key2
+
+- name: test absent ssh key in check mode
+ vultr.cloud.ssh_key:
+ name: "{{ vultr_ssh_key_name }}"
+ state: absent
+ register: result
+ check_mode: true
+- name: verify test absent ssh key in check mode
+ ansible.builtin.assert:
+ that:
+ - result is changed
+ - result.vultr_ssh_key.name == vultr_ssh_key_name
+ - result.vultr_ssh_key.ssh_key == vultr_ssh_key2
+
+- name: test absent ssh key
+ vultr.cloud.ssh_key:
+ name: "{{ vultr_ssh_key_name }}"
+ state: absent
+ register: result
+- name: verify test absent ssh key
+ ansible.builtin.assert:
+ that:
+ - result is changed
+ - result.vultr_ssh_key.name == vultr_ssh_key_name
+ - result.vultr_ssh_key.ssh_key == vultr_ssh_key2
+
+- name: test absent ssh key idempotence
+ vultr.cloud.ssh_key:
+ name: "{{ vultr_ssh_key_name }}"
+ state: absent
+ register: result
+- name: verify test absent ssh key idempotence
+ ansible.builtin.assert:
+ that:
+ - result is not changed
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/ssh_key_info/aliases b/ansible_collections/vultr/cloud/tests/integration/targets/ssh_key_info/aliases
new file mode 100644
index 000000000..c749ce7ca
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/ssh_key_info/aliases
@@ -0,0 +1,3 @@
+cloud/vultr
+needs/target/common
+needs/target/cleanup
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/ssh_key_info/defaults/main.yml b/ansible_collections/vultr/cloud/tests/integration/targets/ssh_key_info/defaults/main.yml
new file mode 100644
index 000000000..914be3a6e
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/ssh_key_info/defaults/main.yml
@@ -0,0 +1,3 @@
+---
+ssh_key_name: "{{ vultr_resource_prefix }}-sshkey"
+ssh_key_content: ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC+ZFQv3MyjtL1BMpSA0o0gIkzLVVC711rthT29hBNeORdNowQ7FSvVWUdAbTq00U7Xzak1ANIYLJyn+0r7olsdG4XEiUR0dqgC99kbT/QhY5mLe5lpl7JUjW9ctn00hNmt+TswpatCKWPNwdeAJT2ERynZaqPobENgvIq7jfOFWQIVew7qrewtqwerqwrewUr2Cdq7Nb7U0XFXh3x1p0v0+MbL4tiJwPlMAGvFTKIMt+EaA+AsRIxiOo9CMk5ZuOl9pT8h5vNuEOcvS0qx4v44EAD2VOsCVCcrPNMcpuSzZP8dRTGU9wRREAWXngD0Zq9YJMH38VTxHiskoBw1NnPz ansibletest-{{ vultr_resource_prefix }}@sshkey
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/ssh_key_info/meta/main.yml b/ansible_collections/vultr/cloud/tests/integration/targets/ssh_key_info/meta/main.yml
new file mode 100644
index 000000000..2083f0e12
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/ssh_key_info/meta/main.yml
@@ -0,0 +1,3 @@
+---
+dependencies:
+ - common
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/ssh_key_info/tasks/main.yml b/ansible_collections/vultr/cloud/tests/integration/targets/ssh_key_info/tasks/main.yml
new file mode 100644
index 000000000..44b1abf0b
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/ssh_key_info/tasks/main.yml
@@ -0,0 +1,7 @@
+---
+- block:
+ - ansible.builtin.import_tasks: tests.yml
+ always:
+ - ansible.builtin.import_role:
+ name: cleanup
+ tasks_from: cleanup_ssh_key
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/ssh_key_info/tasks/tests.yml b/ansible_collections/vultr/cloud/tests/integration/targets/ssh_key_info/tasks/tests.yml
new file mode 100644
index 000000000..63ce48ee0
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/ssh_key_info/tasks/tests.yml
@@ -0,0 +1,44 @@
+# Copyright (c) 2018, Yanis Guenane <yanis+ansible@guenane.org>
+# Copyright (c) 2021, René Moser <mail@renemoser.net>
+# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
+---
+- name: test get vultr ssh key info - empty resources
+ vultr.cloud.ssh_key_info:
+ register: result
+
+- name: verify test get vultr ssh key infos in check mode
+ ansible.builtin.assert:
+ that:
+ - result.vultr_ssh_key_info|selectattr('name','equalto','{{ ssh_key_name }}') | list | count == 0
+ - result.vultr_ssh_key_info|selectattr('ssh_key','equalto','{{ ssh_key_content }}') | list | count == 0
+
+- name: Upload an ssh key
+ vultr.cloud.ssh_key:
+ name: "{{ ssh_key_name }}"
+ ssh_key: "{{ ssh_key_content }}"
+
+- name: test get vultr ssh key infos in check mode
+ vultr.cloud.ssh_key_info:
+ check_mode: true
+ register: result
+
+- name: verify test get vultr ssh key infos in check mode
+ ansible.builtin.assert:
+ that:
+ - result.vultr_ssh_key_info|selectattr('name','equalto','{{ ssh_key_name }}') | list | count == 1
+ - result.vultr_ssh_key_info|selectattr('ssh_key','equalto','{{ ssh_key_content }}') | list | count == 1
+
+- name: test get vultr ssh key info
+ vultr.cloud.ssh_key_info:
+ register: result
+
+- name: verify test get vultr ssh key infos
+ ansible.builtin.assert:
+ that:
+ - result.vultr_ssh_key_info|selectattr('name','equalto','{{ ssh_key_name }}') | list | count == 1
+ - result.vultr_ssh_key_info|selectattr('ssh_key','equalto','{{ ssh_key_content }}') | list | count == 1
+
+- name: Destroy the ssh key
+ vultr.cloud.ssh_key:
+ name: "{{ ssh_key_name }}"
+ state: absent
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/startup_script/aliases b/ansible_collections/vultr/cloud/tests/integration/targets/startup_script/aliases
new file mode 100644
index 000000000..c749ce7ca
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/startup_script/aliases
@@ -0,0 +1,3 @@
+cloud/vultr
+needs/target/common
+needs/target/cleanup
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/startup_script/defaults/main.yml b/ansible_collections/vultr/cloud/tests/integration/targets/startup_script/defaults/main.yml
new file mode 100644
index 000000000..3093aa725
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/startup_script/defaults/main.yml
@@ -0,0 +1,6 @@
+# Copyright (c) 2018, René Moser <mail@renemoser.net>
+# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
+---
+vultr_startup_script_name: "{{ vultr_resource_prefix }}_script"
+vultr_startup_script: "#!/bin/bash\necho Hello World > /root/hello"
+vultr_startup_script2: "#!/bin/bash\necho Hello to my World > /root/hello"
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/startup_script/meta/main.yml b/ansible_collections/vultr/cloud/tests/integration/targets/startup_script/meta/main.yml
new file mode 100644
index 000000000..2083f0e12
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/startup_script/meta/main.yml
@@ -0,0 +1,3 @@
+---
+dependencies:
+ - common
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/startup_script/tasks/main.yml b/ansible_collections/vultr/cloud/tests/integration/targets/startup_script/tasks/main.yml
new file mode 100644
index 000000000..18bc711e7
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/startup_script/tasks/main.yml
@@ -0,0 +1,7 @@
+---
+- block:
+ - ansible.builtin.import_tasks: tests.yml
+ always:
+ - ansible.builtin.import_role:
+ name: cleanup
+ tasks_from: cleanup_startup_script
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/startup_script/tasks/tests.yml b/ansible_collections/vultr/cloud/tests/integration/targets/startup_script/tasks/tests.yml
new file mode 100644
index 000000000..cd8b067ee
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/startup_script/tasks/tests.yml
@@ -0,0 +1,140 @@
+# Copyright (c) 2021, René Moser <mail@renemoser.net>
+# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
+---
+- name: setup
+ vultr.cloud.startup_script:
+ name: "{{ vultr_startup_script_name }}"
+ state: absent
+ register: result
+- name: verify setup
+ ansible.builtin.assert:
+ that:
+ - result is success
+
+- name: test fail if missing name
+ vultr.cloud.startup_script:
+ register: result
+ ignore_errors: true
+- name: verify test fail if missing name
+ ansible.builtin.assert:
+ that:
+ - result is failed
+ - 'result.msg == "missing required arguments: name"'
+
+- name: test fail if missing params for state=present
+ vultr.cloud.startup_script:
+ name: "{{ vultr_startup_script_name }}"
+ register: result
+ ignore_errors: true
+- name: verify fail if missing params for state=present
+ ansible.builtin.assert:
+ that:
+ - result is failed
+ - 'result.msg == "state is present but all of the following are missing: script"'
+
+- name: test create startup script in check mode
+ vultr.cloud.startup_script:
+ name: "{{ vultr_startup_script_name }}"
+ script: "{{ vultr_startup_script }}"
+ register: result
+ check_mode: true
+- name: verify test create startup script in check mode
+ ansible.builtin.assert:
+ that:
+ - result is changed
+
+- name: test create startup script
+ vultr.cloud.startup_script:
+ name: "{{ vultr_startup_script_name }}"
+ script: "{{ vultr_startup_script }}"
+ register: result
+- name: verify test create startup script
+ ansible.builtin.assert:
+ that:
+ - result is changed
+ - result.vultr_startup_script.name == vultr_startup_script_name
+ - result.vultr_startup_script.script == vultr_startup_script
+
+- name: test create startup script idempotence
+ vultr.cloud.startup_script:
+ name: "{{ vultr_startup_script_name }}"
+ script: "{{ vultr_startup_script }}"
+ register: result
+- name: verify test create startup script idempotence
+ ansible.builtin.assert:
+ that:
+ - result is not changed
+ - result.vultr_startup_script.name == vultr_startup_script_name
+ - result.vultr_startup_script.script == vultr_startup_script
+
+- name: test update startup script in check mode
+ vultr.cloud.startup_script:
+ name: "{{ vultr_startup_script_name }}"
+ script: "{{ vultr_startup_script2 }}"
+ register: result
+ check_mode: true
+- name: verify test update startup script in check mode
+ ansible.builtin.assert:
+ that:
+ - result is changed
+ - result.vultr_startup_script.name == vultr_startup_script_name
+ - result.vultr_startup_script.script == vultr_startup_script
+
+- name: test update startup script
+ vultr.cloud.startup_script:
+ name: "{{ vultr_startup_script_name }}"
+ script: "{{ vultr_startup_script2 }}"
+ register: result
+- name: verify test update startup script
+ ansible.builtin.assert:
+ that:
+ - result is changed
+ - result.vultr_startup_script.name == vultr_startup_script_name
+ - result.vultr_startup_script.script == vultr_startup_script2
+
+- name: test update startup script idempotence
+ vultr.cloud.startup_script:
+ name: "{{ vultr_startup_script_name }}"
+ script: "{{ vultr_startup_script2 }}"
+ register: result
+- name: verify test update startup script idempotence
+ ansible.builtin.assert:
+ that:
+ - result is not changed
+ - result.vultr_startup_script.name == vultr_startup_script_name
+ - result.vultr_startup_script.script == vultr_startup_script2
+
+- name: test absent startup script in check mode
+ vultr.cloud.startup_script:
+ name: "{{ vultr_startup_script_name }}"
+ state: absent
+ register: result
+ check_mode: true
+- name: verify test absent startup script in check mode
+ ansible.builtin.assert:
+ that:
+ - result is changed
+ - result.vultr_startup_script.name == vultr_startup_script_name
+ - result.vultr_startup_script.script == vultr_startup_script2
+
+- name: test absent startup script
+ vultr.cloud.startup_script:
+ name: "{{ vultr_startup_script_name }}"
+ state: absent
+ register: result
+- name: verify test absent startup script
+ ansible.builtin.assert:
+ that:
+ - result is changed
+ - result.vultr_startup_script.name == vultr_startup_script_name
+ - result.vultr_startup_script.script == vultr_startup_script2
+
+- name: test absent startup script idempotence
+ vultr.cloud.startup_script:
+ name: "{{ vultr_startup_script_name }}"
+ state: absent
+ register: result
+- name: verify test absent startup script idempotence
+ ansible.builtin.assert:
+ that:
+ - result is not changed
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/startup_script_info/aliases b/ansible_collections/vultr/cloud/tests/integration/targets/startup_script_info/aliases
new file mode 100644
index 000000000..c749ce7ca
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/startup_script_info/aliases
@@ -0,0 +1,3 @@
+cloud/vultr
+needs/target/common
+needs/target/cleanup
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/startup_script_info/defaults/main.yml b/ansible_collections/vultr/cloud/tests/integration/targets/startup_script_info/defaults/main.yml
new file mode 100644
index 000000000..37632d6eb
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/startup_script_info/defaults/main.yml
@@ -0,0 +1,4 @@
+---
+startup_script_name: "{{ vultr_resource_prefix }}_script"
+startup_script_type: boot
+startup_script_content: "#!/bin/bash\necho Hello World > /root/hello"
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/startup_script_info/meta/main.yml b/ansible_collections/vultr/cloud/tests/integration/targets/startup_script_info/meta/main.yml
new file mode 100644
index 000000000..2083f0e12
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/startup_script_info/meta/main.yml
@@ -0,0 +1,3 @@
+---
+dependencies:
+ - common
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/startup_script_info/tasks/main.yml b/ansible_collections/vultr/cloud/tests/integration/targets/startup_script_info/tasks/main.yml
new file mode 100644
index 000000000..18bc711e7
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/startup_script_info/tasks/main.yml
@@ -0,0 +1,7 @@
+---
+- block:
+ - ansible.builtin.import_tasks: tests.yml
+ always:
+ - ansible.builtin.import_role:
+ name: cleanup
+ tasks_from: cleanup_startup_script
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/startup_script_info/tasks/tests.yml b/ansible_collections/vultr/cloud/tests/integration/targets/startup_script_info/tasks/tests.yml
new file mode 100644
index 000000000..730df6d71
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/startup_script_info/tasks/tests.yml
@@ -0,0 +1,35 @@
+# Copyright (c) 2018, Yanis Guenane <yanis+ansible@guenane.org>
+# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
+---
+- name: test gather vultr startup script info - empty resources
+ vultr.cloud.startup_script_info:
+
+- name: Create the script
+ vultr.cloud.startup_script:
+ name: "{{ startup_script_name }}"
+ script_type: "{{ startup_script_type }}"
+ script: "{{ startup_script_content }}"
+
+- name: test gather vultr startup script info in check mode
+ vultr.cloud.startup_script_info:
+ check_mode: true
+ register: result
+
+- name: verify test gather vultr startup script info in check mode
+ ansible.builtin.assert:
+ that:
+ - result.vultr_startup_script_info|selectattr('name','equalto','{{ startup_script_name }}') | list | count == 1
+
+- name: test gather vultr startup script info
+ vultr.cloud.startup_script_info:
+ register: result
+
+- name: verify test gather vultr startup script info
+ ansible.builtin.assert:
+ that:
+ - result.vultr_startup_script_info|selectattr('name','equalto','{{ startup_script_name }}') | list | count == 1
+
+- name: Delete the script
+ vultr.cloud.startup_script:
+ name: "{{ startup_script_name }}"
+ state: absent
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/user/aliases b/ansible_collections/vultr/cloud/tests/integration/targets/user/aliases
new file mode 100644
index 000000000..c749ce7ca
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/user/aliases
@@ -0,0 +1,3 @@
+cloud/vultr
+needs/target/common
+needs/target/cleanup
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/user/defaults/main.yml b/ansible_collections/vultr/cloud/tests/integration/targets/user/defaults/main.yml
new file mode 100644
index 000000000..a95c755d3
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/user/defaults/main.yml
@@ -0,0 +1,4 @@
+# Copyright (c) 2018, René Moser <mail@renemoser.net>
+# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
+---
+vultr_user_name: "{{ vultr_resource_prefix }}_user"
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/user/meta/main.yml b/ansible_collections/vultr/cloud/tests/integration/targets/user/meta/main.yml
new file mode 100644
index 000000000..2083f0e12
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/user/meta/main.yml
@@ -0,0 +1,3 @@
+---
+dependencies:
+ - common
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/user/tasks/main.yml b/ansible_collections/vultr/cloud/tests/integration/targets/user/tasks/main.yml
new file mode 100644
index 000000000..bd6ae3f26
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/user/tasks/main.yml
@@ -0,0 +1,7 @@
+---
+- block:
+ - ansible.builtin.import_tasks: tests.yml
+ always:
+ - ansible.builtin.import_role:
+ name: cleanup
+ tasks_from: cleanup_user
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/user/tasks/tests.yml b/ansible_collections/vultr/cloud/tests/integration/targets/user/tasks/tests.yml
new file mode 100644
index 000000000..06bb2b843
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/user/tasks/tests.yml
@@ -0,0 +1,218 @@
+---
+# Copyright (c) 2018, René Moser <mail@renemoser.net>
+# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
+- name: setup
+ vultr.cloud.user:
+ name: "{{ vultr_user_name }}"
+ state: absent
+ register: result
+- name: verify setup
+ ansible.builtin.assert:
+ that:
+ - result is success
+
+- name: test fail if missing name
+ vultr.cloud.user:
+ register: result
+ ignore_errors: true
+- name: verify test fail if missing name
+ ansible.builtin.assert:
+ that:
+ - result is failed
+ - 'result.msg == "missing required arguments: name"'
+
+- name: test fail if missing params for state=present
+ vultr.cloud.user:
+ name: "{{ vultr_user_name }}"
+ register: result
+ ignore_errors: true
+- name: verify fail if missing params for state=present
+ ansible.builtin.assert:
+ that:
+ - result is failed
+ - 'result.msg.startswith("state is present but all of the following are missing")'
+
+- name: test fail param not in choices
+ vultr.cloud.user:
+ name: "{{ vultr_user_name }}"
+ email: john.doe{{ vultr_resource_prefix }}@example.com
+ password: s3cr3t
+ acls:
+ - bad
+ - dns
+ - manage_users
+ register: result
+ ignore_errors: true
+- name: verify test fail if missing name
+ ansible.builtin.assert:
+ that:
+ - result is failed
+ - 'result.msg.startswith("value of acls must be one or more of")'
+
+- name: test create user in check mode
+ vultr.cloud.user:
+ name: "{{ vultr_user_name }}"
+ email: john.doe{{ vultr_resource_prefix }}@example.com
+ password: s3cr3t
+ acls:
+ - upgrade
+ - dns
+ - manage_users
+ register: result
+ check_mode: true
+- name: verify test create user in check mode
+ ansible.builtin.assert:
+ that:
+ - result is changed
+
+- name: test create user
+ vultr.cloud.user:
+ name: "{{ vultr_user_name }}"
+ email: john.doe{{ vultr_resource_prefix }}@example.com
+ password: s3cr3t
+ acls:
+ - upgrade
+ - dns
+ - manage_users
+ register: result
+- name: verify test create user
+ ansible.builtin.assert:
+ that:
+ - result is changed
+ - result.vultr_user.name == vultr_user_name
+ - result.vultr_user.email == 'john.doe{{ vultr_resource_prefix }}@example.com'
+ - result.vultr_user.api_enabled == true
+ - "'upgrade' in result.vultr_user.acls"
+ - "'manage_users' in result.vultr_user.acls"
+ - "'dns' in result.vultr_user.acls"
+
+- name: test create user idempotence
+ vultr.cloud.user:
+ name: "{{ vultr_user_name }}"
+ email: john.doe{{ vultr_resource_prefix }}@example.com
+ password: s3cr3t
+ acls:
+ - upgrade
+ - dns
+ - manage_users
+ register: result
+- name: verify test create user idempotence
+ ansible.builtin.assert:
+ that:
+ - result is not changed
+ - result.vultr_user.name == vultr_user_name
+ - result.vultr_user.email == 'john.doe{{ vultr_resource_prefix }}@example.com'
+ - result.vultr_user.api_enabled == true
+ - "'upgrade' in result.vultr_user.acls"
+ - "'manage_users' in result.vultr_user.acls"
+ - "'dns' in result.vultr_user.acls"
+
+- name: test update user in check mode
+ vultr.cloud.user:
+ name: "{{ vultr_user_name }}"
+ email: jimmy{{ vultr_resource_prefix }}@example.com
+ password: s3cr3t
+ api_enabled: false
+ acls:
+ - manage_users
+ - upgrade
+ - support
+ register: result
+ check_mode: true
+- name: verify test update user in check mode
+ ansible.builtin.assert:
+ that:
+ - result is changed
+ - result.vultr_user.name == vultr_user_name
+ - result.vultr_user.email == 'john.doe{{ vultr_resource_prefix }}@example.com'
+ - "'upgrade' in result.vultr_user.acls"
+ - "'manage_users' in result.vultr_user.acls"
+ - "'dns' in result.vultr_user.acls"
+ - result.vultr_user.api_enabled == true
+
+- name: test update user
+ vultr.cloud.user:
+ name: "{{ vultr_user_name }}"
+ email: jimmy{{ vultr_resource_prefix }}@example.com
+ password: s3cr3t
+ api_enabled: false
+ acls:
+ - manage_users
+ - upgrade
+ - support
+ register: result
+- name: verify test update user
+ ansible.builtin.assert:
+ that:
+ - result is changed
+ - result.vultr_user.name == vultr_user_name
+ - result.vultr_user.email == 'jimmy{{ vultr_resource_prefix }}@example.com'
+ - "'upgrade' in result.vultr_user.acls"
+ - "'manage_users' in result.vultr_user.acls"
+ - "'support' in result.vultr_user.acls"
+ - result.vultr_user.api_enabled == false
+
+- name: test update user idempotence
+ vultr.cloud.user:
+ name: "{{ vultr_user_name }}"
+ email: jimmy{{ vultr_resource_prefix }}@example.com
+ password: s3cr3t
+ api_enabled: false
+ acls:
+ - manage_users
+ - upgrade
+ - support
+ register: result
+- name: verify test update user idempotence
+ ansible.builtin.assert:
+ that:
+ - result is not changed
+ - result.vultr_user.name == vultr_user_name
+ - result.vultr_user.email == 'jimmy{{ vultr_resource_prefix }}@example.com'
+ - "'upgrade' in result.vultr_user.acls"
+ - "'manage_users' in result.vultr_user.acls"
+ - "'support' in result.vultr_user.acls"
+ - result.vultr_user.api_enabled == false
+
+- name: test absent user in check mode
+ vultr.cloud.user:
+ name: "{{ vultr_user_name }}"
+ state: absent
+ register: result
+ check_mode: true
+- name: verify test absent user in check mode
+ ansible.builtin.assert:
+ that:
+ - result is changed
+ - result.vultr_user.name == vultr_user_name
+ - result.vultr_user.email == 'jimmy{{ vultr_resource_prefix }}@example.com'
+ - "'upgrade' in result.vultr_user.acls"
+ - "'manage_users' in result.vultr_user.acls"
+ - "'support' in result.vultr_user.acls"
+ - result.vultr_user.api_enabled == false
+
+- name: test absent user
+ vultr.cloud.user:
+ name: "{{ vultr_user_name }}"
+ state: absent
+ register: result
+- name: verify test absent user
+ ansible.builtin.assert:
+ that:
+ - result is changed
+ - result.vultr_user.name == vultr_user_name
+ - result.vultr_user.email == 'jimmy{{ vultr_resource_prefix }}@example.com'
+ - "'upgrade' in result.vultr_user.acls"
+ - "'manage_users' in result.vultr_user.acls"
+ - "'support' in result.vultr_user.acls"
+ - result.vultr_user.api_enabled == false
+
+- name: test absent user idempotence
+ vultr.cloud.user:
+ name: "{{ vultr_user_name }}"
+ state: absent
+ register: result
+- name: verify test absent user idempotence
+ ansible.builtin.assert:
+ that:
+ - result is not changed
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/user_info/aliases b/ansible_collections/vultr/cloud/tests/integration/targets/user_info/aliases
new file mode 100644
index 000000000..c749ce7ca
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/user_info/aliases
@@ -0,0 +1,3 @@
+cloud/vultr
+needs/target/common
+needs/target/cleanup
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/user_info/defaults/main.yml b/ansible_collections/vultr/cloud/tests/integration/targets/user_info/defaults/main.yml
new file mode 100644
index 000000000..5922f6fe2
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/user_info/defaults/main.yml
@@ -0,0 +1,10 @@
+---
+vultr_resource_prefix: "vultr-test-prefix"
+user_name: "{{ vultr_resource_prefix }}_user"
+user_email: mytestuser-{{ vultr_resource_prefix }}@example.com
+user_password: "{{ vultr_resource_prefix }}aP4ssw0rd!"
+user_acls:
+ - upgrade
+ - dns
+ - manage_users
+ - subscriptions
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/user_info/meta/main.yml b/ansible_collections/vultr/cloud/tests/integration/targets/user_info/meta/main.yml
new file mode 100644
index 000000000..2083f0e12
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/user_info/meta/main.yml
@@ -0,0 +1,3 @@
+---
+dependencies:
+ - common
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/user_info/tasks/main.yml b/ansible_collections/vultr/cloud/tests/integration/targets/user_info/tasks/main.yml
new file mode 100644
index 000000000..bd6ae3f26
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/user_info/tasks/main.yml
@@ -0,0 +1,7 @@
+---
+- block:
+ - ansible.builtin.import_tasks: tests.yml
+ always:
+ - ansible.builtin.import_role:
+ name: cleanup
+ tasks_from: cleanup_user
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/user_info/tasks/tests.yml b/ansible_collections/vultr/cloud/tests/integration/targets/user_info/tasks/tests.yml
new file mode 100644
index 000000000..023cd3b82
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/user_info/tasks/tests.yml
@@ -0,0 +1,34 @@
+# Copyright (c) 2018, Yanis Guenane <yanis+ansible@guenane.org>
+# Copyright (c) 2021, René Moser <mail@renemoser.net>
+# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
+---
+- name: Create the user
+ vultr.cloud.user:
+ name: "{{ user_name }}"
+ email: "{{ user_email }}"
+ password: "{{ user_password }}"
+ acls: "{{ user_acls }}"
+
+- name: test get vultr user info in check mode
+ vultr.cloud.user_info:
+ register: result
+ check_mode: true
+
+- name: verify test get vultr user info in check mode
+ ansible.builtin.assert:
+ that:
+ - result.vultr_user_info|selectattr('name','equalto','{{ user_name }}') | list | count == 1
+
+- name: test get vultr user info
+ vultr.cloud.user_info:
+ register: result
+
+- name: verify test get vultr user info
+ ansible.builtin.assert:
+ that:
+ - result.vultr_user_info|selectattr('name','equalto','{{ user_name }}') | list | count == 1
+
+- name: Delete the user
+ vultr.cloud.user:
+ name: "{{ user_name }}"
+ state: absent
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/vpc/aliases b/ansible_collections/vultr/cloud/tests/integration/targets/vpc/aliases
new file mode 100644
index 000000000..c749ce7ca
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/vpc/aliases
@@ -0,0 +1,3 @@
+cloud/vultr
+needs/target/common
+needs/target/cleanup
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/vpc/defaults/main.yml b/ansible_collections/vultr/cloud/tests/integration/targets/vpc/defaults/main.yml
new file mode 100644
index 000000000..83923ffe8
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/vpc/defaults/main.yml
@@ -0,0 +1,5 @@
+---
+vultr_vpc_description: "{{ vultr_resource_prefix }}_vpc"
+vultr_vpc_v4_subnet: 192.168.42.0
+vultr_vpc_v4_subnet_mask: 24
+vultr_vpc_region: ewr
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/vpc/meta/main.yml b/ansible_collections/vultr/cloud/tests/integration/targets/vpc/meta/main.yml
new file mode 100644
index 000000000..2083f0e12
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/vpc/meta/main.yml
@@ -0,0 +1,3 @@
+---
+dependencies:
+ - common
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/vpc/tasks/main.yml b/ansible_collections/vultr/cloud/tests/integration/targets/vpc/tasks/main.yml
new file mode 100644
index 000000000..4a0ba389c
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/vpc/tasks/main.yml
@@ -0,0 +1,7 @@
+---
+- block:
+ - ansible.builtin.import_tasks: tests.yml
+ always:
+ - ansible.builtin.import_role:
+ name: cleanup
+ tasks_from: cleanup_vpc
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/vpc/tasks/tests.yml b/ansible_collections/vultr/cloud/tests/integration/targets/vpc/tasks/tests.yml
new file mode 100644
index 000000000..8ed2dfdc7
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/vpc/tasks/tests.yml
@@ -0,0 +1,112 @@
+# Copyright (c) 2022, René Moser <mail@renemoser.net>
+# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
+---
+- name: setup
+ vultr.cloud.vpc:
+ description: "{{ vultr_vpc_description }}"
+ state: absent
+
+- name: test fail if missing description
+ vultr.cloud.vpc:
+ register: result
+ ignore_errors: true
+- name: verify test fail if missing description
+ ansible.builtin.assert:
+ that:
+ - result is failed
+ - 'result.msg == "missing required arguments: description"'
+
+- name: test fail if missing params for state=present
+ vultr.cloud.vpc:
+ description: "{{ vultr_vpc_description }}"
+ register: result
+ ignore_errors: true
+- name: verify fail if missing params for state=present
+ ansible.builtin.assert:
+ that:
+ - result is failed
+ - 'result.msg == "state is present but all of the following are missing: v4_subnet, v4_subnet_mask, region"'
+
+- name: test create vpc in check mode
+ vultr.cloud.vpc:
+ description: "{{ vultr_vpc_description }}"
+ v4_subnet: "{{ vultr_vpc_v4_subnet }}"
+ v4_subnet_mask: "{{ vultr_vpc_v4_subnet_mask }}"
+ region: "{{ vultr_vpc_region }}"
+ register: result
+ check_mode: true
+- name: verify test create server in check mode
+ ansible.builtin.assert:
+ that:
+ - result is changed
+
+- name: test create vpc
+ vultr.cloud.vpc:
+ description: "{{ vultr_vpc_description }}"
+ v4_subnet: "{{ vultr_vpc_v4_subnet }}"
+ v4_subnet_mask: "{{ vultr_vpc_v4_subnet_mask }}"
+ region: "{{ vultr_vpc_region }}"
+ register: result
+- name: verify test create vpc
+ ansible.builtin.assert:
+ that:
+ - result is changed
+ - result.vultr_vpc.description == vultr_vpc_description
+ - result.vultr_vpc.region == vultr_vpc_region
+ - result.vultr_vpc.v4_subnet == vultr_vpc_v4_subnet
+ - result.vultr_vpc.v4_subnet_mask == vultr_vpc_v4_subnet_mask
+
+- name: test create vpc idempotence
+ vultr.cloud.vpc:
+ description: "{{ vultr_vpc_description }}"
+ v4_subnet: "{{ vultr_vpc_v4_subnet }}"
+ v4_subnet_mask: "{{ vultr_vpc_v4_subnet_mask }}"
+ region: "{{ vultr_vpc_region }}"
+ register: result
+- name: verify test vpc idempotence
+ ansible.builtin.assert:
+ that:
+ - result is not changed
+ - result.vultr_vpc.description == vultr_vpc_description
+ - result.vultr_vpc.region == vultr_vpc_region
+ - result.vultr_vpc.v4_subnet == vultr_vpc_v4_subnet
+ - result.vultr_vpc.v4_subnet_mask == vultr_vpc_v4_subnet_mask
+
+- name: test destroy vpc in check mode
+ vultr.cloud.vpc:
+ description: "{{ vultr_vpc_description }}"
+ state: absent
+ register: result
+ check_mode: true
+- name: verify test destroy vpc in check mode
+ ansible.builtin.assert:
+ that:
+ - result is changed
+ - result.vultr_vpc.description == vultr_vpc_description
+ - result.vultr_vpc.region == vultr_vpc_region
+ - result.vultr_vpc.v4_subnet == vultr_vpc_v4_subnet
+ - result.vultr_vpc.v4_subnet_mask == vultr_vpc_v4_subnet_mask
+
+- name: test destroy vpc
+ vultr.cloud.vpc:
+ description: "{{ vultr_vpc_description }}"
+ state: absent
+ register: result
+- name: verify test destroy vpc
+ ansible.builtin.assert:
+ that:
+ - result is changed
+ - result.vultr_vpc.description == vultr_vpc_description
+ - result.vultr_vpc.region == vultr_vpc_region
+ - result.vultr_vpc.v4_subnet == vultr_vpc_v4_subnet
+ - result.vultr_vpc.v4_subnet_mask == vultr_vpc_v4_subnet_mask
+
+- name: test destroy an existing vpc idempotence
+ vultr.cloud.vpc:
+ description: "{{ vultr_vpc_description }}"
+ state: absent
+ register: result
+- name: verify test destroy an existing vpc idempotence
+ ansible.builtin.assert:
+ that:
+ - result is not changed
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/vpc_info/aliases b/ansible_collections/vultr/cloud/tests/integration/targets/vpc_info/aliases
new file mode 100644
index 000000000..c749ce7ca
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/vpc_info/aliases
@@ -0,0 +1,3 @@
+cloud/vultr
+needs/target/common
+needs/target/cleanup
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/vpc_info/defaults/main.yml b/ansible_collections/vultr/cloud/tests/integration/targets/vpc_info/defaults/main.yml
new file mode 100644
index 000000000..83923ffe8
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/vpc_info/defaults/main.yml
@@ -0,0 +1,5 @@
+---
+vultr_vpc_description: "{{ vultr_resource_prefix }}_vpc"
+vultr_vpc_v4_subnet: 192.168.42.0
+vultr_vpc_v4_subnet_mask: 24
+vultr_vpc_region: ewr
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/vpc_info/meta/main.yml b/ansible_collections/vultr/cloud/tests/integration/targets/vpc_info/meta/main.yml
new file mode 100644
index 000000000..2083f0e12
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/vpc_info/meta/main.yml
@@ -0,0 +1,3 @@
+---
+dependencies:
+ - common
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/vpc_info/tasks/main.yml b/ansible_collections/vultr/cloud/tests/integration/targets/vpc_info/tasks/main.yml
new file mode 100644
index 000000000..4a0ba389c
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/vpc_info/tasks/main.yml
@@ -0,0 +1,7 @@
+---
+- block:
+ - ansible.builtin.import_tasks: tests.yml
+ always:
+ - ansible.builtin.import_role:
+ name: cleanup
+ tasks_from: cleanup_vpc
diff --git a/ansible_collections/vultr/cloud/tests/integration/targets/vpc_info/tasks/tests.yml b/ansible_collections/vultr/cloud/tests/integration/targets/vpc_info/tasks/tests.yml
new file mode 100644
index 000000000..a8ab3d857
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/integration/targets/vpc_info/tasks/tests.yml
@@ -0,0 +1,36 @@
+# Copyright (c) 2022, René Moser <mail@renemoser.net>
+# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
+---
+- name: test gather VPC info - empty resources
+ vultr.cloud.vpc_info:
+
+- name: Create the vpc
+ vultr.cloud.vpc:
+ description: "{{ vultr_vpc_description }}"
+ v4_subnet: "{{ vultr_vpc_v4_subnet }}"
+ v4_subnet_mask: "{{ vultr_vpc_v4_subnet_mask }}"
+ region: "{{ vultr_vpc_region }}"
+
+- name: test gather VPC info in check mode
+ vultr.cloud.vpc_info:
+ check_mode: true
+ register: result
+
+- name: verify test gather vultr vpc info in check mode
+ ansible.builtin.assert:
+ that:
+ - result.vultr_vpc_info|selectattr('description','equalto','{{ vultr_vpc_description }}') | list | count == 1
+
+- name: test gather VPC info
+ vultr.cloud.vpc_info:
+ register: result
+
+- name: verify test gather vultr vpc info
+ ansible.builtin.assert:
+ that:
+ - result.vultr_vpc_info|selectattr('description','equalto','{{ vultr_vpc_description }}') | list | count == 1
+
+- name: Delete the VPC
+ vultr.cloud.vpc:
+ name: "{{ vultr_vpc_description }}"
+ state: absent
diff --git a/ansible_collections/vultr/cloud/tests/unit/plugins/inventory/fixtures/empty_vultr_inventory.json b/ansible_collections/vultr/cloud/tests/unit/plugins/inventory/fixtures/empty_vultr_inventory.json
new file mode 100644
index 000000000..4ae585950
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/unit/plugins/inventory/fixtures/empty_vultr_inventory.json
@@ -0,0 +1,10 @@
+{
+ "instances": [],
+ "meta": {
+ "total": 0,
+ "links": {
+ "next": "",
+ "prev": ""
+ }
+ }
+}
diff --git a/ansible_collections/vultr/cloud/tests/unit/plugins/inventory/fixtures/unauthorized_vultr_inventory.json b/ansible_collections/vultr/cloud/tests/unit/plugins/inventory/fixtures/unauthorized_vultr_inventory.json
new file mode 100644
index 000000000..8da6d1321
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/unit/plugins/inventory/fixtures/unauthorized_vultr_inventory.json
@@ -0,0 +1,4 @@
+{
+ "error": "Invalid API token.",
+ "status": 401
+}
diff --git a/ansible_collections/vultr/cloud/tests/unit/plugins/inventory/fixtures/vultr_inventory.json b/ansible_collections/vultr/cloud/tests/unit/plugins/inventory/fixtures/vultr_inventory.json
new file mode 100644
index 000000000..11ae1c749
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/unit/plugins/inventory/fixtures/vultr_inventory.json
@@ -0,0 +1,275 @@
+[
+ {
+ "id": "f1c4ae0c-ea06-4449-a028-ffe6b05f9f80",
+ "os": "Custom Installed",
+ "ram": 512,
+ "disk": 10,
+ "main_ip": "100.68.102.38",
+ "vcpu_count": 1,
+ "region": "ewr",
+ "plan": "vc2-1c-0.5gb-v6",
+ "date_created": "2022-12-05T13:15:58+00:00",
+ "status": "active",
+ "allowed_bandwidth": 500,
+ "netmask_v4": "255.255.192.0",
+ "gateway_v4": "100.68.64.1",
+ "power_status": "running",
+ "server_status": "locked",
+ "v6_network": "2001:19f0:face:395c::",
+ "v6_main_ip": "2001:19f0:face:395c:5400:04ff:beef:cafe",
+ "v6_network_size": 64,
+ "label": "",
+ "internal_ip": "10.1.96.3",
+ "kvm": "https:\/\/my.vultr.com\/subs\/vps\/novnc\/api.php?data=random-data",
+ "hostname": "",
+ "tag": "",
+ "tags": [],
+ "os_id": 159,
+ "app_id": 0,
+ "image_id": "",
+ "firewall_group_id": "",
+ "features": [
+ "auto_backups",
+ "ipv6",
+ "ddos_protection"
+ ]
+ },
+ {
+ "id": "4adbf858-8426-40c4-8f48-91d83024bb5e",
+ "os": "Custom Installed",
+ "ram": 1024,
+ "disk": 25,
+ "main_ip": "100.68.102.39",
+ "vcpu_count": 1,
+ "region": "sea",
+ "plan": "vc2-1c-1gb",
+ "date_created": "2022-12-05T13:21:57+00:00",
+ "status": "active",
+ "allowed_bandwidth": 1000,
+ "netmask_v4": "255.255.254.0",
+ "gateway_v4": "104.207.156.1",
+ "power_status": "stopped",
+ "server_status": "locked",
+ "v6_network": "2001:19f0:face:f17::",
+ "v6_main_ip": "2001:19f0:face:0f17:5400:04ff:beef:cafe",
+ "v6_network_size": 64,
+ "label": "restore-guest",
+ "internal_ip": "",
+ "kvm": "https:\/\/my.vultr.com\/subs\/vps\/novnc\/api.php?data=random-data",
+ "hostname": "restore-guest",
+ "tag": "",
+ "tags": [],
+ "os_id": 159,
+ "app_id": 0,
+ "image_id": "",
+ "firewall_group_id": "",
+ "features": [
+ "ipv6"
+ ]
+ },
+ {
+ "id": "5d8813ec-df65-4a69-8bfc-864aabe2a7d2",
+ "os": "Custom Installed",
+ "ram": 1024,
+ "disk": 25,
+ "main_ip": "100.68.102.40",
+ "vcpu_count": 1,
+ "region": "ord",
+ "plan": "vhp-1c-1gb-intel",
+ "date_created": "2022-12-05T13:29:19+00:00",
+ "status": "pending",
+ "allowed_bandwidth": 2000,
+ "netmask_v4": "255.255.254.0",
+ "gateway_v4": "45.76.228.1",
+ "power_status": "running",
+ "server_status": "none",
+ "v6_network": "",
+ "v6_main_ip": "",
+ "v6_network_size": 0,
+ "label": "snapshot-guest",
+ "internal_ip": "",
+ "kvm": "",
+ "hostname": "snapshot-guest",
+ "tag": "",
+ "tags": [],
+ "os_id": 159,
+ "app_id": 0,
+ "image_id": "",
+ "firewall_group_id": "",
+ "features": []
+ },
+ {
+ "id": "30c17c34-223f-436e-acbe-393af5293adb",
+ "os": "Debian 11 x64 (bullseye)",
+ "ram": 512,
+ "disk": 10,
+ "main_ip": "100.68.102.41",
+ "vcpu_count": 1,
+ "region": "ewr",
+ "plan": "vc2-1c-0.5gb-v6",
+ "date_created": "2022-12-05T12:43:00+00:00",
+ "status": "active",
+ "allowed_bandwidth": 500,
+ "netmask_v4": "255.255.192.0",
+ "gateway_v4": "100.68.64.1",
+ "power_status": "running",
+ "server_status": "ok",
+ "v6_network": "2001:19f0:face:8fd::",
+ "v6_main_ip": "2001:19f0:face:08fd:5400:04ff:beef:cafe",
+ "v6_network_size": 64,
+ "label": "debian-guest",
+ "internal_ip": "10.1.96.3",
+ "kvm": "https:\/\/my.vultr.com\/subs\/vps\/novnc\/api.php?data=random-data",
+ "hostname": "debian-guest",
+ "tag": "",
+ "tags": [
+ "vpc",
+ "vpc:d0db548b-5d50-4c94-9cdb-b083d46925f8",
+ "os:debian"
+ ],
+ "os_id": 477,
+ "app_id": 0,
+ "image_id": "",
+ "firewall_group_id": "",
+ "features": [
+ "auto_backups",
+ "ipv6"
+ ]
+ },
+ {
+ "id": "37d67f9f-17f0-4c56-879b-507355dc5174",
+ "os": "OpenBSD 7.2 x64",
+ "ram": 4096,
+ "disk": 30,
+ "main_ip": "100.68.102.42",
+ "vcpu_count": 1,
+ "region": "ewr",
+ "plan": "voc-g-1c-4gb-30s-amd",
+ "date_created": "2022-12-05T12:44:17+00:00",
+ "status": "active",
+ "allowed_bandwidth": 4000,
+ "netmask_v4": "255.255.254.0",
+ "gateway_v4": "45.63.22.1",
+ "power_status": "running",
+ "server_status": "ok",
+ "v6_network": "",
+ "v6_main_ip": "",
+ "v6_network_size": 0,
+ "label": "openbsd-guest",
+ "internal_ip": "",
+ "kvm": "https:\/\/my.vultr.com\/subs\/vps\/novnc\/api.php?data=random-data",
+ "hostname": "openbsd-guest",
+ "tag": "",
+ "tags": [],
+ "os_id": 1968,
+ "app_id": 0,
+ "image_id": "",
+ "firewall_group_id": "",
+ "features": []
+ },
+ {
+ "id": "2db0bb8c-9d83-4e62-86ef-b3d999960d72",
+ "os": "Windows 2016 Standard",
+ "ram": 2048,
+ "disk": 50,
+ "main_ip": "100.68.102.43",
+ "vcpu_count": 1,
+ "region": "fra",
+ "plan": "vhp-1c-2gb-amd",
+ "date_created": "2022-12-05T12:50:30+00:00",
+ "status": "active",
+ "allowed_bandwidth": 3000,
+ "netmask_v4": "255.255.254.0",
+ "gateway_v4": "45.77.142.1",
+ "power_status": "running",
+ "server_status": "installingbooting",
+ "v6_network": "",
+ "v6_main_ip": "",
+ "v6_network_size": 0,
+ "label": "windows-guest",
+ "internal_ip": "",
+ "kvm": "https:\/\/my.vultr.com\/subs\/vps\/novnc\/api.php?data=random-data",
+ "hostname": "windows-guest",
+ "tag": "",
+ "tags": [
+ "os:windows2016"
+ ],
+ "os_id": 240,
+ "app_id": 0,
+ "image_id": "",
+ "firewall_group_id": "",
+ "features": []
+ },
+ {
+ "id": "e0aabdd7-7d68-448a-a0ce-a7712b09fcc1",
+ "os": "Arch Linux x64",
+ "ram": 6144,
+ "disk": 70,
+ "main_ip": "100.68.102.44",
+ "vcpu_count": 1,
+ "region": "sjc",
+ "plan": "vcg-a100-1c-6g-4vram",
+ "date_created": "2022-12-05T12:52:06+00:00",
+ "status": "active",
+ "allowed_bandwidth": 1000,
+ "netmask_v4": "255.255.254.0",
+ "gateway_v4": "140.82.50.1",
+ "power_status": "running",
+ "server_status": "installingbooting",
+ "v6_network": "2001:19f0:face:1df3::",
+ "v6_main_ip": "2001:19f0:face:1df3:5400:04ff:beef:cafe",
+ "v6_network_size": 64,
+ "label": "mldev-guest",
+ "internal_ip": "",
+ "kvm": "https:\/\/my.vultr.com\/subs\/vps\/novnc\/api.php?data=random-data",
+ "hostname": "mldev-guest",
+ "tag": "",
+ "tags": [],
+ "os_id": 535,
+ "app_id": 0,
+ "image_id": "mldev",
+ "firewall_group_id": "",
+ "features": [
+ "auto_backups",
+ "ipv6"
+ ]
+ },
+ {
+ "id": "90676f7b-5a34-49a8-b770-b0abed017577",
+ "os": "Application",
+ "ram": 2048,
+ "disk": 64,
+ "main_ip": "100.68.102.45",
+ "vcpu_count": 1,
+ "region": "ord",
+ "plan": "vhf-1c-2gb",
+ "date_created": "2022-12-05T12:54:37+00:00",
+ "status": "active",
+ "allowed_bandwidth": 2000,
+ "netmask_v4": "255.255.254.0",
+ "gateway_v4": "149.28.114.1",
+ "power_status": "running",
+ "server_status": "installingbooting",
+ "v6_network": "2001:19f0:face:16ec::",
+ "v6_main_ip": "2001:19f0:face:16ec:5400:04ff:beef:cafe",
+ "v6_network_size": 64,
+ "label": "wordpress-guest",
+ "internal_ip": "10.2.96.3",
+ "kvm": "https:\/\/my.vultr.com\/subs\/vps\/novnc\/api.php?data=random-data",
+ "hostname": "wordpress-guest",
+ "tag": "",
+ "tags": [
+ "vpc",
+ "vpc:d0db548b-5d50-4c94-9cdb-b083d46925f8",
+ "application"
+ ],
+ "os_id": 186,
+ "app_id": 2,
+ "image_id": "",
+ "firewall_group_id": "",
+ "features": [
+ "auto_backups",
+ "ipv6"
+ ]
+ }
+]
diff --git a/ansible_collections/vultr/cloud/tests/unit/plugins/inventory/fixtures/vultr_inventory_page1.json b/ansible_collections/vultr/cloud/tests/unit/plugins/inventory/fixtures/vultr_inventory_page1.json
new file mode 100644
index 000000000..a4862285d
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/unit/plugins/inventory/fixtures/vultr_inventory_page1.json
@@ -0,0 +1,179 @@
+{
+ "instances": [
+ {
+ "id": "f1c4ae0c-ea06-4449-a028-ffe6b05f9f80",
+ "os": "Custom Installed",
+ "ram": 512,
+ "disk": 10,
+ "main_ip": "100.68.102.38",
+ "vcpu_count": 1,
+ "region": "ewr",
+ "plan": "vc2-1c-0.5gb-v6",
+ "date_created": "2022-12-05T13:15:58+00:00",
+ "status": "active",
+ "allowed_bandwidth": 500,
+ "netmask_v4": "255.255.192.0",
+ "gateway_v4": "100.68.64.1",
+ "power_status": "running",
+ "server_status": "locked",
+ "v6_network": "2001:19f0:face:395c::",
+ "v6_main_ip": "2001:19f0:face:395c:5400:04ff:beef:cafe",
+ "v6_network_size": 64,
+ "label": "",
+ "internal_ip": "10.1.96.3",
+ "kvm": "https:\/\/my.vultr.com\/subs\/vps\/novnc\/api.php?data=random-data",
+ "hostname": "",
+ "tag": "",
+ "tags": [],
+ "os_id": 159,
+ "app_id": 0,
+ "image_id": "",
+ "firewall_group_id": "",
+ "features": [
+ "auto_backups",
+ "ipv6",
+ "ddos_protection"
+ ]
+ },
+ {
+ "id": "4adbf858-8426-40c4-8f48-91d83024bb5e",
+ "os": "Custom Installed",
+ "ram": 1024,
+ "disk": 25,
+ "main_ip": "100.68.102.39",
+ "vcpu_count": 1,
+ "region": "sea",
+ "plan": "vc2-1c-1gb",
+ "date_created": "2022-12-05T13:21:57+00:00",
+ "status": "active",
+ "allowed_bandwidth": 1000,
+ "netmask_v4": "255.255.254.0",
+ "gateway_v4": "104.207.156.1",
+ "power_status": "stopped",
+ "server_status": "locked",
+ "v6_network": "2001:19f0:face:f17::",
+ "v6_main_ip": "2001:19f0:face:0f17:5400:04ff:beef:cafe",
+ "v6_network_size": 64,
+ "label": "restore-guest",
+ "internal_ip": "",
+ "kvm": "https:\/\/my.vultr.com\/subs\/vps\/novnc\/api.php?data=random-data",
+ "hostname": "restore-guest",
+ "tag": "",
+ "tags": [],
+ "os_id": 159,
+ "app_id": 0,
+ "image_id": "",
+ "firewall_group_id": "",
+ "features": [
+ "ipv6"
+ ]
+ },
+ {
+ "id": "5d8813ec-df65-4a69-8bfc-864aabe2a7d2",
+ "os": "Custom Installed",
+ "ram": 1024,
+ "disk": 25,
+ "main_ip": "100.68.102.40",
+ "vcpu_count": 1,
+ "region": "ord",
+ "plan": "vhp-1c-1gb-intel",
+ "date_created": "2022-12-05T13:29:19+00:00",
+ "status": "pending",
+ "allowed_bandwidth": 2000,
+ "netmask_v4": "255.255.254.0",
+ "gateway_v4": "45.76.228.1",
+ "power_status": "running",
+ "server_status": "none",
+ "v6_network": "",
+ "v6_main_ip": "",
+ "v6_network_size": 0,
+ "label": "snapshot-guest",
+ "internal_ip": "",
+ "kvm": "",
+ "hostname": "snapshot-guest",
+ "tag": "",
+ "tags": [],
+ "os_id": 159,
+ "app_id": 0,
+ "image_id": "",
+ "firewall_group_id": "",
+ "features": []
+ },
+ {
+ "id": "30c17c34-223f-436e-acbe-393af5293adb",
+ "os": "Debian 11 x64 (bullseye)",
+ "ram": 512,
+ "disk": 10,
+ "main_ip": "100.68.102.41",
+ "vcpu_count": 1,
+ "region": "ewr",
+ "plan": "vc2-1c-0.5gb-v6",
+ "date_created": "2022-12-05T12:43:00+00:00",
+ "status": "active",
+ "allowed_bandwidth": 500,
+ "netmask_v4": "255.255.192.0",
+ "gateway_v4": "100.68.64.1",
+ "power_status": "running",
+ "server_status": "ok",
+ "v6_network": "2001:19f0:face:8fd::",
+ "v6_main_ip": "2001:19f0:face:08fd:5400:04ff:beef:cafe",
+ "v6_network_size": 64,
+ "label": "debian-guest",
+ "internal_ip": "10.1.96.3",
+ "kvm": "https:\/\/my.vultr.com\/subs\/vps\/novnc\/api.php?data=random-data",
+ "hostname": "debian-guest",
+ "tag": "",
+ "tags": [
+ "vpc",
+ "vpc:d0db548b-5d50-4c94-9cdb-b083d46925f8",
+ "os:debian"
+ ],
+ "os_id": 477,
+ "app_id": 0,
+ "image_id": "",
+ "firewall_group_id": "",
+ "features": [
+ "auto_backups",
+ "ipv6"
+ ]
+ },
+ {
+ "id": "37d67f9f-17f0-4c56-879b-507355dc5174",
+ "os": "OpenBSD 7.2 x64",
+ "ram": 4096,
+ "disk": 30,
+ "main_ip": "100.68.102.42",
+ "vcpu_count": 1,
+ "region": "ewr",
+ "plan": "voc-g-1c-4gb-30s-amd",
+ "date_created": "2022-12-05T12:44:17+00:00",
+ "status": "active",
+ "allowed_bandwidth": 4000,
+ "netmask_v4": "255.255.254.0",
+ "gateway_v4": "45.63.22.1",
+ "power_status": "running",
+ "server_status": "ok",
+ "v6_network": "",
+ "v6_main_ip": "",
+ "v6_network_size": 0,
+ "label": "openbsd-guest",
+ "internal_ip": "",
+ "kvm": "https:\/\/my.vultr.com\/subs\/vps\/novnc\/api.php?data=random-data",
+ "hostname": "openbsd-guest",
+ "tag": "",
+ "tags": [],
+ "os_id": 1968,
+ "app_id": 0,
+ "image_id": "",
+ "firewall_group_id": "",
+ "features": []
+ }
+ ],
+ "meta": {
+ "total": 8,
+ "links": {
+ "next": "page2",
+ "prev": ""
+ }
+ }
+}
diff --git a/ansible_collections/vultr/cloud/tests/unit/plugins/inventory/fixtures/vultr_inventory_page2.json b/ansible_collections/vultr/cloud/tests/unit/plugins/inventory/fixtures/vultr_inventory_page2.json
new file mode 100644
index 000000000..2f4ace8fa
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/unit/plugins/inventory/fixtures/vultr_inventory_page2.json
@@ -0,0 +1,116 @@
+{
+ "instances": [
+ {
+ "id": "2db0bb8c-9d83-4e62-86ef-b3d999960d72",
+ "os": "Windows 2016 Standard",
+ "ram": 2048,
+ "disk": 50,
+ "main_ip": "100.68.102.43",
+ "vcpu_count": 1,
+ "region": "fra",
+ "plan": "vhp-1c-2gb-amd",
+ "date_created": "2022-12-05T12:50:30+00:00",
+ "status": "active",
+ "allowed_bandwidth": 3000,
+ "netmask_v4": "255.255.254.0",
+ "gateway_v4": "45.77.142.1",
+ "power_status": "running",
+ "server_status": "installingbooting",
+ "v6_network": "",
+ "v6_main_ip": "",
+ "v6_network_size": 0,
+ "label": "windows-guest",
+ "internal_ip": "",
+ "kvm": "https:\/\/my.vultr.com\/subs\/vps\/novnc\/api.php?data=random-data",
+ "hostname": "windows-guest",
+ "tag": "",
+ "tags": [
+ "os:windows2016"
+ ],
+ "os_id": 240,
+ "app_id": 0,
+ "image_id": "",
+ "firewall_group_id": "",
+ "features": []
+ },
+ {
+ "id": "e0aabdd7-7d68-448a-a0ce-a7712b09fcc1",
+ "os": "Arch Linux x64",
+ "ram": 6144,
+ "disk": 70,
+ "main_ip": "100.68.102.44",
+ "vcpu_count": 1,
+ "region": "sjc",
+ "plan": "vcg-a100-1c-6g-4vram",
+ "date_created": "2022-12-05T12:52:06+00:00",
+ "status": "active",
+ "allowed_bandwidth": 1000,
+ "netmask_v4": "255.255.254.0",
+ "gateway_v4": "140.82.50.1",
+ "power_status": "running",
+ "server_status": "installingbooting",
+ "v6_network": "2001:19f0:face:1df3::",
+ "v6_main_ip": "2001:19f0:face:1df3:5400:04ff:beef:cafe",
+ "v6_network_size": 64,
+ "label": "mldev-guest",
+ "internal_ip": "",
+ "kvm": "https:\/\/my.vultr.com\/subs\/vps\/novnc\/api.php?data=random-data",
+ "hostname": "mldev-guest",
+ "tag": "",
+ "tags": [],
+ "os_id": 535,
+ "app_id": 0,
+ "image_id": "mldev",
+ "firewall_group_id": "",
+ "features": [
+ "auto_backups",
+ "ipv6"
+ ]
+ },
+ {
+ "id": "90676f7b-5a34-49a8-b770-b0abed017577",
+ "os": "Application",
+ "ram": 2048,
+ "disk": 64,
+ "main_ip": "100.68.102.45",
+ "vcpu_count": 1,
+ "region": "ord",
+ "plan": "vhf-1c-2gb",
+ "date_created": "2022-12-05T12:54:37+00:00",
+ "status": "active",
+ "allowed_bandwidth": 2000,
+ "netmask_v4": "255.255.254.0",
+ "gateway_v4": "149.28.114.1",
+ "power_status": "running",
+ "server_status": "installingbooting",
+ "v6_network": "2001:19f0:face:16ec::",
+ "v6_main_ip": "2001:19f0:face:16ec:5400:04ff:beef:cafe",
+ "v6_network_size": 64,
+ "label": "wordpress-guest",
+ "internal_ip": "10.2.96.3",
+ "kvm": "https:\/\/my.vultr.com\/subs\/vps\/novnc\/api.php?data=random-data",
+ "hostname": "wordpress-guest",
+ "tag": "",
+ "tags": [
+ "vpc",
+ "vpc:d0db548b-5d50-4c94-9cdb-b083d46925f8",
+ "application"
+ ],
+ "os_id": 186,
+ "app_id": 2,
+ "image_id": "",
+ "firewall_group_id": "",
+ "features": [
+ "auto_backups",
+ "ipv6"
+ ]
+ }
+ ],
+ "meta": {
+ "total": 8,
+ "links": {
+ "next": "",
+ "prev": "page1"
+ }
+ }
+}
diff --git a/ansible_collections/vultr/cloud/tests/unit/plugins/inventory/test_vultr.py b/ansible_collections/vultr/cloud/tests/unit/plugins/inventory/test_vultr.py
new file mode 100644
index 000000000..aa8d8fbce
--- /dev/null
+++ b/ansible_collections/vultr/cloud/tests/unit/plugins/inventory/test_vultr.py
@@ -0,0 +1,233 @@
+from __future__ import absolute_import, division, print_function
+
+__metaclass__ = type
+
+import json
+import os.path
+import pytest
+
+from ansible.errors import AnsibleError, AnsibleParserError
+from ansible.inventory.data import InventoryData
+from ansible.parsing.dataloader import DataLoader
+from ansible.template import Templar
+
+import ansible_collections.vultr.cloud.plugins.inventory.vultr as module_under_test
+from ansible_collections.vultr.cloud.plugins.inventory.vultr import InventoryModule
+
+
+default_options = {
+ "api_endpoint": "https://test.api.vultr.com/v2",
+ "api_key": "TEST_VULTR_API_KEY",
+ "api_results_per_page": 100,
+ "api_timeout": 60,
+ "attributes": ["id", "region", "label", "plan", "hostname", "main_ip"],
+ "filters": [],
+ "plugin": "vultr.cloud.vultr",
+ "variable_prefix": "vultr_",
+ "validate_certs": True,
+}
+
+
+def get_option(opts):
+ def func(option):
+ return opts.get(option, False)
+
+ return func
+
+
+def load_fixture(filename):
+ return open(os.path.join(os.path.dirname(__file__), "fixtures", filename))
+
+
+def get_paginated_json_response(url):
+ cursor = "page1"
+ if "&cursor=" in url:
+ cursor = "page2"
+ return load_fixture("vultr_inventory_{0}.json".format(cursor))
+
+
+@pytest.fixture()
+def inventory():
+ r = InventoryModule()
+ r.inventory = InventoryData()
+ r.templar = Templar(loader=DataLoader())
+ return r
+
+
+@pytest.fixture()
+def instances():
+ return json.load(load_fixture("vultr_inventory.json"))
+
+
+def test_verify_file_no_filename(inventory):
+ assert inventory.verify_file("") is False
+
+
+def test_verify_file_valid_filename(tmp_path, inventory):
+ valid_config = tmp_path / "vultr.yaml"
+ valid_config.touch()
+ assert inventory.verify_file(str(valid_config)) is True
+
+
+def test_verify_file_invalid_filename(tmp_path, inventory):
+ invalid_config = tmp_path / "vultr.notyaml"
+ invalid_config.touch()
+ assert inventory.verify_file(str(invalid_config)) is False
+
+
+@pytest.mark.parametrize("cache_option", [True, False])
+def test_parse(tmp_path, inventory, mocker, cache_option):
+ inventory_file = tmp_path / "vultr.yaml"
+ inventory_file.write_text("---\nplugin: vultr.cloud.vultr")
+
+ plugin_cache_dir = tmp_path / "cache"
+
+ opts = default_options.copy()
+ opts.update(
+ {
+ "cache": cache_option,
+ "cache_connection": plugin_cache_dir,
+ "cache_plugin": "jsonfile",
+ }
+ )
+ inventory.get_option = mocker.MagicMock(side_effect=get_option(opts))
+
+ mocker.patch("{0}.Request".format(module_under_test.__name__))
+ RequestMock = module_under_test.Request
+
+ req = RequestMock.return_value
+ req.get.side_effect = get_paginated_json_response
+
+ inventory._redirected_names = ["vultr.cloud.vultr", "vultr"]
+ inventory._load_name = "vultr.cloud.vultr"
+ inventory.parse(inventory.inventory, DataLoader(), str(inventory_file))
+
+ if cache_option:
+ RequestMock.reset_mock()
+
+ inventory.parse(inventory.inventory, DataLoader(), str(inventory_file))
+ RequestMock.assert_not_called()
+
+ assert len(inventory.inventory.hosts.items()) > 0
+
+
+def test_parse_non_plugin_invalid_parameter(inventory):
+ try:
+ inventory.parse(None, DataLoader(), "")
+ assert False, "Expected parse() to raise AnsibleParserError"
+ except AnsibleParserError:
+ pass
+
+
+def test_get_instances(inventory, mocker):
+ inventory.get_option = mocker.MagicMock(side_effect=get_option(default_options))
+
+ mocker.patch("{0}.Request".format(module_under_test.__name__))
+ RequestMock = module_under_test.Request
+
+ req = RequestMock.return_value
+ req.get.side_effect = get_paginated_json_response
+
+ instance_list = inventory._get_instances()
+ assert len(instance_list) == 8
+
+
+def test_get_instances_invalid_api_key(inventory, mocker):
+ inventory.get_option = mocker.MagicMock(side_effect=get_option(default_options))
+
+ mocker.patch("{0}.Request".format(module_under_test.__name__))
+ RequestMock = module_under_test.Request
+
+ req = RequestMock.return_value
+ req.get.return_value = load_fixture("unauthorized_vultr_inventory.json")
+
+ try:
+ inventory._get_instances()
+ assert False, "Expected _get_instances() to raise AnsibleParserError"
+ except AnsibleParserError:
+ pass
+
+
+def test_get_instances_templated_api_key(inventory, mocker):
+ opts = default_options.copy()
+ opts.update({"api_key": '{{ lookup("random_choice", "TEST_VULTR_API_KEY") }}'})
+
+ inventory.get_option = mocker.MagicMock(side_effect=get_option(opts))
+
+ mocker.patch("{0}.Request".format(module_under_test.__name__))
+ RequestMock = module_under_test.Request
+
+ req = RequestMock.return_value
+ req.get.return_value = load_fixture("empty_vultr_inventory.json")
+
+ inventory._get_instances()
+
+ req_headers = RequestMock.call_args.kwargs["headers"]
+ assert req_headers.get("Authorization") == "Bearer TEST_VULTR_API_KEY"
+
+
+def test_populate(inventory, instances, mocker):
+ inventory.get_option = mocker.MagicMock(side_effect=get_option(default_options))
+ inventory._populate(instances)
+
+ assert len(inventory.inventory.hosts.items()) > 0
+
+
+def test_populate_with_empty_response(inventory, mocker):
+ inventory.get_option = mocker.MagicMock(side_effect=get_option(default_options))
+
+ mocker.patch("{0}.Request".format(module_under_test.__name__))
+ RequestMock = module_under_test.Request
+
+ req = RequestMock.return_value
+ req.get.return_value = load_fixture("empty_vultr_inventory.json")
+
+ inventory._populate(inventory._get_instances())
+
+ assert len(inventory.inventory.hosts.items()) == 0
+
+
+def test_populate_host_variables(inventory, instances, mocker):
+ inventory.get_option = mocker.MagicMock(side_effect=get_option(default_options))
+ inventory._populate(instances)
+
+ windows_host = inventory.inventory.get_host("windows-guest")
+ assert windows_host.vars["vultr_plan"] == "vhp-1c-2gb-amd"
+ assert windows_host.vars["vultr_region"] == "fra"
+ assert windows_host.vars["vultr_id"] == "2db0bb8c-9d83-4e62-86ef-b3d999960d72"
+
+
+def test_populate_host_variables_with_filters(inventory, instances, mocker):
+ opts = default_options.copy()
+ opts.update({"filters": ['vultr_id == "37d67f9f-17f0-4c56-879b-507355dc5174"']})
+
+ inventory.get_option = mocker.MagicMock(side_effect=get_option(opts))
+ inventory._populate(instances)
+
+ unfiltered_host = inventory.inventory.get_host("openbsd-guest")
+ filtered_host = inventory.inventory.get_host("debian-guest")
+
+ for host in inventory.inventory.hosts:
+ this_host = inventory.inventory.get_host(host)
+ assert "vultr_id" in this_host.vars
+ assert this_host.vars["vultr_id"] == "37d67f9f-17f0-4c56-879b-507355dc5174"
+
+ assert len(inventory.inventory.hosts.items()) == 1
+ assert unfiltered_host.vars["vultr_plan"] == "voc-g-1c-4gb-30s-amd"
+ assert filtered_host is None
+
+
+def test_passes_filters_invalid_filter_not_strict(inventory):
+ try:
+ inventory._passes_filters(["invalid filter"], {}, "host", False)
+ assert True
+ except AnsibleError:
+ assert False, "unexpected AnsibleError from _passes_filters()"
+
+
+def test_passes_filters_invalid_filter_strict(inventory):
+ try:
+ inventory._passes_filters(["invalid filter"], {}, "host", True)
+ assert False, "expected _passes_filters() to raise AnsibleError"
+ except AnsibleError:
+ pass