equinix.metal.device (1.4.1) — module

Manage a bare metal server in Equinix Metal

| "added in version" 1.1.0 of equinix.metal"

Authors: Tomas Karasek (@t0mk) <tom.to.the.k@gmail.com>, Matt Baldwin (@baldwinSPC) <baldwin@stackpointcloud.com>, Thibaud Morel l'Horset (@teebes) <teebes@gmail.com>, Jason DeTiberus (@detiber) <jdetiberus@equinix.com>

Install collection

Install with ansible-galaxy collection install equinix.metal:==1.4.1


Add to requirements.yml

  collections:
    - name: equinix.metal
      version: 1.4.1

Description

Manage a bare metal server in Equinix Metal (a "device" in the API terms).

When the machine is created it can optionally wait for public IP address, or for active state.

API is documented at U(https://metal.equinix.com/developers/api/devices/).


Requirements

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# All the examples assume that you have your Equinix Metal API token in env var METAL_API_TOKEN.
# You can also pass it to the api_token parameter of the module instead.

# Creating devices

- name: Create 1 device
  hosts: localhost
  tasks:
  - equinix.metal.device:
      project_id: 89b497ee-5afc-420a-8fb5-56984898f4df
      hostnames: myserver
      tags: ci-xyz
      operating_system: ubuntu_16_04
      plan: baremetal_0
      facility: sjc1
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Create the same device and wait until it is in state "active", (when it's
# ready for other API operations). Fail if the device is not "active" in
# 10 minutes.

- name: Create device and wait up to 10 minutes for active state
  hosts: localhost
  tasks:
  - equinix.metal.device:
      project_id: 89b497ee-5afc-420a-8fb5-56984898f4df
      hostnames: myserver
      operating_system: ubuntu_16_04
      plan: baremetal_0
      facility: sjc1
      state: active
      wait_timeout: 600
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Create 3 ubuntu devices called server-01, server-02 and server-03
  hosts: localhost
  tasks:
  - equinix.metal.device:
      project_id: 89b497ee-5afc-420a-8fb5-56984898f4df
      hostnames: server-%02d
      count: 3
      operating_system: ubuntu_16_04
      plan: baremetal_0
      facility: sjc1
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Create 3 coreos devices with userdata, wait until they get IPs and then wait for SSH
  hosts: localhost
  tasks:
  - name: Create 3 devices and register their facts
    equinix.metal.device:
      hostnames: [coreos-one, coreos-two, coreos-three]
      operating_system: coreos_stable
      plan: baremetal_0
      facility: ewr1
      locked: true
      project_id: 89b497ee-5afc-420a-8fb5-56984898f4df
      wait_for_public_IPv: 4
      user_data: |
        #cloud-config
        ssh_authorized_keys:
          - {{ lookup('file', 'my_equinix_metal_sshkey') }}
        coreos:
          etcd:
            discovery: https://discovery.etcd.io/6a28e078895c5ec737174db2419bb2f3
            addr: $private_ipv4:4001
            peer-addr: $private_ipv4:7001
          fleet:
            public-ip: $private_ipv4
          units:
            - name: etcd.service
              command: start
            - name: fleet.service
              command: start
    register: newhosts

  - name: Wait for ssh
    ansible.builtin.wait_for:
      delay: 1
      host: "{{ item.public_ipv4 }}"
      port: 22
      state: started
      timeout: 500
    with_items: "{{ newhosts.devices }}"
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.

# Other states of devices

- name: Remove 3 devices by uuid
  hosts: localhost
  tasks:
  - equinix.metal.device:
      project_id: 89b497ee-5afc-420a-8fb5-56984898f4df
      state: absent
      device_ids:
        - 1fb4faf8-a638-4ac7-8f47-86fe514c30d8
        - 2eb4faf8-a638-4ac7-8f47-86fe514c3043
        - 6bb4faf8-a638-4ac7-8f47-86fe514c301f

Inputs

    
plan:
    description:
    - Plan slug for device creation. See Equinix Metal API for current list - U(https://metal.equinix.com/developers/api/plans/).
    type: str

tags:
    description:
    - List of device tags.
    - Currently implemented only for device creation.
    elements: str
    type: list

count:
    default: 1
    description:
    - The number of devices to create. Count number can be included in hostname via the
      %d string formatter.
    type: int

state:
    choices:
    - present
    - absent
    - active
    - inactive
    - rebooted
    default: present
    description:
    - Desired state of the device.
    - If set to C(present) (the default), the module call will return immediately after
      the device-creating HTTP request successfully returns.
    - If set to C(active), the module call will block until all the specified devices
      are in state active, or until I(wait_timeout).
    type: str

locked:
    aliases:
    - lock
    default: false
    description:
    - Whether to lock a created device.
    type: bool

facility:
    description:
    - Facility slug for device creation. See the Equinix Metal API for current list -
      U(https://metal.equinix.com/developers/api/facilities/).
    type: str

features:
    description:
    - Dict with "features" for device creation. See Equinix Metal API docs for details.
    type: dict

api_token:
    aliases:
    - auth_token
    description:
    - The Equinix Metal API token to use
    - If not set, then the value of the METAL_API_TOKEN, PACKET_API_TOKEN, or PACKET_TOKEN
      environment variable is used.
    required: true
    type: str

hostnames:
    aliases:
    - name
    description:
    - A hostname of a device, or a list of hostnames.
    - If given string or one-item list, you can use the C("%d") Python string format to
      expand numbers from I(count).
    - If only one hostname, it might be expanded to list if I(count)>1.
    elements: str
    type: list

user_data:
    description:
    - Userdata blob made available to the machine
    type: str

always_pxe:
    default: false
    description:
    - Persist PXE as the first boot option.
    - Normally, the PXE process happens only on the first boot. Set this arg to have your
      device continuously boot to iPXE.
    type: bool

device_ids:
    description:
    - List of device IDs on which to operate.
    elements: str
    type: list

project_id:
    description:
    - Project ID.
    required: true
    type: str

count_offset:
    default: 1
    description:
    - From which number to start the count.
    type: int

wait_timeout:
    default: 900
    description:
    - How long (seconds) to wait either for automatic IP address assignment, or for the
      device to reach the C(active) I(state).
    - If I(wait_for_public_IPv) is set and I(state) is C(active), the module will wait
      for both events consequently, applying the timeout twice.
    type: int

ipxe_script_url:
    description:
    - URL of custom iPXE script for provisioning.
    - More about custom iPXE for Equinix Metal devices at U(https://metal.equinix.com/developers/docs/operating-systems/custom-ipxe/).
    type: str

operating_system:
    description:
    - OS slug for device creation. See Equinix Metal API for current list - U(https://metal.equinix.com/developers/api/operatingsystems/).
    type: str

wait_for_public_IPv:
    choices:
    - 4
    - 6
    description:
    - Whether to wait for the instance to be assigned a public IPv4/IPv6 address.
    - If set to 4, it will wait until IPv4 is assigned to the instance.
    - If set to 6, wait until public IPv6 is assigned to the instance.
    type: int

Outputs

changed:
  description: True if a device was altered in any way (created, modified or removed)
  returned: success
  sample: true
  type: bool
devices:
  description: Information about each device that was processed
  returned: success
  sample: '[{"hostname": "my-server.com", "id": "2a5122b9-c323-4d5c-b53c-9ad3f54273e7",
    "public_ipv4": "147.229.15.12", "private-ipv4": "10.0.15.12", "tags": [], "locked":
    false, "state": "provisioning", "public_ipv6": ""2604:1380:2:5200::3"}]'
  type: list