community.general.packet_device 模块 – 管理 Packet 主机中的裸金属服务器
注意
此模块是 community.general 集合(版本 10.1.0)的一部分。
如果您正在使用 ansible
包,您可能已经安装了此集合。它不包含在 ansible-core
中。要检查是否已安装,请运行 ansible-galaxy collection list
。
要安装它,请使用:ansible-galaxy collection install community.general
。您需要进一步的要求才能使用此模块,请参阅 要求 了解详细信息。
要在剧本中使用它,请指定:community.general.packet_device
。
概要
管理 Packet 主机中的裸金属服务器(API 术语中的“设备”)。
创建机器时,可以选择等待公共 IP 地址或等待活动状态。
此模块依赖于 packet >= 1.0。
要求
在执行此模块的主机上需要以下要求。
packet-python >= 1.35
参数
参数 |
注释 |
---|---|
将 PXE 保留为第一个启动选项。 通常,PXE 进程仅在第一次启动时发生。设置此参数可使您的设备持续启动到 iPXE。 选择
|
|
Packet API 令牌。您也可以在环境变量 |
|
要创建的设备数量。计数编号可以通过 %d 字符串格式化程序包含在主机名中。 默认值: |
|
从哪个数字开始计数。 默认值: |
|
要操作的设备 ID 列表。 |
|
用于设备创建的设施别名。有关当前列表,请参阅 Packet API - https://www.packet.net/developers/api/facilities/。 |
|
用于设备创建的包含“功能”的字典。有关详细信息,请参阅 Packet API 文档。 |
|
用于配置的自定义 iPXE 脚本的 URL。 有关 Packet 设备自定义 iPXE 的更多信息,请访问 https://help.packet.net/technical/infrastructure/custom-ipxe。 默认值: |
|
是否锁定创建的设备。 选择
|
|
用于设备创建的操作系统别名。有关当前列表,请参阅 Packet API - https://www.packet.net/developers/api/operatingsystems/。 |
|
用于设备创建的计划别名。有关当前列表,请参阅 Packet API - https://www.packet.net/developers/api/plans/。 |
|
设备的 Project ID。 |
|
设备的所需状态。 如果设置为 如果设置为 选择
|
|
设备标签列表。 目前仅在设备创建时实现。 |
|
提供给机器的用户数据 Blob |
|
是否等待实例分配到公共 IPv4/IPv6 地址。 如果设置为 4,它将等待直到 IPv4 被分配给实例。 如果设置为 6,则等待直到公共 IPv6 被分配给实例。 选择
|
|
等待自动分配 IP 地址或设备达到 如果设置了 默认值: |
属性
属性 |
支持 |
描述 |
---|---|---|
支持: 无 |
可以在 |
|
支持: 无 |
在差异模式下,将返回已更改(或可能需要在 |
示例
# All the examples assume that you have your Packet API token in environment variable 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:
- community.general.packet_device:
project_id: 89b497ee-5afc-420a-8fb5-56984898f4df
hostnames: myserver
tags: ci-xyz
operating_system: ubuntu_16_04
plan: baremetal_0
facility: sjc1
# 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:
- community.general.packet_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
- name: Create 3 ubuntu devices called server-01, server-02 and server-03
hosts: localhost
tasks:
- community.general.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
community.general.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
wait_for_public_IPv: 4
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
ansible.builtin.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:
- community.general.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
返回值
常见返回值记录在此处 此处,以下是此模块特有的字段
键 |
描述 |
---|---|
如果设备以任何方式被更改(创建、修改或删除),则为 True 返回:成功 示例: |
|
有关已处理的每个设备的信息 返回:成功 示例: |