community.general.linode 模块 – 管理 Linode 公有云上的实例

注意

此模块是 community.general 集合 (版本 10.1.0) 的一部分。

如果您正在使用 ansible 包,则可能已安装此集合。它不包含在 ansible-core 中。要检查它是否已安装,请运行 ansible-galaxy collection list

要安装它,请使用:ansible-galaxy collection install community.general。您需要其他要求才能使用此模块,有关详细信息,请参见 要求

要在剧本中使用它,请指定:community.general.linode

概要

  • 管理 Linode 公有云实例,并可选择等待其状态变为“运行”。

要求

以下要求是在执行此模块的主机上所需的。

  • linode-python

参数

参数

注释

additional_disks

列表 / 元素=字典

用于创建添加到 Linode 配置设置的附加磁盘的字典列表。

字典包含大小、标签、类型。大小以 MB 为单位。

alert_bwin_enabled

布尔值

设置带宽警报的状态。

选项

  • false

  • true

alert_bwin_threshold

整数

设置带宽警报的阈值(以 MB 为单位)。

alert_bwout_enabled

布尔值

设置带宽输出警报的状态。

选项

  • false

  • true

alert_bwout_threshold

整数

设置带宽输出警报的阈值(以 MB 为单位)。

alert_bwquota_enabled

布尔值

设置带宽配额警报的状态,以网络传输配额的百分比表示。

选项

  • false

  • true

alert_bwquota_threshold

整数

设置带宽配额警报的阈值(以 MB 为单位)。

alert_cpu_enabled

布尔值

设置接收 CPU 使用率警报的状态。

选项

  • false

  • true

alert_cpu_threshold

整数

设置接收 CPU 使用率警报的百分比阈值。每个 CPU 内核都会将总计增加 100%。

alert_diskio_enabled

布尔值

设置接收磁盘 IO 警报的状态。

选项

  • false

  • true

alert_diskio_threshold

整数

设置 2 小时内平均 IO ops/sec 的阈值。

api_key

字符串 / 必需

Linode API 密钥。

LINODE_API_KEY 环境变量可以替代使用。

backupweeklyday

整数

进行备份的星期几。

backupwindow

整数

进行备份的时间窗口。

datacenter

整数

创建实例的数据中心(Linode 数据中心)

displaygroup

字符串

将实例添加到 Linode Manager 中的显示组。

默认值: ""

distribution

整数

要用于实例的发行版(Linode 发行版)

kernel_id

整数

要用于实例的内核(Linode 内核)

linode_id

别名:lid

整数

Linode 服务器的唯一 ID。此值在创建 Linode 时是只读的,因为它不会被使用。Linode API 生成这些 ID,我们可以在这里使用生成的这些值来更具体地引用 Linode。这对于幂等性非常有用。

name

字符串 / 必需

要赋予实例的名称(字母数字、短划线、下划线)。

为了保持 Linode Web 控制台的一致性,名称前缀为 LinodeID-

password

字符串

要应用于新服务器的 root 密码(如果缺少则自动生成)

payment_term

整数

要用于实例的付款期限(以月为单位)

选项

  • 1 ← (默认)

  • 12

  • 24

plan

整数

要用于实例的计划(Linode 计划)

private_ip

布尔值

创建 Linode 时添加私有 IPv4 地址。

默认为 false

选项

  • false

  • true

ssh_pub_key

字符串

应用于 root 用户的 SSH 公钥

state

字符串

指示所需资源状态

选项

  • "absent"

  • "active"

  • "deleted"

  • "present" ← (默认)

  • "restarted"

  • "started"

  • "stopped"

swap

整数

交换空间大小(以 MB 为单位)

默认值: 512

wait

布尔值

等待实例处于 running 状态后再返回

选项

  • false

  • true ← (默认)

wait_timeout

整数

等待超时时间(秒)

默认值: 300

watchdog

布尔值

设置 Lassie 看门狗的状态。

选项

  • false

  • true ← (默认)

属性

属性

支持

描述

check_mode

支持:

可在check_mode下运行,并在不修改目标的情况下返回更改状态预测。

diff_mode

支持:

在diff模式下,将返回有关已更改内容(或在check_mode下可能需要更改的内容)的详细信息。

备注

注意

  • 请注意,linode-python 不支持 Python 3。

  • 此模块使用现已弃用的 Linode API v3。

  • 请查看https://www.linode.com/api/linode 以确定所需的参数。

示例

- name: Create a new Linode
  community.general.linode:
    name: linode-test1
    plan: 1
    datacenter: 7
    distribution: 129
    state: present
  register: linode_creation

- name: Create a server with a private IP Address
  community.general.linode:
     module: linode
     api_key: 'longStringFromLinodeApi'
     name: linode-test1
     plan: 1
     datacenter: 2
     distribution: 99
     password: 'superSecureRootPassword'
     private_ip: true
     ssh_pub_key: 'ssh-rsa qwerty'
     swap: 768
     wait: true
     wait_timeout: 600
     state: present
  delegate_to: localhost
  register: linode_creation

- name: Fully configure new server
  community.general.linode:
     api_key: 'longStringFromLinodeApi'
     name: linode-test1
     plan: 4
     datacenter: 2
     distribution: 99
     kernel_id: 138
     password: 'superSecureRootPassword'
     private_ip: true
     ssh_pub_key: 'ssh-rsa qwerty'
     swap: 768
     wait: true
     wait_timeout: 600
     state: present
     alert_bwquota_enabled: true
     alert_bwquota_threshold: 80
     alert_bwin_enabled: true
     alert_bwin_threshold: 10
     alert_cpu_enabled: true
     alert_cpu_threshold: 210
     alert_bwout_enabled: true
     alert_bwout_threshold: 10
     alert_diskio_enabled: true
     alert_diskio_threshold: 10000
     backupweeklyday: 1
     backupwindow: 2
     displaygroup: 'test'
     additional_disks:
      - {Label: 'disk1', Size: 2500, Type: 'raw'}
      - {Label: 'newdisk', Size: 2000}
     watchdog: true
  delegate_to: localhost
  register: linode_creation

- name: Ensure a running server (create if missing)
  community.general.linode:
     api_key: 'longStringFromLinodeApi'
     name: linode-test1
     plan: 1
     datacenter: 2
     distribution: 99
     password: 'superSecureRootPassword'
     ssh_pub_key: 'ssh-rsa qwerty'
     swap: 768
     wait: true
     wait_timeout: 600
     state: present
  delegate_to: localhost
  register: linode_creation

- name: Delete a server
  community.general.linode:
     api_key: 'longStringFromLinodeApi'
     name: linode-test1
     linode_id: "{{ linode_creation.instance.id }}"
     state: absent
  delegate_to: localhost

- name: Stop a server
  community.general.linode:
     api_key: 'longStringFromLinodeApi'
     name: linode-test1
     linode_id: "{{ linode_creation.instance.id }}"
     state: stopped
  delegate_to: localhost

- name: Reboot a server
  community.general.linode:
     api_key: 'longStringFromLinodeApi'
     name: linode-test1
     linode_id: "{{ linode_creation.instance.id }}"
     state: restarted
  delegate_to: localhost

作者

  • Vincent Viallet (@zbal)