Skip to content

Commit

Permalink
Merge pull request #107 from AlexBacho/feature-65
Browse files Browse the repository at this point in the history
Add modules metal_project_ssh_key{_info}, docs and tests
  • Loading branch information
t0mk authored Aug 15, 2023
2 parents cfa0a3d + d2e4b3a commit 2a64e13
Show file tree
Hide file tree
Showing 8 changed files with 663 additions and 5 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Equinix Ansible Collection
[![Ansible Galaxy](https://img.shields.io/badge/galaxy-equinix.cloud-660198.svg?style=flat)](https://galaxy.ansible.com/equinix/cloud/)
[![Ansible Galaxy](https://img.shields.io/badge/galaxy-equinix.cloud-660198.svg?style=flat)](https://galaxy.ansible.com/equinix/cloud/)
![Tests](https://img.shields.io/github/actions/workflow/status/equinix-labs/ansible-collection-equinix/integration-tests.yml?branch=main)

The Ansible Collection Equinix contains various plugins for managing Equinix services.
Expand All @@ -26,11 +26,14 @@ Name | Description |
[equinix.cloud.metal_ip_assignment](./docs/modules/metal_ip_assignment.md)|Manage Equinix Metal IP assignments|
[equinix.cloud.metal_organization](./docs/modules/metal_organization.md)|Lookup a single organization by ID in Equinix Metal|
[equinix.cloud.metal_project](./docs/modules/metal_project.md)|Manage Projects in Equinix Metal|
[equinix.cloud.metal_project_ssh_key](./docs/modules/metal_project_ssh_key.md)|Manage a project ssh key 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.|
[equinix.cloud.metal_ssh_key](./docs/modules/metal_ssh_key.md)|Manage personal SSH keys in Equinix Metal|
[equinix.cloud.metal_project_ssh_key](./docs/modules/metal_project_ssh_key.md)|Manage project SSH keys in Equinix Metal|
[equinix.cloud.metal_vlan](./docs/modules/metal_vlan.md)|Manage a VLAN resource in Equinix Metal|



### Info Modules

Modules for retrieving information about existing Equinix infrastructure.
Expand All @@ -45,7 +48,10 @@ Name | Description |
[equinix.cloud.metal_operating_system_info](./docs/modules/metal_operating_system_info.md)|Gather information about Operating Systems available for devices in Equinix Metal|
[equinix.cloud.metal_organization_info](./docs/modules/metal_organization_info.md)|Gather information about Equinix Metal organizations|
[equinix.cloud.metal_project_info](./docs/modules/metal_project_info.md)|Gather information about Equinix Metal projects|
[equinix.cloud.metal_project_ssh_key_info](./docs/modules/metal_project_ssh_key_info.md)|Gather project SSH keys.|
[equinix.cloud.metal_reserved_ip_block_info](./docs/modules/metal_reserved_ip_block_info.md)|Gather list of reserved IP blocks|
[equinix.cloud.metal_ssh_key_info](./docs/modules/metal_ssh_key_info.md)|Gather personal SSH keys|list project SSH keys
[equinix.cloud.metal_project_ssh_key_info](./docs/modules/metal_project_ssh_key_info.md)|Gather project SSH keys|
[equinix.cloud.metal_ssh_key_info](./docs/modules/metal_ssh_key_info.md)|Gather personal SSH keys|
[equinix.cloud.metal_vlan_info](./docs/modules/metal_vlan_info.md)|Gather VLANs.|

Expand Down
73 changes: 73 additions & 0 deletions docs/modules/metal_project_ssh_key.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# metal_project_ssh_key

Manage project ssh key in Equinix Metal. Read more about personal and project SSH keys in [Equinix Metal documentation](https://deploy.equinix.com/developers/docs/metal/accounts/ssh-keys/#personal-keys-vs-project-keys). You can use *id* or *label* to lookup a project SSH key. If you want to create new resource, you must provide *name*, *public_key* and *project_id*.


- [Examples](#examples)
- [Parameters](#parameters)
- [Return Values](#return-values)

## Examples

```yaml
- name: Create new project project ssh_key
hosts: localhost
tasks:
- equinix.cloud.metal_project_ssh_key:
name: "test_key"
public_key: "ssh-dss AAAAB3NzaC1kc3MAAACBAPLEVntPO3L7VUbEwWZ2ErkQJ3KJ8o9kFXJrPcpvVfdNag4jIhQDqbtAUgUy6BclhhbfH9l5nlGTprrpEFkxm/GL91qJUX6xrPkDMjMqx2wSKa4YraReOrCOfkqqEkC3o3G/gYSuvTzLgp2rmPiflypftZyzNM4JZT8jDwFGotJhAAAAFQDPk43bayONtUxjkAcOf+6zP1qb6QAAAIBZHHH0tIlth5ot+Xa/EYuB/M4qh77EkrWUbER0Kki7suskw/ffdKQ0y/v+ZhoAHtBU7BeE3HmP98Vrha1i4cOU+A7DCqV+lK/a+5LoEpua0M2M+VzNSGluYuV4qGpAOxNh3mxUi2R7yXxheN1oks1ROJ/bqkF4BJQXU9Nv49GkZgAAAIByWcsFeOitvzyDaNJOZzEHv9fqGuj0L3maRVWb6O47HGzlMzniIy8WjL2dfgm2/ek+NxVR/yFnYTKDPr6+0uqSD/cb4eHaFbIj7v+k7H8hA1Ioz+duJ1ONAjn6KwneXxOXu15bYIR49P7Go0s9jCdSAP/r9NE5TnE3yiRiQzgEzw== tomk@node"
project_id: "local.project_id"

```

```yaml
- name: Remove project ssh_key by id
hosts: localhost
tasks:
- equinix.cloud.metal_project_ssh_key:
id: "eef49903-7a09-4ca1-af67-4087c29ab5b6"
state: absent

```










## Parameters

| Field | Type | Required | Description |
|-----------|------|----------|------------------------------------------------------------------------------|
| `id` | <center>`str`</center> | <center>Optional</center> | UUID of the ssh_key. |
| `name` | <center>`str`</center> | <center>Optional</center> | The name of the ssh_key. **(Updatable)** |
| `public_key` | <center>`str`</center> | <center>Optional</center> | The public key of the project ssh_key. **(Updatable)** |
| `project_id` | <center>`str`</center> | <center>Optional</center> | The ID of parent project. **(Updatable)** |






## Return Values

- `metal_project_ssh_key` - The module object

- Sample Response:
```json

{
"fingerprint": "98:9c:35:ed:f9:75:5b:52:e2:70:50:22:ea:77:5b:b6",
"id": "eef49903-7a09-4ca1-af67-4087c29ab5b6",
"public_key": "ssh-dss AAAAB3NzaC1kc3MAAACBAPLEVntPO3L7VUbEwWZ2ErkQJ3KJ8o9kFXJrPcpvVfdNag4jIhQDqbtAUgUy6BclhhbfH9l5nlGTprrpEFkxm/GL91qJUX6xrPkDMjMqx2wSKa4YraReOrCOfkqqEkC3o3G/gYSuvTzLgp2rmPiflypftZyzNM4JZT8jDwFGotJhAAAAFQDPk43bayONtUxjkAcOf+6zP1qb6QAAAIBZHHH0tIlth5ot+Xa/EYuB/M4qh77EkrWUbER0Kki7suskw/ffdKQ0y/v+ZhoAHtBU7BeE3HmP98Vrha1i4cOU+A7DCqV+lK/a+5LoEpua0M2M+VzNSGluYuV4qGpAOxNh3mxUi2R7yXxheN1oks1ROJ/bqkF4BJQXU9Nv49GkZgAAAIByWcsFeOitvzyDaNJOZzEHv9fqGuj0L3maRVWb6O47HGzlMzniIy8WjL2dfgm2/ek+NxVR/yFnYTKDPr6+0uqSD/cb4eHaFbIj7v+k7H8hA1Ioz+duJ1ONAjn6KwneXxOXu15bYIR49P7Go0s9jCdSAP/r9NE5TnE3yiRiQzgEzw== tomk@xps",
"name": "test_key",
"project_id": "local.project_id"
}

```


73 changes: 73 additions & 0 deletions docs/modules/metal_project_ssh_key_info.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# metal_project_ssh_key_info

Gather project SSH keys. Read more about project vs project SSH keys in [Equinix Metal documentation](https://metal.equinix.com/developers/docs/accounts/ssh-keys/#personal-keys-vs-project-keys).


- [Examples](#examples)
- [Parameters](#parameters)
- [Return Values](#return-values)

## Examples

```yaml

- set_fact:
desired_name_substring: "tkarasek"

- name: list project ssh keys
equinix.cloud.metal_project_ssh_key_info:
register: ssh_keys_listed

- name: filter found ssh keys
set_fact:
both_ssh_keys_listed: "{{ ssh_keys_listed.resources | selectattr('name', 'match', desired_name_substring) }}"

```










## Parameters

| Field | Type | Required | Description |
|-----------|------|----------|------------------------------------------------------------------------------|
| `name` | <center>`str`</center> | <center>**Required**</center> | Name to search for in existing keys. |






## Return Values

- `resources` - Found resources

- Sample Response:
```json

[
{
"fingerprint": "70:c1:73:8b:3f:2f:a4:18:ea:4d:79:13:52:7b:c4:3e",
"id": "6edfcbc2-17e5-4221-9eac-2f40dbe60daf",
"key": "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAt5gwVMhwcCrxyxpMEKwiS0xgit3PIIEgVXt6SQHc8eONq0mYJJ5TOBNTnySqXd9RtSv/Jbf5Aq9BzBGWeoZ6sZfKwh984Ip35StJtjXtyIOlY3skovndtupBIwlGXgX/WQzyLr+G/+Yu9/nhdxQi801PDZnDvKoeomM0rMD29nV+m0ud+GrtsAt6VFul2PxqpypZ1TYviyED6IKo7rgQsQDkE9QHcNdfT1FZWiJbfP7o8TIurQJcAXg+MtLoc8rKKcxFMeZ9FSydgtTC7nP1h558RtECGWiUgaBPI7TpBmcdMtbEfAiBoGT17GWnT8qmy2u5xnEKPD9Qft4w4fjfpw==",
"label": "tkarasek",
"project_id": local.project_id
},
{
"fingerprint": "ba:70:af:b3:0f:0e:7f:e5:eb:97:e2:27:b1:f5:6f:94",
"id": "d00c596d-b42a-44a7-ac14-e299b85e73d3",
"key": "ssh-dss AAAAB3NzaC1kc3MAAACBAOpXVtmc0Bla98bt0o5/Zj7sb4mHIukgVFZu7F32R3VK1cEKB4rEE8uS0oLS/qMRLue45TWVJwRMYGlPjt3p/VyraelxoyJZLuITIsqa5hBc9w0oTlB5Bmbkn16umW96WCaWEoq/aitpocbRChTiP5biI6FyQTQlIHDaYzBDOi11AAAAFQDUXy7cmuzphDpJSYYTiudiUhVokwAAAIEAyUQ9m8qL/1HPkFe6jbXAvtSSmW27F4c+G2xR5HizaHQzXgBOxPcsOsY17KTU+Ddbg+OF9soWNwSpm9pyVjVmNGqH3S8R1pwvuJF/O2Asy1m6wpWhbPw8JdEBW7WHoptBpfuzJoS2LOzJUEmUu4Eb+xS237KG1d1BVny/49KAoH0AAACBAJKBSsm9Xey0fUN6vYtTQgoYeGxxj/LqAIAOs/TpCxZDntly860y/SzHYai8x48k4t7whENY1CJ41fpMcPlz8xIsrNP3326Wbr0ExwOIvJKAVN1YLYqF8NXWzaVrjo5WbSeI8PiWTYemvLAujVxZssIrApTZBhp55nnwge6K1zTG tomk@air",
"label": "ansible-integration-test-ssh_key-ztiapihf-ssh_key1_renamed",
"project_id": local.project_id
}
]

```


10 changes: 9 additions & 1 deletion plugins/module_utils/metal/api_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ def get_routes(mpc):
('metal_ssh_key', action.LIST): spec_types.Specs(
equinix_metal.SSHKeysApi(mpc).find_ssh_keys,
),
('metal_project_ssh_key', action.LIST): spec_types.Specs(
equinix_metal.SSHKeysApi(mpc).find_project_ssh_keys,
{'id': 'project_id'}
),
('metal_organization', action.LIST): spec_types.Specs(
equinix_metal.OrganizationsApi(mpc).find_organizations,
{'personal': 'personal', 'with_projects': 'with_projects'},
Expand Down Expand Up @@ -130,7 +134,6 @@ def get_routes(mpc):
equinix_metal.VLANsApi(mpc).delete_virtual_network,
),


# CREATORS
('metal_device', action.CREATE): spec_types.Specs(
equinix_metal.DevicesApi(mpc).create_device,
Expand Down Expand Up @@ -162,6 +165,11 @@ def get_routes(mpc):
{},
equinix_metal.SSHKeyCreateInput,
),
('metal_project_ssh_key', action.CREATE): spec_types.Specs(
equinix_metal.SSHKeysApi(mpc).create_project_ssh_key,
{'id': 'project_id'},
equinix_metal.SSHKeyCreateInput,
),
('metal_vlan', action.CREATE): spec_types.Specs(
equinix_metal.VLANsApi(mpc).create_virtual_network,
{'id': 'project_id'},
Expand Down
Loading

0 comments on commit 2a64e13

Please sign in to comment.