Documentation

packet_device - create, destroy, start, stop, and reboot a Packet Host machine.

New in version 2.3.

Synopsis

Requirements (on host that executes module)

  • packet-python
  • python >= 2.6

Options

parameter required default choices comments
auth_token
no
Packet api token. You can also supply it in env var PACKET_API_TOKEN.
count
no
The number of devices to create. Count number can be included in hostname via the %d string formatter.
count_offset
no
From which number to start the count.
device_ids
no
List of device IDs on which to operate.
facility
no
Facility slug for device creation. As of 2016, it should be one of [ewr1, sjc1, ams1, nrt1].
features
no
Dict with "features" for device creation. See Packet API docs for details.
hostnames
no
A hostname of a device, or a list of hostnames.
If given string or one-item list, you can use the "%d" Python string format to expand numbers from count.
If only one hostname, it might be expanded to list if count>1.

aliases: name
lock
no
Whether to lock a created device.
operating_system
no
OS slug for device creation. See Packet docs or API for current list.
plan
no
Plan slug for device creation. See Packet docs or API for current list.
project_id
yes
ID of project of the device.
state
no present
  • present
  • absent
  • active
  • inactive
  • rebooted
Desired state of the device.
user_data
no None
Userdata blob made available to the machine
wait
no
  • yes
  • no
Whether to wait for the instance to be assigned IP address before returning.
wait_timeout
no 60
How long to wait for IP address of new devices before quitting. In seconds.

Examples

# All the examples assume that you have your Packet api token in env var PACKET_API_TOKEN.
# You can also pass it to the auth_token parameter of the module instead.

# Creating devices

- name: create 1 device
  hosts: localhost
  tasks:
  - packet_device:
      project_id: 89b497ee-5afc-420a-8fb5-56984898f4df
      hostnames: myserver
      operating_system: ubuntu_16_04
      plan: baremetal_0
      facility: sjc1

- name: create 3 ubuntu devices called server-01, server-02 and server-03
  hosts: localhost
  tasks:
  - packet_device:
      project_id: 89b497ee-5afc-420a-8fb5-56984898f4df
      hostnames: server-%02d
      count: 3
      operating_system: ubuntu_16_04
      plan: baremetal_0
      facility: sjc1

- 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
    packet_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
      user_data: |
        #cloud-config
        ssh_authorized_keys:
          - {{ lookup('file', 'my_packet_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
    wait_for:
      delay: 1
      host: "{{ item.public_ipv4 }}"
      port: 22
      state: started
      timeout: 500
    with_items: "{{ newhosts.devices }}"


# Other states of devices

- name: remove 3 devices by uuid
  hosts: localhost
  tasks:
  - packet_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

Return Values

Common return values are documented here Return Values, the following are the fields unique to this module:

name description returned type sample
changed True if a device was altered in any way (created, modified or removed) always bool True
devices Information about each device that was processed always array [{"hostname": "my-server.com", "id": "server-id", "public-ipv4": "147.229.15.12", "private-ipv4": "10.0.15.12", "public-ipv6": ""2604:1380:2:5200::3"}]


Status

This module is flagged as preview which means that it is not guaranteed to have a backwards compatible interface.

Support

This module is community maintained without core committer oversight.

For more information on what this means please read Module Support

For help in developing on modules, should you be so inclined, please read Community Information & Contributing, Helping Testing PRs and Developing Modules.