Vultr: rename _facts -> _info (#61239)

pull/61265/head
Felix Fontein 5 years ago committed by René Moser
parent 1fbb930747
commit c3b1a0a7e8

@ -0,0 +1,8 @@
minor_changes:
- The ``vultr_dns_domain_facts`` module has been deprecated. Use ``vultr_dns_domain_info`` instead.
- The ``vultr_firewall_group_facts`` module has been deprecated. Use ``vultr_firewall_group_info`` instead.
- The ``vultr_network_facts`` module has been deprecated. Use ``vultr_network_info`` instead.
- The ``vultr_plan_facts`` module has been deprecated. Use ``vultr_plan_info`` instead.
- The ``vultr_region_facts`` module has been deprecated. Use ``vultr_region_info`` instead.
- The ``vultr_server_facts`` module has been deprecated. Use ``vultr_server_info`` instead.
- The ``vultr_startup_script_facts`` module has been deprecated. Use ``vultr_startup_script_info`` instead.

@ -94,6 +94,20 @@ The following modules will be removed in Ansible 2.13. Please update update your
* purefb_facts use :ref:`purefb_info <purefb_info_module>` instead.
* vultr_dns_domain_facts use :ref:`vultr_dns_domain_info <vultr_dns_domain_info_module>` instead.
* vultr_firewall_group_facts use :ref:`vultr_firewall_group_info <vultr_firewall_group_info_module>` instead.
* vultr_network_facts use :ref:`vultr_network_info <vultr_network_info_module>` instead.
* vultr_plan_facts use :ref:`vultr_plan_info <vultr_plan_info_module>` instead.
* vultr_region_facts use :ref:`vultr_region_info <vultr_region_info_module>` instead.
* vultr_server_facts use :ref:`vultr_server_info <vultr_server_info_module>` instead.
* vultr_startup_script_facts use :ref:`vultr_startup_script_info <vultr_startup_script_info_module>` instead.
* vyos_interface use :ref:`vyos_interfaces <vyos_interfaces_module>` instead.
* vyos_l3_interface use :ref:`vyos_l3_interfaces <vyos_l3_interfaces_module>` instead.

@ -55,18 +55,10 @@ To check that everything is working properly run the following command:
.. code-block:: console
#> VULTR_API_KEY=XXX ansible -m vultr_account_facts localhost
#> VULTR_API_KEY=XXX ansible -m vultr_account_info localhost
localhost | SUCCESS => {
"ansible_facts": {
"vultr_account_facts": {
"balance": -8.9,
"last_payment_amount": -10.0,
"last_payment_date": "2018-07-21 11:34:46",
"pending_charges": 6.0
}
},
"changed": false,
"vultr_account_facts": {
"vultr_account_info": {
"balance": -8.9,
"last_payment_amount": -10.0,
"last_payment_date": "2018-07-21 11:34:46",
@ -172,8 +164,8 @@ Run all Vultr tests:
$ ansible-test integration cloud/vultr/ -v --diff --allow-unsupported
To run a specific test, e.g. vultr_account_facts:
To run a specific test, e.g. vultr_account_info:
.. code-block:: shell
$ ansible-test integration cloud/vultr/vultr_account_facts -v --diff --allow-unsupported
$ ansible-test integration cloud/vultr/vultr_account_info -v --diff --allow-unsupported

@ -7,12 +7,16 @@ from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'],
'status': ['deprecated'],
'supported_by': 'community'}
DOCUMENTATION = r'''
---
module: vultr_dns_domain_facts
deprecated:
removed_in: '2.13'
why: Deprecated in favour of C(_info) module.
alternative: Use M(vultr_dns_domain_info) instead.
short_description: Gather facts about the Vultr DNS domains available.
description:
- Gather facts about DNS domains available in Vultr.

@ -7,12 +7,16 @@ from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'],
'status': ['deprecated'],
'supported_by': 'community'}
DOCUMENTATION = r'''
---
module: vultr_firewall_group_facts
deprecated:
removed_in: '2.13'
why: Deprecated in favour of C(_info) module.
alternative: Use M(vultr_firewall_group_info) instead.
short_description: Gather facts about the Vultr firewall groups available.
description:
- Gather facts about firewall groups available in Vultr.

@ -7,12 +7,16 @@ from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'],
'status': ['deprecated'],
'supported_by': 'community'}
DOCUMENTATION = r'''
---
module: vultr_network_facts
deprecated:
removed_in: '2.13'
why: Deprecated in favour of C(_info) module.
alternative: Use M(vultr_network_info) instead.
short_description: Gather facts about the Vultr networks available.
description:
- Gather facts about networks available in Vultr.

@ -8,12 +8,16 @@ from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'],
'status': ['deprecated'],
'supported_by': 'community'}
DOCUMENTATION = r'''
---
module: vultr_plan_facts
deprecated:
removed_in: '2.13'
why: Deprecated in favour of C(_info) module.
alternative: Use M(vultr_plan_info) instead.
short_description: Gather facts about the Vultr plans available.
description:
- Gather facts about plans available to boot servers.

@ -8,12 +8,16 @@ from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'],
'status': ['deprecated'],
'supported_by': 'community'}
DOCUMENTATION = r'''
---
module: vultr_region_facts
deprecated:
removed_in: '2.13'
why: Deprecated in favour of C(_info) module.
alternative: Use M(vultr_region_info) instead.
short_description: Gather facts about the Vultr regions available.
description:
- Gather facts about regions available to boot servers.

@ -8,12 +8,16 @@ from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'],
'status': ['deprecated'],
'supported_by': 'community'}
DOCUMENTATION = r'''
---
module: vultr_server_facts
deprecated:
removed_in: '2.13'
why: Deprecated in favour of C(_info) module.
alternative: Use M(vultr_server_info) instead.
short_description: Gather facts about the Vultr servers available.
description:
- Gather facts about servers available.

@ -8,12 +8,16 @@ from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'],
'status': ['deprecated'],
'supported_by': 'community'}
DOCUMENTATION = r'''
---
module: vultr_startup_script_facts
deprecated:
removed_in: '2.13'
why: Deprecated in favour of C(_info) module.
alternative: Use M(vultr_startup_script_info) instead.
short_description: Gather facts about the Vultr startup scripts available.
description:
- Gather facts about vultr_startup_scripts available.

@ -0,0 +1,116 @@
#!/usr/bin/python
#
# (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)
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'],
'supported_by': 'community'}
DOCUMENTATION = r'''
---
module: vultr_dns_domain_info
short_description: Gather information about the Vultr DNS domains available.
description:
- Gather information about DNS domains available in Vultr.
version_added: "2.9"
author: "Yanis Guenane (@Spredzy)"
extends_documentation_fragment: vultr
'''
EXAMPLES = r'''
- name: Gather Vultr DNS domains information
local_action:
module: vultr_dns_domains_info
register: result
- name: Print the gathered information
debug:
var: result.vultr_dns_domain_info
'''
RETURN = r'''
---
vultr_api:
description: Response from Vultr API with a few additions/modification
returned: success
type: complex
contains:
api_account:
description: Account used in the ini file to select the key
returned: success
type: str
sample: default
api_timeout:
description: Timeout used for the API requests
returned: success
type: int
sample: 60
api_retries:
description: Amount of max retries for the API requests
returned: success
type: int
sample: 5
api_retry_max_delay:
description: Exponential backoff delay in seconds between retries up to this max delay value.
returned: success
type: int
sample: 12
version_added: '2.9'
api_endpoint:
description: Endpoint used for the API requests
returned: success
type: str
sample: "https://api.vultr.com"
vultr_dns_domain_info:
description: Response from Vultr API
returned: success
type: complex
contains:
"vultr_dns_domain_info": [
{
"date_created": "2018-07-19 07:14:21",
"domain": "ansibletest.com"
}
]
'''
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.vultr import (
Vultr,
vultr_argument_spec,
)
class AnsibleVultrDnsDomainInfo(Vultr):
def __init__(self, module):
super(AnsibleVultrDnsDomainInfo, self).__init__(module, "vultr_dns_domain_info")
self.returns = {
"date_created": dict(),
"domain": dict(),
}
def get_domains(self):
return self.api_query(path="/v1/dns/list")
def main():
argument_spec = vultr_argument_spec()
module = AnsibleModule(
argument_spec=argument_spec,
supports_check_mode=True,
)
domain_info = AnsibleVultrDnsDomainInfo(module)
result = domain_info.get_result(domain_info.get_domains())
module.exit_json(**result)
if __name__ == '__main__':
main()

@ -0,0 +1,133 @@
#!/usr/bin/python
#
# (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)
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'],
'supported_by': 'community'}
DOCUMENTATION = r'''
---
module: vultr_firewall_group_info
short_description: Gather information about the Vultr firewall groups available.
description:
- Gather information about firewall groups available in Vultr.
version_added: "2.9"
author: "Yanis Guenane (@Spredzy)"
extends_documentation_fragment: vultr
'''
EXAMPLES = r'''
- name: Gather Vultr firewall groups information
local_action:
module: vultr_firewall_group_info
register: result
- name: Print the gathered information
debug:
var: result.vultr_firewall_group_info
'''
RETURN = r'''
---
vultr_api:
description: Response from Vultr API with a few additions/modification
returned: success
type: complex
contains:
api_account:
description: Account used in the ini file to select the key
returned: success
type: str
sample: default
api_timeout:
description: Timeout used for the API requests
returned: success
type: int
sample: 60
api_retries:
description: Amount of max retries for the API requests
returned: success
type: int
sample: 5
api_retry_max_delay:
description: Exponential backoff delay in seconds between retries up to this max delay value.
returned: success
type: int
sample: 12
version_added: '2.9'
api_endpoint:
description: Endpoint used for the API requests
returned: success
type: str
sample: "https://api.vultr.com"
vultr_firewall_group_info:
description: Response from Vultr API
returned: success
type: complex
contains:
"vultr_firewall_group_info": [
{
"date_created": "2018-07-12 10:27:14",
"date_modified": "2018-07-12 10:27:14",
"description": "test",
"id": "5e128ff0",
"instance_count": 0,
"max_rule_count": 50,
"rule_count": 0
}
]
'''
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.vultr import (
Vultr,
vultr_argument_spec,
)
class AnsibleVultrFirewallGroupInfo(Vultr):
def __init__(self, module):
super(AnsibleVultrFirewallGroupInfo, self).__init__(module, "vultr_firewall_group_info")
self.returns = {
"FIREWALLGROUPID": dict(key='id'),
"date_created": dict(),
"date_modified": dict(),
"description": dict(),
"instance_count": dict(convert_to='int'),
"max_rule_count": dict(convert_to='int'),
"rule_count": dict(convert_to='int')
}
def get_firewall_group(self):
return self.api_query(path="/v1/firewall/group_list")
def parse_fw_group_list(fwgroups_list):
if not fwgroups_list:
return []
return [group for id, group in fwgroups_list.items()]
def main():
argument_spec = vultr_argument_spec()
module = AnsibleModule(
argument_spec=argument_spec,
supports_check_mode=True,
)
fw_group_info = AnsibleVultrFirewallGroupInfo(module)
result = fw_group_info.get_result(parse_fw_group_list(fw_group_info.get_firewall_group()))
module.exit_json(**result)
if __name__ == '__main__':
main()

@ -0,0 +1,139 @@
#!/usr/bin/python
#
# (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)
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'],
'supported_by': 'community'}
DOCUMENTATION = r'''
---
module: vultr_network_info
short_description: Gather information about the Vultr networks available.
description:
- Gather information about networks available in Vultr.
version_added: "2.9"
author: "Yanis Guenane (@Spredzy)"
extends_documentation_fragment: vultr
'''
EXAMPLES = r'''
- name: Gather Vultr networks information
local_action:
module: vultr_network_info
register: result
- name: Print the gathered information
debug:
var: result.vultr_network_info
'''
RETURN = r'''
---
vultr_api:
description: Response from Vultr API with a few additions/modification
returned: success
type: complex
contains:
api_account:
description: Account used in the ini file to select the key
returned: success
type: str
sample: default
api_timeout:
description: Timeout used for the API requests
returned: success
type: int
sample: 60
api_retries:
description: Amount of max retries for the API requests
returned: success
type: int
sample: 5
api_retry_max_delay:
description: Exponential backoff delay in seconds between retries up to this max delay value.
returned: success
type: int
sample: 12
version_added: '2.9'
api_endpoint:
description: Endpoint used for the API requests
returned: success
type: str
sample: "https://api.vultr.com"
vultr_network_info:
description: Response from Vultr API
returned: success
type: complex
contains:
"vultr_network_info": [
{
"date_created": "2018-08-02 11:18:49",
"id": "net5b62e8991adfg",
"name": "mynet",
"region": "Amsterdam",
"v4_subnet": "192.168.42.0",
"v4_subnet_mask": 24
}
]
'''
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.vultr import (
Vultr,
vultr_argument_spec,
)
class AnsibleVultrNetworkInfo(Vultr):
def __init__(self, module):
super(AnsibleVultrNetworkInfo, self).__init__(module, "vultr_network_info")
self.returns = {
'DCID': dict(key='region', transform=self._get_region_name),
'NETWORKID': dict(key='id'),
'date_created': dict(),
'description': dict(key='name'),
'v4_subnet': dict(),
'v4_subnet_mask': dict(convert_to='int'),
}
def _get_region_name(self, region):
return self.query_resource_by_key(
key='DCID',
value=region,
resource='regions',
use_cache=True
)['name']
def get_networks(self):
return self.api_query(path="/v1/network/list")
def parse_network_list(network_list):
if isinstance(network_list, list):
return []
return [network for id, network in network_list.items()]
def main():
argument_spec = vultr_argument_spec()
module = AnsibleModule(
argument_spec=argument_spec,
supports_check_mode=True,
)
network_info = AnsibleVultrNetworkInfo(module)
result = network_info.get_result(parse_network_list(network_info.get_networks()))
module.exit_json(**result)
if __name__ == '__main__':
main()

@ -0,0 +1,143 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# (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)
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'],
'supported_by': 'community'}
DOCUMENTATION = r'''
---
module: vultr_plan_info
short_description: Gather information about the Vultr plans available.
description:
- Gather information about plans available to boot servers.
version_added: "2.9"
author: "Yanis Guenane (@Spredzy)"
extends_documentation_fragment: vultr
'''
EXAMPLES = r'''
- name: Gather Vultr plans information
local_action:
module: vultr_plan_info
register: result
- name: Print the gathered information
debug:
var: result.vultr_plan_info
'''
RETURN = r'''
---
vultr_api:
description: Response from Vultr API with a few additions/modification
returned: success
type: complex
contains:
api_account:
description: Account used in the ini file to select the key
returned: success
type: str
sample: default
api_timeout:
description: Timeout used for the API requests
returned: success
type: int
sample: 60
api_retries:
description: Amount of max retries for the API requests
returned: success
type: int
sample: 5
api_retry_max_delay:
description: Exponential backoff delay in seconds between retries up to this max delay value.
returned: success
type: int
sample: 12
version_added: '2.9'
api_endpoint:
description: Endpoint used for the API requests
returned: success
type: str
sample: "https://api.vultr.com"
vultr_plan_info:
description: Response from Vultr API
returned: success
type: complex
contains:
plan:
description: List of the plans available.
returned: success
type: list
sample: [{
"available_locations": [
1
],
"bandwidth": 40.0,
"bandwidth_gb": 40960,
"disk": 110,
"id": 118,
"name": "32768 MB RAM,110 GB SSD,40.00 TB BW",
"plan_type": "DEDICATED",
"price_per_month": 240.0,
"ram": 32768,
"vcpu_count": 8,
"windows": false
}]
'''
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.vultr import (
Vultr,
vultr_argument_spec,
)
class AnsibleVultrPlanInfo(Vultr):
def __init__(self, module):
super(AnsibleVultrPlanInfo, self).__init__(module, "vultr_plan_info")
self.returns = {
"VPSPLANID": dict(key='id', convert_to='int'),
"available_locations": dict(),
"bandwidth": dict(convert_to='float'),
"bandwidth_gb": dict(convert_to='int'),
"disk": dict(convert_to='int'),
"name": dict(),
"plan_type": dict(),
"price_per_month": dict(convert_to='float'),
"ram": dict(convert_to='int'),
"vcpu_count": dict(convert_to='int'),
"windows": dict(convert_to='bool')
}
def get_plans(self):
return self.api_query(path="/v1/plans/list")
def parse_plans_list(plans_list):
return [plan for id, plan in plans_list.items()]
def main():
argument_spec = vultr_argument_spec()
module = AnsibleModule(
argument_spec=argument_spec,
supports_check_mode=True,
)
plan_info = AnsibleVultrPlanInfo(module)
result = plan_info.get_result(parse_plans_list(plan_info.get_plans()))
module.exit_json(**result)
if __name__ == '__main__':
main()

@ -0,0 +1,133 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# (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)
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'],
'supported_by': 'community'}
DOCUMENTATION = r'''
---
module: vultr_region_info
short_description: Gather information about the Vultr regions available.
description:
- Gather information about regions available to boot servers.
version_added: "2.9"
author: "Yanis Guenane (@Spredzy)"
extends_documentation_fragment: vultr
'''
EXAMPLES = r'''
- name: Gather Vultr regions information
local_action:
module: vultr_region_info
register: result
- name: Print the gathered information
debug:
var: result.vultr_region_info
'''
RETURN = r'''
---
vultr_api:
description: Response from Vultr API with a few additions/modification
returned: success
type: complex
contains:
api_account:
description: Account used in the ini file to select the key
returned: success
type: str
sample: default
api_timeout:
description: Timeout used for the API requests
returned: success
type: int
sample: 60
api_retries:
description: Amount of max retries for the API requests
returned: success
type: int
sample: 5
api_retry_max_delay:
description: Exponential backoff delay in seconds between retries up to this max delay value.
returned: success
type: int
sample: 12
version_added: '2.9'
api_endpoint:
description: Endpoint used for the API requests
returned: success
type: str
sample: "https://api.vultr.com"
vultr_region_info:
description: Response from Vultr API
returned: success
type: complex
contains:
"vultr_region_info": [
{
"block_storage": false,
"continent": "Europe",
"country": "GB",
"ddos_protection": true,
"id": 8,
"name": "London",
"regioncode": "LHR",
"state": ""
}
]
'''
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.vultr import (
Vultr,
vultr_argument_spec,
)
class AnsibleVultrRegionInfo(Vultr):
def __init__(self, module):
super(AnsibleVultrRegionInfo, self).__init__(module, "vultr_region_info")
self.returns = {
"DCID": dict(key='id', convert_to='int'),
"block_storage": dict(convert_to='bool'),
"continent": dict(),
"country": dict(),
"ddos_protection": dict(convert_to='bool'),
"name": dict(),
"regioncode": dict(),
"state": dict()
}
def get_regions(self):
return self.api_query(path="/v1/regions/list")
def parse_regions_list(regions_list):
return [region for id, region in regions_list.items()]
def main():
argument_spec = vultr_argument_spec()
module = AnsibleModule(
argument_spec=argument_spec,
supports_check_mode=True,
)
region_info = AnsibleVultrRegionInfo(module)
result = region_info.get_result(parse_regions_list(region_info.get_regions()))
module.exit_json(**result)
if __name__ == '__main__':
main()

@ -0,0 +1,192 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# (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)
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'],
'supported_by': 'community'}
DOCUMENTATION = r'''
---
module: vultr_server_info
short_description: Gather information about the Vultr servers available.
description:
- Gather information about servers available.
version_added: "2.9"
author: "Yanis Guenane (@Spredzy)"
extends_documentation_fragment: vultr
'''
EXAMPLES = r'''
- name: Gather Vultr servers information
local_action:
module: vultr_server_info
register: result
- name: Print the gathered information
debug:
var: result.vultr_server_info
'''
RETURN = r'''
---
vultr_api:
description: Response from Vultr API with a few additions/modification
returned: success
type: complex
contains:
api_account:
description: Account used in the ini file to select the key
returned: success
type: str
sample: default
api_timeout:
description: Timeout used for the API requests
returned: success
type: int
sample: 60
api_retries:
description: Amount of max retries for the API requests
returned: success
type: int
sample: 5
api_retry_max_delay:
description: Exponential backoff delay in seconds between retries up to this max delay value.
returned: success
type: int
sample: 12
version_added: '2.9'
api_endpoint:
description: Endpoint used for the API requests
returned: success
type: str
sample: "https://api.vultr.com"
vultr_server_info:
description: Response from Vultr API
returned: success
type: complex
contains:
"vultr_server_info": [
{
"allowed_bandwidth_gb": 1000,
"auto_backup_enabled": false,
"application": null,
"cost_per_month": 5.00,
"current_bandwidth_gb": 0,
"date_created": "2018-07-19 08:23:03",
"default_password": "p4ssw0rd!",
"disk": "Virtual 25 GB",
"firewallgroup": null,
"id": 17241096,
"internal_ip": "",
"kvm_url": "https://my.vultr.com/subs/vps/novnc/api.php?data=OFB...",
"name": "ansibletest",
"os": "CentOS 7 x64",
"pending_charges": 0.01,
"plan": "1024 MB RAM,25 GB SSD,1.00 TB BW",
"power_status": "running",
"ram": "1024 MB",
"region": "Amsterdam",
"server_state": "ok",
"status": "active",
"tag": "",
"v4_gateway": "105.178.158.1",
"v4_main_ip": "105.178.158.181",
"v4_netmask": "255.255.254.0",
"v6_main_ip": "",
"v6_network": "",
"v6_network_size": "",
"v6_networks": [],
"vcpu_count": 1
}
]
'''
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.vultr import (
Vultr,
vultr_argument_spec,
)
class AnsibleVultrServerInfo(Vultr):
def __init__(self, module):
super(AnsibleVultrServerInfo, self).__init__(module, "vultr_server_info")
self.returns = {
"APPID": dict(key='application', convert_to='int', transform=self._get_application_name),
"FIREWALLGROUPID": dict(key='firewallgroup', transform=self._get_firewallgroup_name),
"SUBID": dict(key='id', convert_to='int'),
"VPSPLANID": dict(key='plan', convert_to='int', transform=self._get_plan_name),
"allowed_bandwidth_gb": dict(convert_to='int'),
'auto_backups': dict(key='auto_backup_enabled', convert_to='bool'),
"cost_per_month": dict(convert_to='float'),
"current_bandwidth_gb": dict(convert_to='float'),
"date_created": dict(),
"default_password": dict(),
"disk": dict(),
"gateway_v4": dict(key='v4_gateway'),
"internal_ip": dict(),
"kvm_url": dict(),
"label": dict(key='name'),
"location": dict(key='region'),
"main_ip": dict(key='v4_main_ip'),
"netmask_v4": dict(key='v4_netmask'),
"os": dict(),
"pending_charges": dict(convert_to='float'),
"power_status": dict(),
"ram": dict(),
"server_state": dict(),
"status": dict(),
"tag": dict(),
"v6_main_ip": dict(),
"v6_network": dict(),
"v6_network_size": dict(),
"v6_networks": dict(),
"vcpu_count": dict(convert_to='int'),
}
def _get_application_name(self, application):
if application == 0:
return None
return self.get_application(application, 'APPID').get('name')
def _get_firewallgroup_name(self, firewallgroup):
if firewallgroup == 0:
return None
return self.get_firewallgroup(firewallgroup, 'FIREWALLGROUPID').get('description')
def _get_plan_name(self, plan):
return self.get_plan(plan, 'VPSPLANID').get('name')
def get_servers(self):
return self.api_query(path="/v1/server/list")
def parse_servers_list(servers_list):
return [server for id, server in servers_list.items()]
def main():
argument_spec = vultr_argument_spec()
module = AnsibleModule(
argument_spec=argument_spec,
supports_check_mode=True,
)
server_info = AnsibleVultrServerInfo(module)
result = server_info.get_result(parse_servers_list(server_info.get_servers()))
module.exit_json(**result)
if __name__ == '__main__':
main()

@ -0,0 +1,132 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# (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)
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'],
'supported_by': 'community'}
DOCUMENTATION = r'''
---
module: vultr_startup_script_info
short_description: Gather information about the Vultr startup scripts available.
description:
- Gather information about vultr_startup_scripts available.
version_added: "2.9"
author: "Yanis Guenane (@Spredzy)"
extends_documentation_fragment: vultr
'''
EXAMPLES = r'''
- name: Gather Vultr startup scripts information
local_action:
module: vultr_startup_script_info
register: result
- name: Print the gathered information
debug:
var: result.vultr_startup_script_info
'''
RETURN = r'''
---
vultr_api:
description: Response from Vultr API with a few additions/modification
returned: success
type: complex
contains:
api_account:
description: Account used in the ini file to select the key
returned: success
type: str
sample: default
api_timeout:
description: Timeout used for the API requests
returned: success
type: int
sample: 60
api_retries:
description: Amount of max retries for the API requests
returned: success
type: int
sample: 5
api_retry_max_delay:
description: Exponential backoff delay in seconds between retries up to this max delay value.
returned: success
type: int
sample: 12
version_added: '2.9'
api_endpoint:
description: Endpoint used for the API requests
returned: success
type: str
sample: "https://api.vultr.com"
vultr_startup_script_info:
description: Response from Vultr API
returned: success
type: complex
contains:
"vultr_startup_script_info": [
{
"date_created": "2018-07-19 08:38:36",
"date_modified": "2018-07-19 08:38:36",
"id": 327133,
"name": "lolo",
"script": "#!/bin/bash\necho Hello World > /root/hello",
"type": "boot"
}
]
'''
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.vultr import (
Vultr,
vultr_argument_spec,
)
class AnsibleVultrStartupScriptInfo(Vultr):
def __init__(self, module):
super(AnsibleVultrStartupScriptInfo, self).__init__(module, "vultr_startup_script_info")
self.returns = {
"SCRIPTID": dict(key='id', convert_to='int'),
"date_created": dict(),
"date_modified": dict(),
"name": dict(),
"script": dict(),
"type": dict(),
}
def get_startupscripts(self):
return self.api_query(path="/v1/startupscript/list")
def parse_startupscript_list(startupscipts_list):
if not startupscipts_list:
return []
return [startupscript for id, startupscript in startupscipts_list.items()]
def main():
argument_spec = vultr_argument_spec()
module = AnsibleModule(
argument_spec=argument_spec,
supports_check_mode=True,
)
startupscript_info = AnsibleVultrStartupScriptInfo(module)
result = startupscript_info.get_result(parse_startupscript_list(startupscript_info.get_startupscripts()))
module.exit_json(**result)
if __name__ == '__main__':
main()

@ -1,30 +0,0 @@
# 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: Create the record
vultr_dns_domain:
name: '{{ dns_domain_name }}'
server_ip: '{{ dns_domain_server_ip }}'
- name: test gather vultr dns domain facts in check mode
vultr_dns_domain_facts:
check_mode: yes
- name: verify test gather vultr dns domain facts in check mode
assert:
that:
- ansible_facts.vultr_dns_domain_facts|selectattr('domain','equalto','{{ dns_domain_name }}') | list | count == 1
- name: test gather vultr dns domain facts
vultr_dns_domain_facts:
- name: verify test gather vultr dns domain facts
assert:
that:
- ansible_facts.vultr_dns_domain_facts|selectattr('domain','equalto','{{ dns_domain_name }}') | list | count == 1
- name: Delete the record
vultr_dns_domain:
name: '{{ dns_domain_name }}'
server_ip: '{{ dns_domain_server_ip }}'
state: absent

@ -0,0 +1,32 @@
# 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: Create the record
vultr_dns_domain:
name: '{{ dns_domain_name }}'
server_ip: '{{ dns_domain_server_ip }}'
- name: test gather vultr dns domain info in check mode
vultr_dns_domain_info:
check_mode: yes
register: result
- name: verify test gather vultr dns domain info in check mode
assert:
that:
- result.vultr_dns_domain_info|selectattr('domain','equalto','{{ dns_domain_name }}') | list | count == 1
- name: test gather vultr dns domain info
vultr_dns_domain_info:
register: result
- name: verify test gather vultr dns domain info
assert:
that:
- result.vultr_dns_domain_info|selectattr('domain','equalto','{{ dns_domain_name }}') | list | count == 1
- name: Delete the record
vultr_dns_domain:
name: '{{ dns_domain_name }}'
server_ip: '{{ dns_domain_server_ip }}'
state: absent

@ -1,31 +0,0 @@
# 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 firewall group facts - empty resources
vultr_firewall_group_facts:
- name: Create the firewall group
vultr_firewall_group:
name: '{{ firewall_group_name }}'
- name: test gather vultr firewall group facts in check mode
vultr_firewall_group_facts:
check_mode: yes
- name: verify test gather vultr firewall group facts in check mode
assert:
that:
- ansible_facts.vultr_firewall_group_facts|selectattr('description','equalto','{{ firewall_group_name }}') | list | count == 1
- name: test gather vultr firewall group facts
vultr_firewall_group_facts:
- name: verify test gather vultr firewall group facts
assert:
that:
- ansible_facts.vultr_firewall_group_facts|selectattr('description','equalto','{{ firewall_group_name }}') | list | count == 1
- name: Delete the firewall group
vultr_firewall_group:
name: '{{ firewall_group_name }}'
state: absent

@ -0,0 +1,33 @@
# 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 firewall group info - empty resources
vultr_firewall_group_info:
- name: Create the firewall group
vultr_firewall_group:
name: '{{ firewall_group_name }}'
- name: test gather vultr firewall group info in check mode
vultr_firewall_group_info:
check_mode: yes
register: result
- name: verify test gather vultr firewall group info in check mode
assert:
that:
- result.vultr_firewall_group_info|selectattr('description','equalto','{{ firewall_group_name }}') | list | count == 1
- name: test gather vultr firewall group info
vultr_firewall_group_info:
register: result
- name: verify test gather vultr firewall group info
assert:
that:
- result.vultr_firewall_group_info|selectattr('description','equalto','{{ firewall_group_name }}') | list | count == 1
- name: Delete the firewall group
vultr_firewall_group:
name: '{{ firewall_group_name }}'
state: absent

@ -1,33 +0,0 @@
# 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 network facts - empty resources
vultr_network_facts:
- name: Create the network
vultr_network:
name: '{{ vultr_network_name }}'
cidr: '{{ vultr_network_cidr }}'
region: '{{ vultr_network_region }}'
- name: test gather vultr network facts in check mode
vultr_network_facts:
check_mode: yes
- name: verify test gather vultr network facts in check mode
assert:
that:
- ansible_facts.vultr_network_facts|selectattr('name','equalto','{{ vultr_network_name }}') | list | count == 1
- name: test gather vultr network facts
vultr_network_facts:
- name: verify test gather vultr network facts
assert:
that:
- ansible_facts.vultr_network_facts|selectattr('name','equalto','{{ vultr_network_name }}') | list | count == 1
- name: Delete the script
vultr_network:
name: '{{ vultr_network_name }}'
state: absent

@ -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 network info - empty resources
vultr_network_info:
- name: Create the network
vultr_network:
name: '{{ vultr_network_name }}'
cidr: '{{ vultr_network_cidr }}'
region: '{{ vultr_network_region }}'
- name: test gather vultr network info in check mode
vultr_network_info:
check_mode: yes
register: result
- name: verify test gather vultr network info in check mode
assert:
that:
- result.vultr_network_info|selectattr('name','equalto','{{ vultr_network_name }}') | list | count == 1
- name: test gather vultr network info
vultr_network_info:
register: result
- name: verify test gather vultr network info
assert:
that:
- result.vultr_network_info|selectattr('name','equalto','{{ vultr_network_name }}') | list | count == 1
- name: Delete the script
vultr_network:
name: '{{ vultr_network_name }}'
state: absent

@ -1,19 +0,0 @@
# 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 plan facts in check mode
vultr_plan_facts:
check_mode: yes
- name: verify test gather vultr plan facts in check mode
assert:
that:
- ansible_facts.vultr_plan_facts|selectattr('name','equalto','16384 MB RAM,2x110 GB SSD,20.00 TB BW') | list | count == 1
- name: test gather vultr plan fact
vultr_plan_facts:
- name: verify test gather vultr plan facts
assert:
that:
- ansible_facts.vultr_plan_facts|selectattr('name','equalto','16384 MB RAM,2x110 GB SSD,20.00 TB BW') | list | count == 1

@ -0,0 +1,21 @@
# 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 plan info in check mode
vultr_plan_info:
check_mode: yes
register: result
- name: verify test gather vultr plan info in check mode
assert:
that:
- result.vultr_plan_info|selectattr('name','equalto','16384 MB RAM,2x110 GB SSD,20.00 TB BW') | list | count == 1
- name: test gather vultr plan info
vultr_plan_info:
register: result
- name: verify test gather vultr plan info
assert:
that:
- result.vultr_plan_info|selectattr('name','equalto','16384 MB RAM,2x110 GB SSD,20.00 TB BW') | list | count == 1

@ -1,19 +0,0 @@
# 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 region facts in check mode
vultr_region_facts:
check_mode: yes
- name: verify test gather vultr region facts in check mode
assert:
that:
- ansible_facts.vultr_region_facts|selectattr('name','equalto','Atlanta') | list | count == 1
- name: test gather vultr region facts
vultr_region_facts:
- name: verify test gather vultr region facts
assert:
that:
- ansible_facts.vultr_region_facts|selectattr('name','equalto','Atlanta') | list | count == 1

@ -0,0 +1,21 @@
# 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 region info in check mode
vultr_region_info:
check_mode: yes
register: result
- name: verify test gather vultr region info in check mode
assert:
that:
- result.vultr_region_info|selectattr('name','equalto','Atlanta') | list | count == 1
- name: test gather vultr region info
vultr_region_info:
register: result
- name: verify test gather vultr region info
assert:
that:
- result.vultr_region_info|selectattr('name','equalto','Atlanta') | list | count == 1

@ -12,16 +12,17 @@
wait_for:
when: result is changed
- name: test gather vultr server facts - empty resources
vultr_server_facts:
- name: verify test gather vultr server facts - empty resources
- name: test gather vultr server info - empty resources
vultr_server_info:
register: result
- name: verify test gather vultr server info - empty resources
assert:
that:
- ansible_facts.vultr_server_facts | selectattr('name','equalto',vultr_server_name) | list | count == 0
- result.vultr_server_info | selectattr('name','equalto',vultr_server_name) | list | count == 0
- name: setup firewall group
vultr_firewall_group:
name: test_vultr_server_facts
name: test_vultr_server_info
- name: setup create the server
vultr_server:
@ -29,24 +30,26 @@
os: '{{ vultr_server_os }}'
plan: '{{ vultr_server_plan }}'
region: '{{ vultr_server_region }}'
firewall_group: test_vultr_server_facts
firewall_group: test_vultr_server_info
- name: test gather vultr server facts in check mode
vultr_server_facts:
- name: test gather vultr server info in check mode
vultr_server_info:
check_mode: yes
register: result
- name: verify test gather vultr server facts in check mode
- name: verify test gather vultr server info in check mode
assert:
that:
- ansible_facts.vultr_server_facts|selectattr('name','equalto',vultr_server_name) | list | count == 1
- result.vultr_server_info|selectattr('name','equalto',vultr_server_name) | list | count == 1
- name: test gather vultr server facts
vultr_server_facts:
- name: test gather vultr server info
vultr_server_info:
register: result
- name: verify test gather vultr server facts
- name: verify test gather vultr server info
assert:
that:
- ansible_facts.vultr_server_facts|selectattr('name','equalto',vultr_server_name) | list | count == 1
- result.vultr_server_info|selectattr('name','equalto',vultr_server_name) | list | count == 1
- name: Pause for 5 min before deleting the VM
pause:
@ -59,5 +62,5 @@
- name: cleanup firewall group
vultr_firewall_group:
name: test_vultr_server_facts
name: test_vultr_server_info
state: absent

@ -1,33 +0,0 @@
# 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 facts - empty resources
vultr_startup_script_facts:
- name: Create the script
vultr_startup_script:
name: '{{ startup_script_name }}'
script_type: '{{ startup_script_type }}'
script: '{{ startup_script_content }}'
- name: test gather vultr startup script facts in check mode
vultr_startup_script_facts:
check_mode: yes
- name: verify test gather vultr startup script facts in check mode
assert:
that:
- ansible_facts.vultr_startup_script_facts|selectattr('name','equalto','{{ startup_script_name }}') | list | count == 1
- name: test gather vultr startup script facts
vultr_startup_script_facts:
- name: verify test gather vultr startup script facts
assert:
that:
- ansible_facts.vultr_startup_script_facts|selectattr('name','equalto','{{ startup_script_name }}') | list | count == 1
- name: Delete the script
vultr_startup_script:
name: '{{ startup_script_name }}'
state: absent

@ -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_startup_script_info:
- name: Create the script
vultr_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_startup_script_info:
check_mode: yes
register: result
- name: verify test gather vultr startup script info in check mode
assert:
that:
- result.vultr_startup_script_info|selectattr('name','equalto','{{ startup_script_name }}') | list | count == 1
- name: test gather vultr startup script info
vultr_startup_script_info:
register: result
- name: verify test gather vultr startup script info
assert:
that:
- result.vultr_startup_script_info|selectattr('name','equalto','{{ startup_script_name }}') | list | count == 1
- name: Delete the script
vultr_startup_script:
name: '{{ startup_script_name }}'
state: absent
Loading…
Cancel
Save