From 64139e616d4a4d063d51fb40daedd4bf6cb77dfb Mon Sep 17 00:00:00 2001 From: Tomas Karasek Date: Tue, 25 Apr 2023 18:22:26 +0200 Subject: [PATCH 1/7] Improvements in docs generating --- Makefile | 14 +- README.md | 9 +- docs/inventory/metal_device.md | 72 ----- docs/inventory/metal_device.rst | 150 +++++++++ docs/modules/metal_reserved_ip_block_info.md | 16 +- plugins/inventory/metal_device.py | 91 +----- plugins/modules/metal_available_ips_info.py | 39 ++- plugins/modules/metal_device.py | 292 +++++++++++++++++- plugins/modules/metal_device_info.py | 131 +++++++- plugins/modules/metal_ip_assignment.py | 82 ++++- plugins/modules/metal_ip_assignment_info.py | 52 +++- plugins/modules/metal_project.py | 10 +- plugins/modules/metal_project_info.py | 12 +- plugins/modules/metal_reserved_ip_block.py | 107 ++++++- .../modules/metal_reserved_ip_block_info.py | 80 ++++- requirements.txt | 3 +- scripts/render_readme.py | 1 - scripts/specdoc_generate.sh | 12 +- scripts/specdoc_inject.sh | 20 +- scripts/specdoc_remove.sh | 1 + template/README.template.md | 9 +- template/module.rst.j2 | 183 +++++++++++ 22 files changed, 1145 insertions(+), 241 deletions(-) delete mode 100644 docs/inventory/metal_device.md create mode 100644 docs/inventory/metal_device.rst create mode 120000 scripts/specdoc_remove.sh create mode 100644 template/module.rst.j2 diff --git a/Makefile b/Makefile index 40b0627..d6f726c 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ SHELL := /bin/bash COLLECTIONS_PATH ?= ~/.ansible/collections DOCS_PATH ?= docs -COLLECTION_VERSION ?= 0.0.1 +COLLECTION_VERSION ?= TEST_ARGS := -v INTEGRATION_CONFIG := tests/integration/integration_config.yml @@ -32,17 +32,21 @@ lint: mypy plugins/inventory .PHONY: docs -docs: +docs: inject-module-docs rm -rf $(DOCS_PATH)/modules $(DOCS_PATH)/inventory mkdir -p $(DOCS_PATH)/modules $(DOCS_PATH)/inventory DOCS_PATH=$(DOCS_PATH) ./scripts/specdoc_generate.sh python scripts/render_readme.py ${COLLECTION_VERSION} - #ansible-doc-extractor --template=template/module.rst.j2 $(DOCS_PATH)/inventory plugins/inventory/*.py + ansible-doc-extractor --template=template/module.rst.j2 $(DOCS_PATH)/inventory plugins/inventory/metal_device.py -.PHONY: injected-docs -injected-docs: +.PHONY: inject-module-docs +inject-module-docs: DOCS_PATH=$(DOCS_PATH) ./scripts/specdoc_inject.sh +.PHONY: remove-module-docs +remove-module-docs: + DOCS_PATH=$(DOCS_PATH) ./scripts/specdoc_remove.sh + test: integration-test testall: create-integration-config diff --git a/README.md b/README.md index 7b2c941..1334510 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ Dynamically add Equinix infrastructure to an Ansible inventory. Name | --- | -[equinix.cloud.metal_device](https://github.com/equinix-labs/ansible-collection-equinix/blob/0.0.1/docs/inventory/metal_device.md)| +[equinix.cloud.metal_device](./docs/inventory/metal_device.rst)| @@ -69,11 +69,12 @@ pip install -r https://raw.githubusercontent.com/equinix-labs/ansible-collection ## Usage Once the Equinix Ansible collection is installed, it can be referenced by its [Fully Qualified Collection Namespace (FQCN)](https://github.com/ansible-collections/overview#terminology): `equinix.cloud.module_name`. -In order to use this collection, you should have account in the relevant Equinix service. For example you should have an account Equinix Metal to use the `metal_*` plugins. +In order to use this collection, you should have account in the relevant Equinix service. For example you should have an account in Equinix Metal to use the `metal_*` modules. -You can authenticate either by exporting auth tokens as environment variables, or by supplying `*_api_token` attributes to modules. For example, to use `metal_device`, you can export `METAL_AUTH_TOKEN` (or `METAL_API_TOKEN`), or you can supply `metal_auth_token` attribute. +You can authenticate either by exporting auth token as environment variables, or by supplying `*_api_token` attributes to modules. For example, to use `metal_device`, you can export `METAL_AUTH_TOKEN`, or you can supply `metal_api_token` attribute. + +### Example Playbook -#### Example Playbook ```yaml --- - name: create Equinix Metal device diff --git a/docs/inventory/metal_device.md b/docs/inventory/metal_device.md deleted file mode 100644 index d6707e0..0000000 --- a/docs/inventory/metal_device.md +++ /dev/null @@ -1,72 +0,0 @@ -# metal_device - -Reads device inventories from Equinix Metal. Uses YAML configuration file that ends with equinix_metal.(yml|yaml). ansible_host is set to first public IP address of the device. - - -- [Examples](#examples) -- [Parameters](#parameters) -- [Return Values](#return-values) - -## Examples - -```yaml -# Minimal example using environment var credentials -plugin: equinix.cloud.metal_device - -# Example using constructed features to create groups and set ansible_host -plugin: equinix.cloud.metal_device -# keyed_groups may be used to create custom groups -strict: False -keyed_groups: - # Add devices to tag_Name groups for each tag - - prefix: tag - key: tags - # Add devices to e.g. equinix_metal_plan_c3_small_x86 - - prefix: equinix_metal_plan - key: plan - # Create a group per region e.g. equinix_metal_metro_sv - - key: metro - prefix: equinix_metal_metro - # Create a group per device state e.g. equinix_metal_state_active - - key: state - prefix: equinix_metal_state - -``` - - - - - - - - - - -## Parameters - -| Field | Type | Required | Description | -|-----------|------|----------|------------------------------------------------------------------------------| -| `plugin` |
`str`
|
**Required**
| Token that ensures this is a source file for the plugin. **(Choices: `equinix_metal`, `equinix.cloud.metal_device`)** | -| `metal_api_token` |
`str`
|
**Required**
| Equinix Metal API token. Can also be specified via METAL_AUTH_TOKEN environment variable. | -| `project_ids` |
`list`
|
Optional
| List of Equinix Metal project IDs to query for devices. | -| [`keyed_groups` (sub-options)](#keyed_groups) |
`list`
|
Optional
| List of groups to create based on the values of a variable. | - - - - - -### keyed_groups - -| Field | Type | Required | Description | -|-----------|------|----------|------------------------------------------------------------------------------| -| `key` |
`str`
|
Optional
| The key to group by. | -| `prefix` |
`str`
|
Optional
| Prefix to prepend to the group name. | -| `separator` |
`str`
|
Optional
| Separator to use when joining the key and value. | - - - - - - -## Return Values - diff --git a/docs/inventory/metal_device.rst b/docs/inventory/metal_device.rst new file mode 100644 index 0000000..5bf18b0 --- /dev/null +++ b/docs/inventory/metal_device.rst @@ -0,0 +1,150 @@ +.. _metal_device_module: + + +metal_device -- Equinix Metal Device inventory source +===================================================== + +.. contents:: + :local: + :depth: 1 + + +Synopsis +-------- + +Reads device inventories from Equinix Metal. Uses YAML configuration file that ends with equinix_metal.(yml|yaml). ansible_host is set to first public IP address of the device. + + + +Requirements +------------ +The below requirements are needed on the host that executes this module. + +- python >= 3 +- metal_python >= 0.0.1 + + + +Parameters +---------- + + **plugin (Required, type=str):** + \• Token that ensures this is a source file for the plugin. + + \• Options: `equinix_metal`, `equinix.cloud.metal_device` + + + **metal_api_token (Required, type=str):** + \• Equinix Metal API token. Can also be specified via METAL_API_TOKEN environment variable. + + + + **project_ids (type=list):** + \• List of Equinix Metal project IDs to query for devices. + + + **strict (type=bool):** + \• If ``yes`` make invalid entries a fatal error, otherwise skip and continue. + + \• Since it is possible to use facts in the expressions they might not always be available and we ignore those errors by default. + + + **compose (type=dict):** + \• Create vars from jinja2 expressions. + + + **groups (type=dict):** + \• Add hosts to group based on Jinja2 conditionals. + + + **keyed_groups (type=list):** + \• Add hosts to group based on the values of a variable. + + + **parent_group (type=str):** + \• parent group for keyed group + + + **prefix (type=str):** + \• A keyed group name will start with this prefix + + + **separator (type=str, default=_):** + \• separator used to build the keyed group name + + + **key (type=str):** + \• The key from input dictionary used to generate groups + + + **default_value (type=str):** + \• The default value when the host variable's value is an empty string. + + \• This option is mutually exclusive with ``trailing_separator``. + + + **trailing_separator (type=bool, default=True):** + \• Set this option to *False* to omit the ``separator`` after the host variable when the value is an empty string. + + \• This option is mutually exclusive with ``default_value``. + + + + **use_extra_vars (type=bool):** + \• Merge extra vars into the available variables for composition (highest precedence). + + + **leading_separator (type=boolean, default=True):** + \• Use in conjunction with keyed_groups. + + \• By default, a keyed group that does not have a prefix or a separator provided will have a name that starts with an underscore. + + \• This is because the default prefix is "" and the default separator is "_". + + \• Set this option to False to omit the leading underscore (or other separator) if no prefix is given. + + \• If the group name is derived from a mapping the separator is still used to concatenate the items. + + \• To not use a separator in the group name at all, set the separator for the keyed group to an empty string instead. + + + + + + + +Examples +-------- + +.. code-block:: yaml+jinja + + + plugin: equinix.cloud.metal_device + strict: false + keyed_groups: + - prefix: tag + key: tags + - prefix: equinix_metal_plan + key: plan + - key: metro + prefix: equinix_metal_metro + - key: state + prefix: equinix_metal_state + + + + + + +Status +------ + + + + + +Authors +~~~~~~~ + +- Equinix DevRel Team (@equinix) + diff --git a/docs/modules/metal_reserved_ip_block_info.md b/docs/modules/metal_reserved_ip_block_info.md index 27092de..0e58f22 100644 --- a/docs/modules/metal_reserved_ip_block_info.md +++ b/docs/modules/metal_reserved_ip_block_info.md @@ -1,6 +1,6 @@ # metal_reserved_ip_block_info -Gatehr list of reserved IP blocks matching the specified criteria +Gather list of reserved IP blocks matching the specified criteria - [Examples](#examples) @@ -13,9 +13,9 @@ Gatehr list of reserved IP blocks matching the specified criteria - name: Gather list of public_ipv4 reserved_ip_blocks in a project hosts: localhost tasks: - - equinix.cloud.metal_reserved_ip_block_info - type: public_ipv4 - project_id: 2a5122b9-c323-4d5c-b53c-9ad3f54273e7 + - equinix.cloud.metal_reserved_ip_block_info: + type: public_ipv4 + project_id: 2a5122b9-c323-4d5c-b53c-9ad3f54273e7 ``` @@ -23,10 +23,10 @@ Gatehr list of reserved IP blocks matching the specified criteria - name: Gather list of public_ipv6 reserved_ip_blocks in a project in metro ams hosts: localhost tasks: - equinix.cloud.metal_reserved_ip_block_info - type: public_ipv6 - project_id: 2a5122b9-c323-4d5c-b53c-9ad3f54273e7 - metro: ams + - equinix.cloud.metal_reserved_ip_block_info: + type: public_ipv6 + project_id: 2a5122b9-c323-4d5c-b53c-9ad3f54273e7 + metro: ams ``` diff --git a/plugins/inventory/metal_device.py b/plugins/inventory/metal_device.py index ea37670..70fd1a3 100644 --- a/plugins/inventory/metal_device.py +++ b/plugins/inventory/metal_device.py @@ -3,14 +3,6 @@ # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) -from ansible_specdoc.objects import ( - SpecField, - FieldType, -) - -from ansible_collections.equinix.cloud.plugins.module_utils.equinix import ( - getSpecDocMeta, -) import os from typing import List, Dict, Any @@ -60,100 +52,23 @@ - metal_python >= 0.0.1 short_description: Equinix Metal Device inventory source ''' + EXAMPLES = ''' plugin: equinix.cloud.metal_device strict: false keyed_groups: -- prefix: tag - key: tags -- prefix: equinix_metal_plan - key: plan -- key: metro - prefix: equinix_metal_metro -- key: state - prefix: equinix_metal_state -''' -RETURN = ''' -{} -''' - -module_spec = dict( - plugin=SpecField( - type=FieldType.string, - description=['Token that ensures this is a source file for the plugin.'], - choices=['equinix_metal', 'equinix.cloud.metal_device'], - required=True, - ), - project_ids=SpecField( - type=FieldType.list, - description=['List of Equinix Metal project IDs to query for devices.'], - element_type=FieldType.string, - ), - metal_api_token=SpecField( - type=FieldType.string, - description=['Equinix Metal API token. Can also be specified via METAL_AUTH_TOKEN environment variable.'], - required=True, - ), - keyed_groups=SpecField( - type=FieldType.list, - description=['List of groups to create based on the values of a variable.'], - element_type=FieldType.dict, - suboptions=dict( - key=SpecField( - type=FieldType.string, - description=['The key to group by.'], - ), - prefix=SpecField( - type=FieldType.string, - description=['Prefix to prepend to the group name.'], - ), - separator=SpecField( - type=FieldType.string, - description=['Separator to use when joining the key and value.'], - default='', - ), - ), - ), -) - - -specdoc_examples = [ - ''' -# Minimal example using environment var credentials -plugin: equinix.cloud.metal_device - -# Example using constructed features to create groups and set ansible_host -plugin: equinix.cloud.metal_device -# keyed_groups may be used to create custom groups -strict: False -keyed_groups: - # Add devices to tag_Name groups for each tag - prefix: tag key: tags - # Add devices to e.g. equinix_metal_plan_c3_small_x86 - prefix: equinix_metal_plan key: plan - # Create a group per region e.g. equinix_metal_metro_sv - key: metro prefix: equinix_metal_metro - # Create a group per device state e.g. equinix_metal_state_active - key: state prefix: equinix_metal_state ''' - ] - -SPECDOC_META = getSpecDocMeta( - short_description='Equinix Metal Device inventory source', - description=( - "Reads device inventories from Equinix Metal. " - "Uses YAML configuration file that ends with equinix_metal.(yml|yaml). " - "ansible_host is set to first public IP address of the device." - ), - examples=specdoc_examples, - options=module_spec, - return_values={}, -) +RETURN = ''' +''' EXCLUDE_ATTRIBUTES = [ "ssh_keys", diff --git a/plugins/modules/metal_available_ips_info.py b/plugins/modules/metal_available_ips_info.py index 45ccac2..a56567d 100644 --- a/plugins/modules/metal_available_ips_info.py +++ b/plugins/modules/metal_available_ips_info.py @@ -3,9 +3,42 @@ # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) -DOCUMENTATION = "" -EXAMPLES = "" -RETURN = "" +DOCUMENTATION = ''' +author: Equinix DevRel Team (@equinix) +description: Get list of avialable IP addresses from a reserved IP block +module: metal_available_ips_info +notes: [] +options: + cidr: + description: + - CIDR of the reserved IP block to list available IPs for. + required: false + type: str + reserved_ip_block_id: + description: + - UUID of the reserved IP block to list available IPs for. + required: true + type: str +requirements: +- python >= 3 +- equinix_metal >= 0.0.1 +short_description: Get list of avialable IP addresses from a reserved IP block +''' +EXAMPLES = ''' +name: available addresses from reservation +equinix.cloud.metal_available_ips_info: + reserved_ip_block_id: '{{ ip_reservation.id }}' + cidr: 32 + register: available_ips +''' +RETURN = ''' +available: + description: Available IP addresses from the reservation. + returned: always + sample: + - "\n{\n \"available\": [\n \"147.75.71.192/32\"\n ],\n}\n" + type: dict +''' from ansible.module_utils._text import to_native import traceback diff --git a/plugins/modules/metal_device.py b/plugins/modules/metal_device.py index 1338cce..9534bb8 100644 --- a/plugins/modules/metal_device.py +++ b/plugins/modules/metal_device.py @@ -5,9 +5,295 @@ from __future__ import absolute_import, division, print_function -DOCUMENTATION = "" -EXAMPLES = "" -RETURN = "" +DOCUMENTATION = ''' +author: Equinix DevRel Team (@equinix) +description: Create, update, or delete Equinix Metal devices +module: metal_device +notes: [] +options: + always_pxe: + description: !!python/tuple + - When true, devices with a `custom_ipxe` OS will always boot into iPXE. The default + setting of false will ensure that iPXE is only used on first boot. + required: false + type: bool + billing_cycle: + choices: + - hourly + - daily + - monthly + - yearly + description: + - Billing cycle of the device. + required: false + type: str + customdata: + description: + - Customdata is an arbitrary JSON value that can be accessed via the metadata + service. + required: false + type: dict + facility: + description: + - Facility of the device. + required: false + type: str + features: + description: + - 'The features attribute allows you to optionally specify what features your + server should have. In the API shorthand syntax, all features listed are `required` + ` { "features": ["tpm"] } ` Alternatively, if you do not require a certain feature, + but would prefer to be assigned a server with that feature if there are any + available, you may specify that feature with a `preferred` value. The request + will not fail if we have no servers with that feature in our inventory. The + API offers an alternative syntax for mixing preferred and required features + ` { "features": { "tpm": "required", "raid": "preferred" } } ` The request will + only fail if there are no available servers matching the required `tpm` criteria. ' + elements: str + required: false + type: list + hardware_reservation_id: + description: + - The Hardware Reservation UUID to provision. Alternatively, `next-available` + can be specified to select from any of the available hardware reservations. + An error will be returned if the requested reservation option is not available. + See [Reserved Hardware](https://metal.equinix.com/developers/docs/deploy/reserved/) + for more details. + required: false + type: str + hostname: + description: + - Hostname to use within the operating system. The same hostname may be used on + multiple devices within a project. + required: false + type: str + id: + description: + - UUID of the device. + required: false + type: str + ip_addresses: + description: + - 'The `ip_addresses` attribute will allow you to specify the addresses you want + created with your device.The default value configures public IPv4, public IPv6, + and private IPv4. Private IPv4 address is required. When specifying `ip_addresses`, + one of the array items must enable private IPv4. Some operating systems require + public IPv4 address. In those cases you will receive an error message if public + IPv4 is not enabled. For example, to only configure your server with a private + IPv4 address, you can send `{ "ip_addresses": [{ "address_family": 4, "public": + false }] }`. It is possible to request a subnet size larger than a `/30` by + assigning addresses using the UUID(s) of ip_reservations in your project. For + example, `{ "ip_addresses": [..., {"address_family": 4, "public": true, "ip_reservations": + ["uuid1", "uuid2"]}] }` To access a server without public IPs, you can use our + Out-of-Band console access (SOS) or proxy through another server in the project + with public IPs enabled. default is `[{''address_family'': 4, ''public'': True}, + {''address_family'': 4, ''public'': False}, {''address_family'': 6, ''public'': + True}]`' + elements: dict + required: false + suboptions: + address: + description: + - IP address. + required: false + type: str + address_family: + description: + - IP address family. + required: false + type: int + public: + description: + - Whether the IP address is public. + required: false + type: bool + type: list + ipxe_script_url: + description: + - When set, the device will chainload an iPXE Script at boot fetched from the + supplied URL. See [Custom iPXE](https://metal.equinix.com/developers/docs/operating-systems/custom-ipxe/) + for more details. + required: false + type: str + locked: + description: + - Whether the device is locked, preventing accidental deletion. + required: false + type: bool + metro: + description: + - Metro of the device. + required: false + type: str + network_frozen: + description: + - Whether the device network should be frozen, preventing any changes to the network + configuration. + required: false + type: bool + no_ssh_keys: + description: + - Overrides default behaviour of attaching all of the organization members ssh + keys and project ssh keys to device if no specific keys specified. + required: false + type: bool + operating_system: + description: + - Operating system of the device. + required: false + type: str + plan: + description: + - Plan of the device. + required: false + type: str + project_id: + description: + - Project id of the device. + required: false + type: str + project_ssh_keys: + description: + - A list of UUIDs identifying the device parent project that should be authorized + to access this device (typically via /root/.ssh/authorized_keys). These keys + will also appear in the device metadata. If no SSH keys are specified (`user_ssh_keys`, + `project_ssh_keys`, and `ssh_keys` are all empty lists or omitted), all parent + project keys, parent project members keys and organization members keys will + be included. This behaviour can be changed with 'no_ssh_keys' option to omit + any SSH key being added. + elements: str + required: false + type: list + provisioning_wait_seconds: + default: 300 + description: + - How long should the module wait for the device to be provisionedi, in seconds. + required: false + type: int + public_ipv4_subnet_size: + description: + - 'Deprecated. Use ip_addresses. Subnet range for addresses allocated to this + device. Your project must have addresses available for a non-default request. + If not specified, the default is a /31 for IPv4 and a /127 for IPv6. ' + required: false + type: int + spot_instance: + description: + - 'Create a spot instance. Spot instances are created with a maximum bid price. + If the bid price is not met, the spot instance will be terminated as indicated + by the `termination_time` field. ' + required: false + type: bool + spot_price_max: + description: + - 'Maximum bid price for a spot instance. If the bid price is not met, the spot + instance will be terminated as indicated by the `termination_time` field. ' + required: false + type: float + ssh_keys: + description: + - A list of UUIDs identifying SSH keys that should be authorized to access this + device (typically via /root/.ssh/authorized_keys). These keys will also appear + in the device metadata. If no SSH keys are specified (`user_ssh_keys`, `project_ssh_keys`, + and `ssh_keys` are all empty lists or omitted), all parent project keys, parent + project members keys and organization members keys will be included. This behaviour + can be changed with 'no_ssh_keys' option to omit any SSH key being added. + elements: str + required: false + type: list + tags: + description: + - A list of tags to assign to the device. + elements: str + required: false + type: list + termination_time: + description: + - Time at which the spot instance will be terminated. + required: false + type: str + user_ssh_keys: + description: + - A list of UUIDs identifying the device parent user that should be authorized + to access this device (typically via /root/.ssh/authorized_keys). These keys + will also appear in the device metadata. If no SSH keys are specified (`user_ssh_keys`, + `project_ssh_keys`, and `ssh_keys` are all empty lists or omitted), all parent + project keys, parent project members keys and organization members keys will + be included. This behaviour can be changed with 'no_ssh_keys' option to omit + any SSH key being added. + required: false + type: list + userdata: + description: + - The userdata presented in the metadata service for this device. Userdata is + fetched and interpreted by the operating system installed on the device. Acceptable + formats are determined by the operating system, with the exception of a special + iPXE enabling syntax which is handled before the operating system starts. See + [Server User Data](https://metal.equinix.com/developers/docs/servers/user-data/) + and [Provisioning with Custom iPXE] (https://metal.equinix.com/developers/docs/operating-systems/custom-ipxe/#provisioning-with-custom-ipxe) + for more details. + required: false + type: str +requirements: +- python >= 3 +- equinix_metal >= 0.0.1 +short_description: Create, update, or delete Equinix Metal devices +''' +EXAMPLES = ''' +- name: Create new device in a project + hosts: localhost + tasks: + equinix.cloud.metal_device: + name: new device + project_id: 8e4b0b2a-4a6f-4d3b-9c6c-7a0b3c4d5e6f +- name: Remove device by id + hosts: localhost + tasks: + equinix.cloud.metal_device: + id: eef49903-7a09-4ca1-af67-4087c29ab5b6 + state: absent +''' +RETURN = ''' +metal_device: + description: The module object + returned: always + sample: + - "\n{\n \"always_pxe\": false,\n \"billing_cycle\": \"hourly\",\n \"changed\"\ + : true,\n \"customdata\": {},\n \"facility\": \"sv15\",\n \"hardware_reservation_id\"\ + : \"\",\n \"hostname\": \"ansible-integration-test-device-yi4fbuo4-dev1\",\n\ + \ \"id\": \"71a90c54-e0eb-414f-9ea2-9c39ecb32319\",\n \"ip_addresses\":\ + \ [\n {\n \"address\": \"139.178.94.207\",\n \"address_family\"\ + : 4,\n \"public\": true\n },\n {\n \"address\"\ + : \"2604:1380:45e3:2c00::1\",\n \"address_family\": 6,\n \ + \ \"public\": true\n },\n {\n \"address\": \"10.67.168.2\"\ + ,\n \"address_family\": 4,\n \"public\": false\n \ + \ }\n ],\n \"ipxe_script_url\": \"\",\n \"locked\": false,\n \"metal_state\"\ + : \"active\",\n \"metro\": \"sv\",\n \"operating_system\": \"ubuntu_20_04\"\ + ,\n \"plan\": \"c3.small.x86\",\n \"project_id\": \"6ac17ea6-a304-4b01-a1f3-f13a7371cfab\"\ + ,\n \"spot_instance\": false,\n \"spot_price_max\": 0.0,\n \"ssh_keys\"\ + : [\n {\n \"href\": \"/metal/v1/ssh-keys/1ffe4e4b-eaf9-45d9-a268-0d81af71ae55\"\ + ,\n \"id\": \"1ffe4e4b-eaf9-45d9-a268-0d81af71ae55\"\n },\n\ + \ {\n \"href\": \"/metal/v1/ssh-keys/d122d4e4-4832-41c8-abbb-40182930becf\"\ + ,\n \"id\": \"d122d4e4-4832-41c8-abbb-40182930becf\"\n },\n\ + \ {\n \"href\": \"/metal/v1/ssh-keys/b0f196c0-9cf2-4cb7-96c5-403b81ff6813\"\ + ,\n \"id\": \"b0f196c0-9cf2-4cb7-96c5-403b81ff6813\"\n },\n\ + \ {\n \"href\": \"/metal/v1/ssh-keys/4b011c75-e642-4f6d-85f4-590a5956ad28\"\ + ,\n \"id\": \"4b011c75-e642-4f6d-85f4-590a5956ad28\"\n },\n\ + \ {\n \"href\": \"/metal/v1/ssh-keys/217ff08c-057a-4933-8efe-2e9f723fbb5f\"\ + ,\n \"id\": \"217ff08c-057a-4933-8efe-2e9f723fbb5f\"\n },\n\ + \ {\n \"href\": \"/metal/v1/ssh-keys/10968e80-b234-469b-acb8-c5002b4111a4\"\ + ,\n \"id\": \"10968e80-b234-469b-acb8-c5002b4111a4\"\n },\n\ + \ {\n \"href\": \"/metal/v1/ssh-keys/6ff0810b-135c-48cf-ac68-b365bdfd338c\"\ + ,\n \"id\": \"6ff0810b-135c-48cf-ac68-b365bdfd338c\"\n },\n\ + \ {\n \"href\": \"/metal/v1/ssh-keys/6a71d7e1-db14-4dfd-9014-46032b507538\"\ + ,\n \"id\": \"6a71d7e1-db14-4dfd-9014-46032b507538\"\n },\n\ + \ {\n \"href\": \"/metal/v1/ssh-keys/413e2347-f89c-40af-ba9e-0864f2fde990\"\ + ,\n \"id\": \"413e2347-f89c-40af-ba9e-0864f2fde990\"\n },\n\ + \ {\n \"href\": \"/metal/v1/ssh-keys/9308b337-702a-4774-8351-37dfb8c90a57\"\ + ,\n \"id\": \"9308b337-702a-4774-8351-37dfb8c90a57\"\n }\n \ + \ ],\n \"tags\": [],\n \"userdata\": \"\"\n}\n" + type: dict +''' from ansible.module_utils._text import to_native diff --git a/plugins/modules/metal_device_info.py b/plugins/modules/metal_device_info.py index 57d2628..8aa17a2 100644 --- a/plugins/modules/metal_device_info.py +++ b/plugins/modules/metal_device_info.py @@ -6,9 +6,134 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type -DOCUMENTATION = "" -EXAMPLES = "" -RETURN = "" +DOCUMENTATION = ''' +author: Equinix DevRel Team (@equinix) +description: Select list of Equinix Metal devices +module: metal_device_info +notes: [] +options: + hostname: + description: + - Hostname to look up a device. + required: false + type: str + organization_id: + description: + - UUID of the organization containing devices. + required: false + type: str + project_id: + description: + - UUID of the project containing devices. + required: false + type: str +requirements: +- python >= 3 +- equinix_metal >= 0.0.1 +short_description: Select list of Equinix Metal devices +''' +EXAMPLES = ''' +- name: Gather information about all devices + hosts: localhost + tasks: + - equinix.metal.device_info: null +- name: Gather information about devices in a particular project using ID + hosts: localhost + tasks: + - equinix.metal.device_info: + project_id: 173d7f11-f7b9-433e-ac40-f1571a38037a +- name: Gather information about devices in a particular organization using ID + hosts: localhost + tasks: + - equinix.metal.device_info: + organization_id: 173d7f11-f7b9-433e-ac40-f1571a38037a +- name: Gather information about devices with "webserver" in hostname in a project + hosts: localhost + tasks: + - equinix.metal.device_info: + project_id: 173d7f11-f7b9-433e-ac40-f1571a38037a + hostname: webserver +''' +RETURN = ''' +resources: + description: List of devices + returned: always + sample: + - "\n[\n {\n \"always_pxe\": false,\n \"billing_cycle\": \"hourly\"\ + ,\n \"customdata\": {},\n \"facility\": \"sv15\",\n \"hardware_reservation_id\"\ + : \"\",\n \"hostname\": \"ansible-integration-test-device-yi4fbuo4-dev2\"\ + ,\n \"id\": \"6dee3ce4-72f4-4d92-a035-dff5237b2841\",\n \"ip_addresses\"\ + : [\n {\n \"address\": \"147.75.71.193\",\n \ + \ \"address_family\": 4,\n \"public\": true\n \ + \ },\n {\n \"address\": \"2604:1380:45e3:2c00::3\"\ + ,\n \"address_family\": 6,\n \"public\": true\n\ + \ },\n {\n \"address\": \"10.67.168.18\"\ + ,\n \"address_family\": 4,\n \"public\": false\n\ + \ }\n ],\n \"ipxe_script_url\": \"\",\n \"locked\"\ + : false,\n \"metal_state\": \"active\",\n \"metro\": \"sv\",\n \ + \ \"operating_system\": \"ubuntu_20_04\",\n \"plan\": \"c3.small.x86\"\ + ,\n \"project_id\": \"6ac17ea6-a304-4b01-a1f3-f13a7371cfab\",\n \ + \ \"spot_instance\": false,\n \"spot_price_max\": 0.0,\n \"ssh_keys\"\ + : [\n {\n \"href\": \"/metal/v1/ssh-keys/1ffe4e4b-eaf9-45d9-a268-0d81af71ae55\"\ + ,\n \"id\": \"1ffe4e4b-eaf9-45d9-a268-0d81af71ae55\"\n \ + \ },\n {\n \"href\": \"/metal/v1/ssh-keys/d122d4e4-4832-41c8-abbb-40182930becf\"\ + ,\n \"id\": \"d122d4e4-4832-41c8-abbb-40182930becf\"\n \ + \ },\n {\n \"href\": \"/metal/v1/ssh-keys/b0f196c0-9cf2-4cb7-96c5-403b81ff6813\"\ + ,\n \"id\": \"b0f196c0-9cf2-4cb7-96c5-403b81ff6813\"\n \ + \ },\n {\n \"href\": \"/metal/v1/ssh-keys/4b011c75-e642-4f6d-85f4-590a5956ad28\"\ + ,\n \"id\": \"4b011c75-e642-4f6d-85f4-590a5956ad28\"\n \ + \ },\n {\n \"href\": \"/metal/v1/ssh-keys/217ff08c-057a-4933-8efe-2e9f723fbb5f\"\ + ,\n \"id\": \"217ff08c-057a-4933-8efe-2e9f723fbb5f\"\n \ + \ },\n {\n \"href\": \"/metal/v1/ssh-keys/10968e80-b234-469b-acb8-c5002b4111a4\"\ + ,\n \"id\": \"10968e80-b234-469b-acb8-c5002b4111a4\"\n \ + \ },\n {\n \"href\": \"/metal/v1/ssh-keys/6ff0810b-135c-48cf-ac68-b365bdfd338c\"\ + ,\n \"id\": \"6ff0810b-135c-48cf-ac68-b365bdfd338c\"\n \ + \ },\n {\n \"href\": \"/metal/v1/ssh-keys/6a71d7e1-db14-4dfd-9014-46032b507538\"\ + ,\n \"id\": \"6a71d7e1-db14-4dfd-9014-46032b507538\"\n \ + \ },\n {\n \"href\": \"/metal/v1/ssh-keys/413e2347-f89c-40af-ba9e-0864f2fde990\"\ + ,\n \"id\": \"413e2347-f89c-40af-ba9e-0864f2fde990\"\n \ + \ },\n {\n \"href\": \"/metal/v1/ssh-keys/9308b337-702a-4774-8351-37dfb8c90a57\"\ + ,\n \"id\": \"9308b337-702a-4774-8351-37dfb8c90a57\"\n \ + \ }\n ],\n \"tags\": [],\n \"userdata\": \"\"\n },\n\ + \ {\n \"always_pxe\": false,\n \"billing_cycle\": \"hourly\"\ + ,\n \"customdata\": {},\n \"facility\": \"sv15\",\n \"hardware_reservation_id\"\ + : \"\",\n \"hostname\": \"ansible-integration-test-device-yi4fbuo4-dev1\"\ + ,\n \"id\": \"71a90c54-e0eb-414f-9ea2-9c39ecb32319\",\n \"ip_addresses\"\ + : [\n {\n \"address\": \"139.178.94.207\",\n \ + \ \"address_family\": 4,\n \"public\": true\n \ + \ },\n {\n \"address\": \"2604:1380:45e3:2c00::1\"\ + ,\n \"address_family\": 6,\n \"public\": true\n\ + \ },\n {\n \"address\": \"10.67.168.2\",\n\ + \ \"address_family\": 4,\n \"public\": false\n \ + \ }\n ],\n \"ipxe_script_url\": \"\",\n \"locked\"\ + : false,\n \"metal_state\": \"active\",\n \"metro\": \"sv\",\n \ + \ \"operating_system\": \"ubuntu_20_04\",\n \"plan\": \"c3.small.x86\"\ + ,\n \"project_id\": \"6ac17ea6-a304-4b01-a1f3-f13a7371cfab\",\n \ + \ \"spot_instance\": false,\n \"spot_price_max\": 0.0,\n \"ssh_keys\"\ + : [\n {\n \"href\": \"/metal/v1/ssh-keys/1ffe4e4b-eaf9-45d9-a268-0d81af71ae55\"\ + ,\n \"id\": \"1ffe4e4b-eaf9-45d9-a268-0d81af71ae55\"\n \ + \ },\n {\n \"href\": \"/metal/v1/ssh-keys/d122d4e4-4832-41c8-abbb-40182930becf\"\ + ,\n \"id\": \"d122d4e4-4832-41c8-abbb-40182930becf\"\n \ + \ },\n {\n \"href\": \"/metal/v1/ssh-keys/b0f196c0-9cf2-4cb7-96c5-403b81ff6813\"\ + ,\n \"id\": \"b0f196c0-9cf2-4cb7-96c5-403b81ff6813\"\n \ + \ },\n {\n \"href\": \"/metal/v1/ssh-keys/4b011c75-e642-4f6d-85f4-590a5956ad28\"\ + ,\n \"id\": \"4b011c75-e642-4f6d-85f4-590a5956ad28\"\n \ + \ },\n {\n \"href\": \"/metal/v1/ssh-keys/217ff08c-057a-4933-8efe-2e9f723fbb5f\"\ + ,\n \"id\": \"217ff08c-057a-4933-8efe-2e9f723fbb5f\"\n \ + \ },\n {\n \"href\": \"/metal/v1/ssh-keys/10968e80-b234-469b-acb8-c5002b4111a4\"\ + ,\n \"id\": \"10968e80-b234-469b-acb8-c5002b4111a4\"\n \ + \ },\n {\n \"href\": \"/metal/v1/ssh-keys/6ff0810b-135c-48cf-ac68-b365bdfd338c\"\ + ,\n \"id\": \"6ff0810b-135c-48cf-ac68-b365bdfd338c\"\n \ + \ },\n {\n \"href\": \"/metal/v1/ssh-keys/6a71d7e1-db14-4dfd-9014-46032b507538\"\ + ,\n \"id\": \"6a71d7e1-db14-4dfd-9014-46032b507538\"\n \ + \ },\n {\n \"href\": \"/metal/v1/ssh-keys/413e2347-f89c-40af-ba9e-0864f2fde990\"\ + ,\n \"id\": \"413e2347-f89c-40af-ba9e-0864f2fde990\"\n \ + \ },\n {\n \"href\": \"/metal/v1/ssh-keys/9308b337-702a-4774-8351-37dfb8c90a57\"\ + ,\n \"id\": \"9308b337-702a-4774-8351-37dfb8c90a57\"\n \ + \ }\n ],\n \"tags\": [],\n \"userdata\": \"\"\n }\n\ + ]\n" + type: list +''' from ansible.module_utils._text import to_native from ansible_specdoc.objects import SpecField, FieldType, SpecDocMeta, SpecReturnValue diff --git a/plugins/modules/metal_ip_assignment.py b/plugins/modules/metal_ip_assignment.py index af40332..e7697b2 100644 --- a/plugins/modules/metal_ip_assignment.py +++ b/plugins/modules/metal_ip_assignment.py @@ -3,9 +3,85 @@ # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) -DOCUMENTATION = "" -EXAMPLES = "" -RETURN = "" +DOCUMENTATION = ''' +author: Equinix DevRel Team (@equinix) +description: Asign reserved IPs to Equinix Metal devices. +module: metal_ip_assignment +notes: [] +options: + address: + description: + - IP address to assign to the device. + required: false + type: str + customdata: + description: + - Custom data about the ip_assignment to create. + required: false + type: dict + device_id: + description: + - UUID of the device to assign the IP to. + required: false + type: str + id: + description: + - UUID of the ip_assignment. + required: false + type: str + manageable: + description: + - Whether the IP address is manageable. + required: false + type: bool +requirements: +- python >= 3 +- equinix_metal >= 0.0.1 +short_description: Manage Equinix Metal IP assignments +''' +EXAMPLES = ''' +- name: request ip reservation + equinix.cloud.metal_reserved_ip_block: + type: public_ipv4 + metro: sv + quantity: 1 + project_id: '{{ project.id }}' + register: ip_reservation +- name: available addresses from reservation + equinix.cloud.metal_available_ips_info: + reserved_ip_block_id: '{{ ip_reservation.id }}' + cidr: 32 + register: available_ips +- assert: + that: + - available_ips.available | length == 1 +- name: create device + equinix.cloud.metal_device: + project_id: '{{ project.id }}' + hostname: device1 + operating_system: ubuntu_20_04 + plan: c3.small.x86 + metro: sv + state: present + register: device +- name: assign available IP + equinix.cloud.metal_ip_assignment: + device_id: '{{ device.id }}' + address: '{{ available_ips.available[0] }}' + register: assignment +''' +RETURN = ''' +metal_ip_assignment: + description: The assignment object. + returned: always + sample: + - "\n{\n \"address\": \"147.75.71.192/32\",\n \"address_family\": 4,\n \ + \ \"changed\": true,\n \"cidr\": 32,\n \"device_id\": \"a8c5dd81-9f7a-4c70-81c6-a168782931ab\"\ + ,\n \"id\": \"83b5503c-7b7f-4883-9509-b6b728b41491\",\n \"management\":\ + \ false,\n \"metro\": \"sv\",\n \"netmask\": \"255.255.255.255\",\n \"\ + network\": \"147.75.71.192\",\n \"public\": true\n}\n" + type: dict +''' from ansible.module_utils._text import to_native import traceback diff --git a/plugins/modules/metal_ip_assignment_info.py b/plugins/modules/metal_ip_assignment_info.py index 69c61b3..3b2d7cc 100644 --- a/plugins/modules/metal_ip_assignment_info.py +++ b/plugins/modules/metal_ip_assignment_info.py @@ -3,9 +3,55 @@ # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) -DOCUMENTATION = "" -EXAMPLES = "" -RETURN = "" +DOCUMENTATION = ''' +author: Equinix DevRel Team (@equinix) +description: Gather IP address assignments for a device +module: metal_ip_assignment_info +notes: [] +options: + device_id: + description: + - UUID of the device to list ip_assignments for. + required: true + type: str +requirements: +- python >= 3 +- equinix_metal >= 0.0.1 +short_description: Gather IP address assignments for a device +''' +EXAMPLES = ''' +- name: assignment info + equinix.cloud.metal_ip_assignment_info: + device_id: '{{ device.id }}' + register: assignment_info +''' +RETURN = ''' +resources: + description: Found resources + returned: always + sample: + - "\n[\n {\n \"address\": \"147.75.55.115/31\",\n \"address_family\"\ + : 4,\n \"cidr\": 31,\n \"device_id\": \"8ea9837a-6d19-4607-b166-f7f7bb04b022\"\ + ,\n \"id\": \"38deafaa-0a1d-4e32-b8cd-417e2ba958db\",\n \"management\"\ + : true,\n \"metro\": \"da\",\n \"netmask\": \"255.255.255.254\"\ + ,\n \"network\": \"147.75.55.114\",\n \"public\": true\n },\n\ + \ {\n \"address\": \"145.40.102.107/32\",\n \"address_family\"\ + : 4,\n \"cidr\": 32,\n \"device_id\": \"8ea9837a-6d19-4607-b166-f7f7bb04b022\"\ + ,\n \"id\": \"c30b9d28-755c-4016-8480-b90497643c29\",\n \"management\"\ + : false,\n \"metro\": \"da\",\n \"netmask\": \"255.255.255.255\"\ + ,\n \"network\": \"145.40.102.107\",\n \"public\": true\n },\n\ + \ {\n \"address\": \"2604:1380:4641:5b00::1/127\",\n \"address_family\"\ + : 6,\n \"cidr\": 127,\n \"device_id\": \"8ea9837a-6d19-4607-b166-f7f7bb04b022\"\ + ,\n \"id\": \"ad2f9b8c-f73f-4ae7-9016-f78b316f7ad6\",\n \"management\"\ + : true,\n \"metro\": null,\n \"netmask\": \"ffff:ffff:ffff:ffff:ffff:ffff:ffff:fffe\"\ + ,\n \"network\": \"2604:1380:4641:5b00::\",\n \"public\": true\n\ + \ },\n {\n \"address\": \"10.70.50.129/31\",\n \"address_family\"\ + : 4,\n \"cidr\": 31,\n \"device_id\": \"8ea9837a-6d19-4607-b166-f7f7bb04b022\"\ + ,\n \"id\": \"4d81a406-3fb2-4ac4-9e03-2a498c5788e1\",\n \"management\"\ + : true,\n \"metro\": null,\n \"netmask\": \"255.255.255.254\",\n\ + \ \"network\": \"10.70.50.128\",\n \"public\": false\n }\n]\n" + type: dict +''' from ansible.module_utils._text import to_native import traceback diff --git a/plugins/modules/metal_project.py b/plugins/modules/metal_project.py index c58f0bf..543471f 100644 --- a/plugins/modules/metal_project.py +++ b/plugins/modules/metal_project.py @@ -47,31 +47,31 @@ type: str requirements: - python >= 3 -- metal_python >= 0.0.1 +- equinix_metal >= 0.0.1 short_description: Manage Projects in Equinix Metal ''' EXAMPLES = ''' - name: Create new project hosts: localhost tasks: - equinix.cloud.metal_project: + - equinix.cloud.metal_project: name: new project - name: Create new project within non - default organization hosts: localhost tasks: - equinix.cloud.metal_project: + - equinix.cloud.metal_project: name: my org project organization_id: a4cc87f9-e00f-48c2-9460-74aa60beb6b0 - name: Remove project by id hosts: localhost tasks: - equinix.cloud.metal_project: + - equinix.cloud.metal_project: id: eef49903-7a09-4ca1-af67-4087c29ab5b6 state: absent - name: Create new project with non - default billing method hosts: localhost tasks: - equinix.cloud.metal_project: + - equinix.cloud.metal_project: name: newer project payment_method_id: abf49903-7a09-4ca1-af67-4087c29ab343 ''' diff --git a/plugins/modules/metal_project_info.py b/plugins/modules/metal_project_info.py index 6e6302f..6e4f3b7 100644 --- a/plugins/modules/metal_project_info.py +++ b/plugins/modules/metal_project_info.py @@ -24,7 +24,7 @@ type: str requirements: - python >= 3 -- metal_python >= 0.0.1 +- equinix_metal >= 0.0.1 short_description: Gather information about Equinix Metal projects ''' EXAMPLES = ''' @@ -43,11 +43,11 @@ description: Found resources returned: always sample: - - "\n{\n \"backend_transfer_enabled\": false,\n \"customdata\": {},\n \"\ - description\": \"\",\n \"id\": \"31d3ae8b-bd5a-41f3-a420-055211345cc7\",\n\ - \ \"name\": \"ansible-integration-test-project-csle6t2y-project2\",\n \"\ - organization_id\": \"70c2f878-9f32-452e-8c69-ab15480e1d99\",\n \"payment_method_id\"\ - : \"845b45a3-c565-47e5-b9b6-a86204a73d29\"\n}" + - "\n\n[ \n {\n \"backend_transfer_enabled\": false,\n \"customdata\": {},\n\ + \ \"description\": \"\",\n \"id\": \"31d3ae8b-bd5a-41f3-a420-055211345cc7\"\ + ,\n \"name\": \"ansible-integration-test-project-csle6t2y-project2\",\n \ + \ \"organization_id\": \"70c2f878-9f32-452e-8c69-ab15480e1d99\",\n \"payment_method_id\"\ + : \"845b45a3-c565-47e5-b9b6-a86204a73d29\"\n }\n]" type: dict ''' diff --git a/plugins/modules/metal_reserved_ip_block.py b/plugins/modules/metal_reserved_ip_block.py index 6584d93..a1dd369 100644 --- a/plugins/modules/metal_reserved_ip_block.py +++ b/plugins/modules/metal_reserved_ip_block.py @@ -6,9 +6,110 @@ # DOCUMENTATION, EXAMPLES, and METAL_PROJECT_ARGS are generated by # ansible_specdoc. Do not edit them directly. -DOCUMENTATION = "" -EXAMPLES = "" -RETURN = "" +DOCUMENTATION = ''' +author: Equinix DevRel Team (@equinix) +description: When a user provisions first device in a facility, Equinix Metal API + automatically allocates IPv6/56 and private IPv4/25 blocks. The new device then + gets IPv6 and private IPv4 addresses from those block. It also gets a public IPv4/31 + address. Every new device in the project and facility will automatically get IPv6 + and private IPv4 addresses from these pre-allocated blocks. The IPv6 and private + IPv4 blocks can't be created, only imported. With this resource, it's possible to + create either public IPv4 blocks or global IPv4 blocks. +module: metal_reserved_ip_block +notes: [] +options: + comments: + description: + - Comments to associate with the reserved IP block + required: false + type: str + customdata: + description: + - Custom data to associate with the reserved IP block + required: false + type: str + details: + description: + - Details about the reserved IP block + required: false + type: str + id: + description: + - UUID of the reserved IP block + required: false + type: str + metro: + description: + - The metro where the reserved IP block will be created + required: false + type: str + project_id: + description: + - The ID of the project to which the reserved IP block will be assigned + required: false + type: str + quantity: + description: + - The number of IP addresses to reserve + required: false + type: int + tags: + description: + - Tags to associate with the reserved IP block + required: false + type: list + type: + choices: + - public_ipv4 + - public_ipv6 + - private_ipv4 + - global_ipv4 + - vrf + description: + - The type of IP address to list + required: false + type: str + vrf_id: + description: + - The ID of the VRF in which this VRF IP Reservation is created. + - The VRF must have an existing IP Range that contains the requested subnet. + required: false + type: str +requirements: +- python >= 3 +- equinix_metal >= 0.0.1 +short_description: Create/delete blocks of reserved IP addresses in a project. +''' +EXAMPLES = ''' +- name: Create a new reserved IP block in metro "sv" + hosts: localhost + tasks: + - equinix.cloud.metal_reserved_ip_block: + project_id: 2a5122b9-c323-4d5c-b53c-9ad3f54273e7 + type: public_ipv4 + quantity: 1 + metro: sv +- name: Create a new global reserved IP block (no metro) + hosts: localhost + tasks: + - equinix.cloud.metal_reserved_ip_block: + project_id: 2a5122b9-c323-4d5c-b53c-9ad3f54273e7 + type: global_ipv4 + quantity: 1 +''' +RETURN = ''' +metal_reserved_ip_block: + description: The module object + returned: always + sample: + - "\n{\n \"address_family\": 4,\n \"changed\": true,\n \"customdata\":\ + \ {},\n \"details\": \"\",\n \"id\": \"6d94f567-6cf5-4536-8216-7dc96e1585dd\"\ + ,\n \"management\": false,\n \"metro\": \"sv\",\n \"netmask\": \"255.255.255.255\"\ + ,\n \"network\": \"145.40.67.3\",\n \"project_id\": \"fd554070-70b6-420d-b3f8-7ed8438862d5\"\ + ,\n \"public\": true,\n \"quantity\": 1,\n \"tags\": [\n \"t1\"\ + ,\n \"t2\"\n ],\n \"type\": \"public_ipv4\"\n}\n" + type: dict +''' from ansible.module_utils._text import to_native import traceback diff --git a/plugins/modules/metal_reserved_ip_block_info.py b/plugins/modules/metal_reserved_ip_block_info.py index 7498634..e0ec253 100644 --- a/plugins/modules/metal_reserved_ip_block_info.py +++ b/plugins/modules/metal_reserved_ip_block_info.py @@ -6,9 +6,67 @@ # DOCUMENTATION, EXAMPLES, and METAL_PROJECT_ARGS are generated by # ansible_specdoc. Do not edit them directly. -DOCUMENTATION = "" -EXAMPLES = "" -RETURN = "" +DOCUMENTATION = ''' +author: Equinix DevRel Team (@equinix) +description: Gather list of reserved IP blocks matching the specified criteria +module: metal_reserved_ip_block_info +notes: [] +options: + metro: + description: + - The metro to list IP addresses for + required: false + type: str + project_id: + description: + - UUID of the project to list IP addresses for + required: true + type: str + type: + choices: + - public_ipv4 + - public_ipv6 + - private_ipv4 + - global_ipv4 + - vrf + description: + - The type of IP address to list + required: true + type: str +requirements: +- python >= 3 +- equinix_metal >= 0.0.1 +short_description: Gather list of reserved IP blocks +''' +EXAMPLES = ''' +- name: Gather list of public_ipv4 reserved_ip_blocks in a project + hosts: localhost + tasks: + - equinix.cloud.metal_reserved_ip_block_info: + type: public_ipv4 + project_id: 2a5122b9-c323-4d5c-b53c-9ad3f54273e7 +- name: Gather list of public_ipv6 reserved_ip_blocks in a project in metro ams + hosts: localhost + tasks: + - equinix.cloud.metal_reserved_ip_block_info: + type: public_ipv6 + project_id: 2a5122b9-c323-4d5c-b53c-9ad3f54273e7 + metro: ams +''' +RETURN = ''' +resources: + description: Found resources + returned: always + sample: + - "\n[\n {\n \"address_family\": 4,\n \"customdata\": {},\n \ + \ \"details\": \"some desc fff\",\n \"id\": \"16148fad-7839-4c63-b33f-0ecfec4f9e29\"\ + ,\n \"management\": false,\n \"metro\": \"da\",\n \"netmask\"\ + : \"255.255.255.255\",\n \"network\": \"145.40.102.107\",\n \"project_id\"\ + : \"52000fb2-ee46-4673-93a8-de2c2bdba33b\",\n \"public\": true,\n \ + \ \"quantity\": 1,\n \"tags\": [],\n \"type\": \"public_ipv4\"\ + \n }\n]\n" + type: dict +''' from ansible.module_utils._text import to_native from ansible_specdoc.objects import SpecField, FieldType, SpecDocMeta, SpecReturnValue @@ -24,17 +82,17 @@ - name: Gather list of public_ipv4 reserved_ip_blocks in a project hosts: localhost tasks: - - equinix.cloud.metal_reserved_ip_block_info - type: public_ipv4 - project_id: 2a5122b9-c323-4d5c-b53c-9ad3f54273e7 + - equinix.cloud.metal_reserved_ip_block_info: + type: public_ipv4 + project_id: 2a5122b9-c323-4d5c-b53c-9ad3f54273e7 ''', ''' - name: Gather list of public_ipv6 reserved_ip_blocks in a project in metro ams hosts: localhost tasks: - equinix.cloud.metal_reserved_ip_block_info - type: public_ipv6 - project_id: 2a5122b9-c323-4d5c-b53c-9ad3f54273e7 - metro: ams + - equinix.cloud.metal_reserved_ip_block_info: + type: public_ipv6 + project_id: 2a5122b9-c323-4d5c-b53c-9ad3f54273e7 + metro: ams ''' module_spec = dict( @@ -79,7 +137,7 @@ SPECDOC_META = getSpecDocMeta( short_description="Gather list of reserved IP blocks", - description="Gatehr list of reserved IP blocks matching the specified criteria", + description="Gather list of reserved IP blocks matching the specified criteria", examples=specdoc_examples, options=module_spec, return_values={ diff --git a/requirements.txt b/requirements.txt index f2cdd5e..2048c67 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,2 @@ equinix-metal>=0.1.0 -ansible-specdoc>=0.0.12 - +ansible-specdoc>=0.0.13 diff --git a/scripts/render_readme.py b/scripts/render_readme.py index 37d66eb..acdadce 100755 --- a/scripts/render_readme.py +++ b/scripts/render_readme.py @@ -43,7 +43,6 @@ def add_ansible_collection_path(): 'namespace}/{collection}/') return - print(ansible_root) sys.path.append(ansible_root) diff --git a/scripts/specdoc_generate.sh b/scripts/specdoc_generate.sh index b73c36b..4cf39bf 100755 --- a/scripts/specdoc_generate.sh +++ b/scripts/specdoc_generate.sh @@ -4,14 +4,8 @@ DPATH="${DOCS_PATH:="docs"}" for f in plugins/modules/*.py do - echo $f MODULE_NAME="$(basename "$f" .py)" - PYTHONWARNINGS="ignore" ansible-specdoc -i "$f" -f jinja2 -t template/module.md.j2 -o $DPATH/modules/"$MODULE_NAME".md; -done - -for f in plugins/inventory/*.py -do - echo $f - MODULE_NAME="$(basename "$f" .py)" - PYTHONWARNINGS="ignore" ansible-specdoc -i "$f" -f jinja2 -t template/module.md.j2 -o $DPATH/inventory/"$MODULE_NAME".md; + DOCPATH=$DPATH/modules/"$MODULE_NAME".md + echo generating $DOCPATH + PYTHONWARNINGS="ignore" ansible-specdoc -i "$f" -f jinja2 -t template/module.md.j2 -o $DOCPATH done diff --git a/scripts/specdoc_inject.sh b/scripts/specdoc_inject.sh index cc4cfa6..cd0494c 100755 --- a/scripts/specdoc_inject.sh +++ b/scripts/specdoc_inject.sh @@ -1,15 +1,19 @@ #!/bin/bash +SWITCH="-j" + +CALLED_NAME=`basename $0` +VERB="injecting generated docs to" + +if [ $CALLED_NAME == "specdoc_remove.sh" ]; then + SWITCH="-jc" + VERB="removing generated docs from" +fi + DPATH="${DOCS_PATH:="docs"}" for f in plugins/modules/*.py do - echo $f - PYTHONWARNINGS="ignore" ansible-specdoc -j -i "$f"; -done - -for f in plugins/inventory/*.py -do - echo $f - PYTHONWARNINGS="ignore" ansible-specdoc -j -i "$f"; + echo $VERB $f + PYTHONWARNINGS="ignore" ansible-specdoc $SWITCH -i "$f"; done diff --git a/scripts/specdoc_remove.sh b/scripts/specdoc_remove.sh new file mode 120000 index 0000000..c56e30b --- /dev/null +++ b/scripts/specdoc_remove.sh @@ -0,0 +1 @@ +specdoc_inject.sh \ No newline at end of file diff --git a/template/README.template.md b/template/README.template.md index b0eb394..9aa6e88 100644 --- a/template/README.template.md +++ b/template/README.template.md @@ -39,7 +39,7 @@ Dynamically add Equinix infrastructure to an Ansible inventory. Name | --- | -{% for name in inventory %}[equinix.cloud.{{ name }}]({% if is_release %}https://github.com/equinix-labs/ansible-collection-equinix/blob/{{ collection_version }}/docs/inventory/{{ name }}.md{% else %}./docs/inventory/{{ name }}.md{% endif %})| +{% for name in inventory %}[equinix.cloud.{{ name }}]({% if is_release %}https://github.com/equinix-labs/ansible-collection-equinix/blob/{{ collection_version }}/docs/inventory/{{ name }}.md{% else %}./docs/inventory/{{ name }}.rst{% endif %})| {% endfor %} @@ -62,11 +62,12 @@ pip install -r https://raw.githubusercontent.com/equinix-labs/ansible-collection ## Usage Once the Equinix Ansible collection is installed, it can be referenced by its [Fully Qualified Collection Namespace (FQCN)](https://github.com/ansible-collections/overview#terminology): `equinix.cloud.module_name`. -In order to use this collection, you should have account in the relevant Equinix service. For example you should have an account Equinix Metal to use the `metal_*` plugins. +In order to use this collection, you should have account in the relevant Equinix service. For example you should have an account in Equinix Metal to use the `metal_*` modules. -You can authenticate either by exporting auth tokens as environment variables, or by supplying `*_api_token` attributes to modules. For example, to use `metal_device`, you can export `METAL_AUTH_TOKEN` (or `METAL_API_TOKEN`), or you can supply `metal_auth_token` attribute. +You can authenticate either by exporting auth token as environment variables, or by supplying `*_api_token` attributes to modules. For example, to use `metal_device`, you can export `METAL_AUTH_TOKEN` (or `METAL_API_TOKEN`), or you can supply `metal_api_token` attribute. + +### Example Playbook -#### Example Playbook ```yaml --- - name: create Equinix Metal device diff --git a/template/module.rst.j2 b/template/module.rst.j2 new file mode 100644 index 0000000..62eb3ac --- /dev/null +++ b/template/module.rst.j2 @@ -0,0 +1,183 @@ +.. _{{ module }}_module: + +{% if short_description %} +{% set title = module + ' -- ' + short_description | rst_ify %} +{% else %} +{% set title = module %} +{% endif %} + +{{ title }} +{{ '=' * title|length }} + +.. contents:: + :local: + :depth: 1 + + +{% if description -%} +Synopsis +-------- + +{% for desc in description %} +{{ desc | rst_ify }} + +{% endfor %} +{% endif %} + + +{% if requirements -%} +Requirements +------------ +The below requirements are needed on the host that executes this module. + +{% for req in requirements %} +- {{ req | rst_ify }} +{% endfor %} +{% endif %} + + +{% macro option_desc(opts, level, require_exclusive) %} +{% for name, spec in opts.items() %} +{% set req = spec.required %} +{% set typ = spec.type | default("any") %} +{% set def_val = spec.default %} +{% if (req and require_exclusive) or (not req and not require_exclusive) %} + {{ " " * level }}**{{ name }} ({% if req %}Required, {% endif %}type={{ typ }}{% if def_val %}, default={{ def_val }}{% endif %}):** +{% for para in spec.description %} + {{ " " * level }}\• {{ para | rst_ify }} + +{% endfor %} +{% if spec.choices %} + {{ " " * level }}\• Options: {% for c in spec.choices %}`{{ c }}`{% if not loop.last %}, {% endif %}{% endfor %} + + +{% endif %} + +{% if spec.suboptions %} +{{ option_desc(spec.suboptions, level + 1, require_exclusive) }} +{% endif %} +{% endif %} +{% endfor %} +{% endmacro %} + +{% if options -%} +Parameters +---------- + +{{ option_desc(options, 0, True) }} +{{ option_desc(options, 0, False) }} +{% endif %} + + +{% if seealso -%} +See Also +-------- + +.. seealso:: + +{% for item in seealso %} +{% if item.module is defined and item.description is defined %} + :ref:`{{ item.module }}_module` + {{ item.description | rst_ify }} +{% elif item.module is defined %} + :ref:`{{ item.module }}_module` + The official documentation on the **{{ item.module }}** module. +{% elif item.name is defined and item.link is defined and item.description is defined %} + `{{ item.name }} <{{ item.link }}>`_ + {{ item.description | rst_ify }} +{% elif item.ref is defined and item.description is defined %} + :ref:`{{ item.ref }}` + {{ item.description | rst_ify }} +{% endif %} +{% endfor %} +{% endif %} + + +{% if examples -%} +Examples +-------- + +.. code-block:: yaml+jinja + +{{ examples | indent(4, True) }} +{% endif %} + +{% macro result_desc(results, level) %} +{% for name, spec in results.items() %} +{% set ret = spec.returned %} +{% set typ = spec.type | default("any") %} +{% set sample = spec.sample %} +{% set api_docs = spec.linode_api_docs %} +{{ " " * level }}**{{ name }} (returned={{ ret }}, type={{ typ }}):** + +{% for para in spec.description %} +{{ " " * level }}{{ para | rst_ify }} +{% endfor %} + +`Linode Response Object Documentation <{{ api_docs }}>`_ + +Sample Response: + +.. code-block:: JSON + +{{ sample | tojson(indent=True) | indent(4, True) }} + + +{% if spec.contains %} +{{ result_desc(spec.contains, level + 1) }} +{% endif %} +{% endfor %} +{% endmacro %} + + +{% if returndocs -%} +Return Values +------------- + +{{ result_desc(returndocs, 0) }} +{% endif %} + + +Status +------ + +{% if deprecated %} + +- This {{ plugin_type }} will be removed in version + {{ deprecated['removed_in'] | default('') | string | rst_ify }}. + *[deprecated]* + +{% else %} + +{% set module_states = { + "preview": "not guaranteed to have a backwards compatible interface", + "stableinterface": "guaranteed to have backward compatible interface changes going forward", + } +%} + +{% if metadata %} +{% if metadata.status %} + +{% for cur_state in metadata.status %} +- This {{ plugin_type }} is {{ module_states[cur_state] }}. *[{{ cur_state }}]* +{% endfor %} + +{% endif %} + +{% if metadata.supported_by %} +- This {{ plugin_type }} is maintained by {{ metadata.supported_by }}. +{% endif %} + +{% endif %} + +{% endif %} + +{% if author is defined -%} +Authors +~~~~~~~ + +{% for author_name in author %} +- {{ author_name }} +{% endfor %} + +{% endif %} \ No newline at end of file From 59bb0f92cb92083557de6699a729cb0bb378fcdf Mon Sep 17 00:00:00 2001 From: Tomas Karasek Date: Tue, 25 Apr 2023 18:23:41 +0200 Subject: [PATCH 2/7] include generated readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1334510..b657002 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,7 @@ Once the Equinix Ansible collection is installed, it can be referenced by its [F In order to use this collection, you should have account in the relevant Equinix service. For example you should have an account in Equinix Metal to use the `metal_*` modules. -You can authenticate either by exporting auth token as environment variables, or by supplying `*_api_token` attributes to modules. For example, to use `metal_device`, you can export `METAL_AUTH_TOKEN`, or you can supply `metal_api_token` attribute. +You can authenticate either by exporting auth token as environment variables, or by supplying `*_api_token` attributes to modules. For example, to use `metal_device`, you can export `METAL_AUTH_TOKEN` (or `METAL_API_TOKEN`), or you can supply `metal_api_token` attribute. ### Example Playbook From 8dfe0cbc7360f1e2598df390d8cdc3f40985acad Mon Sep 17 00:00:00 2001 From: Tomas Karasek Date: Tue, 25 Apr 2023 18:25:38 +0200 Subject: [PATCH 3/7] improve language in readme --- README.md | 2 +- template/README.template.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b657002..8b41f4f 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,7 @@ Once the Equinix Ansible collection is installed, it can be referenced by its [F In order to use this collection, you should have account in the relevant Equinix service. For example you should have an account in Equinix Metal to use the `metal_*` modules. -You can authenticate either by exporting auth token as environment variables, or by supplying `*_api_token` attributes to modules. For example, to use `metal_device`, you can export `METAL_AUTH_TOKEN` (or `METAL_API_TOKEN`), or you can supply `metal_api_token` attribute. +You can authenticate either by exporting auth token in an environment variable, or by supplying `*_api_token` attributes to modules. For example, to use `metal_device`, you can export `METAL_AUTH_TOKEN` (or `METAL_API_TOKEN`), or you can supply the `metal_api_token` attribute. ### Example Playbook diff --git a/template/README.template.md b/template/README.template.md index 9aa6e88..5bb8a75 100644 --- a/template/README.template.md +++ b/template/README.template.md @@ -64,7 +64,7 @@ Once the Equinix Ansible collection is installed, it can be referenced by its [F In order to use this collection, you should have account in the relevant Equinix service. For example you should have an account in Equinix Metal to use the `metal_*` modules. -You can authenticate either by exporting auth token as environment variables, or by supplying `*_api_token` attributes to modules. For example, to use `metal_device`, you can export `METAL_AUTH_TOKEN` (or `METAL_API_TOKEN`), or you can supply `metal_api_token` attribute. +You can authenticate either by exporting auth token in an environment variable, or by supplying `*_api_token` attributes to modules. For example, to use `metal_device`, you can export `METAL_AUTH_TOKEN` (or `METAL_API_TOKEN`), or you can supply the `metal_api_token` attribute. ### Example Playbook From e6f3857f6874f64f0cfb8aa6435156a30d9ffa83 Mon Sep 17 00:00:00 2001 From: Tomas Karasek Date: Tue, 25 Apr 2023 18:29:27 +0200 Subject: [PATCH 4/7] include generated inventory docs --- docs/inventory/metal_device.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/inventory/metal_device.rst b/docs/inventory/metal_device.rst index 5bf18b0..e4518d9 100644 --- a/docs/inventory/metal_device.rst +++ b/docs/inventory/metal_device.rst @@ -35,7 +35,7 @@ Parameters **metal_api_token (Required, type=str):** - \• Equinix Metal API token. Can also be specified via METAL_API_TOKEN environment variable. + \• Equinix Metal API token. Can also be specified via METAL_AUTH_TOKEN environment variable. From ccff4f21bc7ca04aa8abbb2b4e9bb1d168970850 Mon Sep 17 00:00:00 2001 From: Tomas Karasek Date: Thu, 27 Apr 2023 15:15:14 +0200 Subject: [PATCH 5/7] Add generated readme --- README.md | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 8b41f4f..581511d 100644 --- a/README.md +++ b/README.md @@ -21,10 +21,10 @@ Modules for managing Equinix infrastructure. Name | Description | --- | ------------ | -[equinix.cloud.metal_device](https://github.com/equinix-labs/ansible-collection-equinix/blob/0.0.1/docs/modules/metal_device.md)|Create, update, or delete Equinix Metal devices| -[equinix.cloud.metal_ip_assignment](https://github.com/equinix-labs/ansible-collection-equinix/blob/0.0.1/docs/modules/metal_ip_assignment.md)|Manage Equinix Metal IP assignments| -[equinix.cloud.metal_project](https://github.com/equinix-labs/ansible-collection-equinix/blob/0.0.1/docs/modules/metal_project.md)|Manage Projects in Equinix Metal| -[equinix.cloud.metal_reserved_ip_block](https://github.com/equinix-labs/ansible-collection-equinix/blob/0.0.1/docs/modules/metal_reserved_ip_block.md)|Create/delete blocks of reserved IP addresses in a project.| +[equinix.cloud.metal_device](./docs/modules/metal_device.md)|Create, update, or delete Equinix Metal devices| +[equinix.cloud.metal_ip_assignment](./docs/modules/metal_ip_assignment.md)|Manage Equinix Metal IP assignments| +[equinix.cloud.metal_project](./docs/modules/metal_project.md)|Manage Projects in Equinix Metal| +[equinix.cloud.metal_reserved_ip_block](./docs/modules/metal_reserved_ip_block.md)|Create/delete blocks of reserved IP addresses in a project.| ### Info Modules @@ -33,11 +33,11 @@ Modules for retrieving information about existing Equinix infrastructure. Name | Description | --- | ------------ | -[equinix.cloud.metal_available_ips_info](https://github.com/equinix-labs/ansible-collection-equinix/blob/0.0.1/docs/modules/metal_available_ips_info.md)|Get list of avialable IP addresses from a reserved IP block| -[equinix.cloud.metal_device_info](https://github.com/equinix-labs/ansible-collection-equinix/blob/0.0.1/docs/modules/metal_device_info.md)|Select list of Equinix Metal devices| -[equinix.cloud.metal_ip_assignment_info](https://github.com/equinix-labs/ansible-collection-equinix/blob/0.0.1/docs/modules/metal_ip_assignment_info.md)|Gather IP address assignments for a device| -[equinix.cloud.metal_project_info](https://github.com/equinix-labs/ansible-collection-equinix/blob/0.0.1/docs/modules/metal_project_info.md)|Gather information about Equinix Metal projects| -[equinix.cloud.metal_reserved_ip_block_info](https://github.com/equinix-labs/ansible-collection-equinix/blob/0.0.1/docs/modules/metal_reserved_ip_block_info.md)|Gather list of reserved IP blocks| +[equinix.cloud.metal_available_ips_info](./docs/modules/metal_available_ips_info.md)|Get list of avialable IP addresses from a reserved IP block| +[equinix.cloud.metal_device_info](./docs/modules/metal_device_info.md)|Select list of Equinix Metal devices| +[equinix.cloud.metal_ip_assignment_info](./docs/modules/metal_ip_assignment_info.md)|Gather IP address assignments for a device| +[equinix.cloud.metal_project_info](./docs/modules/metal_project_info.md)|Gather information about Equinix Metal projects| +[equinix.cloud.metal_reserved_ip_block_info](./docs/modules/metal_reserved_ip_block_info.md)|Gather list of reserved IP blocks| ### Inventory Plugins @@ -63,7 +63,7 @@ The Python module dependencies are not installed by `ansible-galaxy`. They can be manually installed using pip: ```shell -pip install -r https://raw.githubusercontent.com/equinix-labs/ansible-collection-equinix/0.0.1/requirements.txt +pip install -r https://raw.githubusercontent.com/equinix-labs/ansible-collection-equinix/main/requirements.txt ``` ## Usage @@ -117,23 +117,21 @@ To install the collection from local directory, do `make install` in the root of ## Releasing -When releasing, make sure that the desired version number is in `COLLECTION_VERSION` variable in Makefile. - -Then go to [https://github.com/equinix-labs/ansible-collection-equinix/releases/new](https://github.com/ansible-collection-equinix/metal-python/releases/new) and create a new release from `main`. Don't choose an existing tag. Put `v{COLLECTION_VERSION}` to the field for "Release title". For example if COLLECTION_VERSION is "0.1.2", use "v0.1.2". +Go to [https://github.com/equinix-labs/ansible-collection-equinix/releases/new](https://github.com/ansible-collection-equinix/metal-python/releases/new) and create a new release from `main`. Don't choose an existing tag. Put version to the field for "Release title", for example `v0.1.2`. Don't add collection number to the Makefile. Add release notes in format of [Terraform Provider Equinix](https://github.com/equinix/terraform-provider-equinix/releases), with at least one of the sections (NOTES, FEATURES, BUG FIXES, ENHANCEMENTS). Click "Publish release", and the manual part should be over. -The release will create a tag, and we have a Github action in place that should create an Ansible Galaxy release for version from COLLECTION_VERSION. +The release will create a tag, and we have a Github action in place that should create an Ansible Galaxy release. The script that creates tarball for Galay removes the first "v", so releasing `v0.1.2` should upload collection equinix.cloud version 0.1.2. Verify that the [releasing Github action](https://github.com/equinix-labs/ansible-collection-equinix/actions) succeeded. -Verify that new version of [equinix.cloud](https://galaxy.ansible.com/equinix/cloud) is avaiable in Ansible Galaxy. +Verify that new version of [equinix.cloud](https://galaxy.ansible.com/equinix/cloud) is available in Ansible Galaxy. ## Licensing GNU General Public License v3.0. -See [COPYING](COPYING) to see the full text. +See [COPYING](COPYING) to see the full text. \ No newline at end of file From 1486f28f764161c83368b9b10c01410fe1640212 Mon Sep 17 00:00:00 2001 From: Tomas Karasek Date: Thu, 27 Apr 2023 15:15:35 +0200 Subject: [PATCH 6/7] install parallel in inegratino tests --- .github/workflows/integration-tests.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml index 845669a..a4a0545 100644 --- a/.github/workflows/integration-tests.yml +++ b/.github/workflows/integration-tests.yml @@ -31,6 +31,12 @@ jobs: - name: install dependencies run: python -m pip install -r requirements-dev.txt -r requirements.txt + - name: update apt + run: sudo apt update + + - name: install parallel + run: sudo apt install parallel + - name: install collection run: make install From 3aee0c420479b31435507ce27394838431273e4c Mon Sep 17 00:00:00 2001 From: Tomas Karasek Date: Thu, 27 Apr 2023 15:30:39 +0200 Subject: [PATCH 7/7] remove inventory integration test --- .../targets/metal_device_inventory/.gitignore | 1 - .../playbooks/create_inventory.yml | 12 ------ .../playbooks/setup_metal_device.yml | 25 ------------- .../playbooks/teardown.yml | 37 ------------------- .../playbooks/test_inventory_keyedgroups.yml | 11 ------ .../playbooks/test_inventory_nofilter.yml | 12 ------ .../targets/metal_device_inventory/runme.sh | 17 --------- .../templates/keyedgroups.metal_device.yml | 7 ---- .../templates/nofilter.metal_device.yml | 2 - 9 files changed, 124 deletions(-) delete mode 100644 tests/integration/targets/metal_device_inventory/.gitignore delete mode 100644 tests/integration/targets/metal_device_inventory/playbooks/create_inventory.yml delete mode 100644 tests/integration/targets/metal_device_inventory/playbooks/setup_metal_device.yml delete mode 100644 tests/integration/targets/metal_device_inventory/playbooks/teardown.yml delete mode 100644 tests/integration/targets/metal_device_inventory/playbooks/test_inventory_keyedgroups.yml delete mode 100644 tests/integration/targets/metal_device_inventory/playbooks/test_inventory_nofilter.yml delete mode 100755 tests/integration/targets/metal_device_inventory/runme.sh delete mode 100644 tests/integration/targets/metal_device_inventory/templates/keyedgroups.metal_device.yml delete mode 100644 tests/integration/targets/metal_device_inventory/templates/nofilter.metal_device.yml diff --git a/tests/integration/targets/metal_device_inventory/.gitignore b/tests/integration/targets/metal_device_inventory/.gitignore deleted file mode 100644 index f9fbc8e..0000000 --- a/tests/integration/targets/metal_device_inventory/.gitignore +++ /dev/null @@ -1 +0,0 @@ -*.metal_device.yml diff --git a/tests/integration/targets/metal_device_inventory/playbooks/create_inventory.yml b/tests/integration/targets/metal_device_inventory/playbooks/create_inventory.yml deleted file mode 100644 index 5d7b001..0000000 --- a/tests/integration/targets/metal_device_inventory/playbooks/create_inventory.yml +++ /dev/null @@ -1,12 +0,0 @@ ---- -- hosts: localhost - connection: local - gather_facts: no - vars: - template_name: '../templates/{{ template }}' - vars_files: - - ../../../integration_config.yml - tasks: - - template: - src: '{{ template_name }}' - dest: '../{{ template }}' diff --git a/tests/integration/targets/metal_device_inventory/playbooks/setup_metal_device.yml b/tests/integration/targets/metal_device_inventory/playbooks/setup_metal_device.yml deleted file mode 100644 index 76e941f..0000000 --- a/tests/integration/targets/metal_device_inventory/playbooks/setup_metal_device.yml +++ /dev/null @@ -1,25 +0,0 @@ ---- -- hosts: localhost - connection: local - gather_facts: no - vars_files: - - ../../../integration_config.yml - tasks: - - - name: Create testing project - equinix.cloud.metal_project: - metal_api_token: '{{ metal_api_token }}' - name: 'ansible-test-inventory' - register: project - - - name: Create a basic Equinix Metal Device - equinix.cloud.metal_device: - project_id: "{{ project.id }}" - hostname: 'ansible-test-inventory' - metal_api_token: '{{ metal_api_token }}' - plan: c3.small.x86 - operating_system: ubuntu_20_04 - metro: sv - provisioning_wait_seconds: 1200 - tags: - - ansible-inventory-node diff --git a/tests/integration/targets/metal_device_inventory/playbooks/teardown.yml b/tests/integration/targets/metal_device_inventory/playbooks/teardown.yml deleted file mode 100644 index a59b73b..0000000 --- a/tests/integration/targets/metal_device_inventory/playbooks/teardown.yml +++ /dev/null @@ -1,37 +0,0 @@ ---- -- hosts: localhost - connection: local - gather_facts: no - vars_files: - - ../../../integration_config.yml - tasks: - - name: get testing project id - equinix.cloud.metal_project_info: - metal_api_token: '{{ metal_api_token }}' - name: 'ansible-test-inventory' - register: projects - - - name: Delete the metal_device - equinix.cloud.metal_device: - project_id: "{{ projects.resources[0].id}}" - hostname: 'ansible-test-inventory' - metal_api_token: '{{ metal_api_token }}' - plan: c3.small.x86 - metro: sv - tags: - - ansible-inventory-node - state: absent - - - name: remove testing project - equinix.cloud.metal_project: - metal_api_token: '{{ metal_api_token }}' - id: "{{ projects.resources[0].id}}" - state: absent - - - name: Ensure test files are absent - file: - path: '../{{item}}.yml' - state: absent - loop: - - nofilter.metal_device.yml - - keyedgroups.metal_device.yml diff --git a/tests/integration/targets/metal_device_inventory/playbooks/test_inventory_keyedgroups.yml b/tests/integration/targets/metal_device_inventory/playbooks/test_inventory_keyedgroups.yml deleted file mode 100644 index b3707d1..0000000 --- a/tests/integration/targets/metal_device_inventory/playbooks/test_inventory_keyedgroups.yml +++ /dev/null @@ -1,11 +0,0 @@ ---- -- hosts: localhost - connection: local - gather_facts: no - tasks: - - meta: refresh_inventory - - - name: Test inventory without filter - assert: - that: - - "groups['cool_group'] | list | length > 0" \ No newline at end of file diff --git a/tests/integration/targets/metal_device_inventory/playbooks/test_inventory_nofilter.yml b/tests/integration/targets/metal_device_inventory/playbooks/test_inventory_nofilter.yml deleted file mode 100644 index b998c25..0000000 --- a/tests/integration/targets/metal_device_inventory/playbooks/test_inventory_nofilter.yml +++ /dev/null @@ -1,12 +0,0 @@ ---- -- hosts: localhost - connection: local - gather_facts: no - tasks: - - meta: refresh_inventory - - - name: Test inventory without filter - assert: - that: - - "'ansible-test-inventory' in hostvars" - - hostvars["ansible-test-inventory"].ansible_host|length > 0 \ No newline at end of file diff --git a/tests/integration/targets/metal_device_inventory/runme.sh b/tests/integration/targets/metal_device_inventory/runme.sh deleted file mode 100755 index 7a634bb..0000000 --- a/tests/integration/targets/metal_device_inventory/runme.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env bash - -set -eux - -# Create testing device -ansible-playbook -vvv playbooks/setup_metal_device.yml "$@" - -# Test an inventory with no filter -ansible-playbook playbooks/create_inventory.yml --extra-vars "template=nofilter.metal_device.yml" "$@" -ANSIBLE_INVENTORY=nofilter.metal_device.yml ansible-playbook playbooks/test_inventory_nofilter.yml "$@" - -# Test an inventory with keyed groups filter -ansible-playbook playbooks/create_inventory.yml --extra-vars "template=keyedgroups.metal_device.yml" "$@" -ANSIBLE_INVENTORY=keyedgroups.metal_device.yml ansible-playbook playbooks/test_inventory_keyedgroups.yml "$@" - -# Clean up -ansible-playbook playbooks/teardown.yml "$@" diff --git a/tests/integration/targets/metal_device_inventory/templates/keyedgroups.metal_device.yml b/tests/integration/targets/metal_device_inventory/templates/keyedgroups.metal_device.yml deleted file mode 100644 index a340eb6..0000000 --- a/tests/integration/targets/metal_device_inventory/templates/keyedgroups.metal_device.yml +++ /dev/null @@ -1,7 +0,0 @@ -plugin: equinix.cloud.metal_device -metal_api_token: '{{ metal_api_token }}' -keyed_groups: - - key: tags - separator: '' -groups: - cool_group: "'ansible-inventory-node' in (tags|list)" diff --git a/tests/integration/targets/metal_device_inventory/templates/nofilter.metal_device.yml b/tests/integration/targets/metal_device_inventory/templates/nofilter.metal_device.yml deleted file mode 100644 index c2a1839..0000000 --- a/tests/integration/targets/metal_device_inventory/templates/nofilter.metal_device.yml +++ /dev/null @@ -1,2 +0,0 @@ -plugin: equinix.cloud.metal_device -metal_api_token: '{{ metal_api_token }}'