Skip to content

Commit

Permalink
Equinix cloud package update from Equinix Metal (#7769)
Browse files Browse the repository at this point in the history
* Update requirements.yml to add equinix.cloud

* Update requirements.txt to ansible-specdoc

* Update metal project on create

* Update create_project.yaml

* Update delete_project.yaml

* Update main.yaml

* Update requirements.txt to add equinix_metal

* Update create_project.yaml for metal_api_token

* Update delete_project.yaml for metal_api_token

* Update create_instances.yaml for metal_api_token

* Update main.yaml for metal_api_token

* Update delete_instances.yaml for equinix.cloud.metal_device

* Update create_instances.yaml to have hostname and userdata

* Update create_instances.yaml for wait_for_public_IPv remove

* Update nested_loop.yml for IP

* Update nested_loop.yml boolean

* Update nested_loop.yml trying first element

* Update nested_loop.yml

* Update nested_loop.yml debugging

* Update nested_loop.yml debug logging

* Update nested_loop.yml

* Update nested_loop.yml

* Update nested_loop.yml results

* Update main.yml debug

* Update main.yml

* Update nested_loop.yml

* Update nested_loop.yml results

* Update nested_loop.yml trying

* Update nested_loop.yml new search

* Update nested_loop.yml address

* Try without nested 'devices'

* Update nested_loop.yml

* add pipe

* Patch the inventory to work with new module

* remove devices[]

* Remove backquotes for true

* Fix jsonquery search string

* Add provisioning_wait_seconds and metro|default(omit)

* take out facility

* Remove 'omit' and add value instead

---------

Co-authored-by: Billy Bethell <[email protected]>
Co-authored-by: Guillaume Coré <[email protected]>
  • Loading branch information
3 people authored Apr 2, 2024
1 parent 53f43ca commit ed31b1d
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 28 deletions.
2 changes: 1 addition & 1 deletion ansible/roles-infra/infra-dns/tasks/nested_loop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{%- if cloud_provider == 'osp' -%}
openstack_servers[?name=='{{ _instance_name }}'].public_v4 | [0]
{%- elif cloud_provider == 'equinix_metal' -%}
results[].devices[?hostname=='{{ _instance_name }}'].public_ipv4[]|[0]
results[?hostname=='{{ _instance_name }}']|[0].ip_addresses[?public==`true` && address_family==`4`].address|[0]
{%- elif cloud_provider == 'vmc' or cloud_provider == 'vmware_ibm' -%}
localhost.publicips[?name=='{{ _instance_name }}'].ip
{%- endif -%}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,21 @@
when:
- item.tags
- '"bastions" in item.tags'
loop: "{{ r_equinix_metal_devices | json_query('results[].devices[]') | list }}"
loop: "{{ r_equinix_metal_devices | json_query('results[]') | list }}"
loop_control:
label: "{{ item.hostname | default(item.id) }}"
ignore_errors: true

- name: Create inventory (add_host)
loop: "{{ r_equinix_metal_devices | json_query('results[].devices[]') | list }}"
loop: "{{ r_equinix_metal_devices | json_query('results[]') | list }}"
loop_control:
label: "{{ item.hostname | default(item.id) }}"
add_host:
name: "{{ item.hostname }}"
shortname: "{{ item.hostname }}"
private_ip_address: "{{ item.private_ipv4 }}"
public_ip_address: "{{ item.public_ipv4 }}"
public_ip6_address: "{{ item.public_ipv6 | default(omit) }}"
private_ip_address: "{{ item | json_query('ip_addresses[?(public==`false` && address_family == `4`)].address|[0]') }}"
public_ip_address: "{{ item | json_query('ip_addresses[?public==`true` && address_family == `4`].address|[0]') }}"
public_ip6_address: "{{ item | json_query('ip_addresses[?public==`true` && address_family == `6`].address|[0]') }}"
groups: "{{ (item.tags | equinix_metal_tags_to_dict).AnsibleGroup }}"
bastion: "{{ local_bastion | default('') }}"
isolated: >-
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
until: r_projects is succeeded

- name: Test project module
equinix.metal.project:
auth_token: "{{ equinix_metal_api_token }}"
equinix.cloud.metal_project:
metal_api_token: "{{ equinix_metal_api_token }}"
name: ThisProjectDoesntExist
state: absent
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,20 @@
label: _instance.name
vars:
equinix.cloud.metal_device:
wait_for_public_IPv: 4
auth_token: "{{ equinix_metal_api_token }}"
metal_api_token: "{{ equinix_metal_api_token }}"
project_id: "{{ equinix_metal_project_id }}"
hostnames: >-
hostname: >-
{{ _instance.name }}
{%- if _instance.count | int > 1 -%}
{{ equinix_metal_instance_numeration }}
{%- endif -%}
count: "{{ _instance.count }}"
operating_system: "{{ _instance.os | default(equinix_metal_default_os) }}"
plan: "{{ _instance.type }}"
metro: "any"
# facility: "{{ omit if _instance.facility == 'any' else _instance.facility }}"
provisioning_wait_seconds: "{{ equinix_metal_provisioning_wait_seconds | default(300) }}"
metro: "{{ _instance.metro | default(equinix_metal_metro) | default('any') }}"
tags: >-
{{ cloud_tags_final
| combine(_instance.tags | ec2_tags_to_dict)
| dict_to_equinix_metal_tags }}
user_data: |
userdata: |
#cloud-config
ssh_authorized_keys:
- {{ lookup('file', equinix_metal_ssh_pub_key_path ) }}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
---
- name: Create Equinix Metal project
equinix.metal.project:
auth_token: "{{ equinix_metal_api_token }}"
equinix.cloud.metal_project:
metal_api_token: "{{ equinix_metal_api_token }}"
name: "{{ equinix_metal_project_name }}"
org_id: "{{ equinix_metal_organization_id }}"
payment_method: "{{ equinix_metal_payment_method_id }}"
organization_id: "{{ equinix_metal_organization_id }}"
payment_method_id: "{{ equinix_metal_payment_method_id }}"
register: r_project

- name: Save Project id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

- name: Delete all devices
when: r_equinix_metal_devices.json.devices | default([]) | length > 0
equinix.metal.device:
auth_token: "{{ equinix_metal_api_token }}"
equinix.cloud.metal_device:
metal_api_token: "{{ equinix_metal_api_token }}"
project_id: "{{ equinix_metal_project_ids[0] }}"
state: absent
device_ids: >-
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
- name: Delete Equinix Metal project
equinix.metal.project:
auth_token: "{{ equinix_metal_api_token }}"
equinix.cloud.metal_project:
metal_api_token: "{{ equinix_metal_api_token }}"
id: "{{ equinix_metal_project_id }}"
org_id: "{{ equinix_metal_organization_id }}"
organization_id: "{{ equinix_metal_organization_id }}"
state: absent
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
ansible-core
ansible-runner
ansible-specdoc
boto3>=1.18.0
botocore>=1.21.0
cryptography
dnspython
equinix_metal
dumb-init
jsonpatch
kubernetes>=12.0.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ collections:

- name: containers.podman

# packet-python>=1.43.1
- name: equinix.metal
# equinix.cloud instead of equinix_metal
- name: equinix.cloud

# requirements.txt from the collection
- name: google.cloud
Expand Down

0 comments on commit ed31b1d

Please sign in to comment.