theforeman.foreman.host_power 模块 – 管理主机的电源状态

注意

此模块是 theforeman.foreman 集合 (版本 4.2.0) 的一部分。

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

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

要在剧本中使用它,请指定: theforeman.foreman.host_power

theforeman.foreman 1.0.0 中的新增功能

概要

  • 管理主机的电源状态

  • 此测试版可以启动和停止现有的 Foreman 主机并查询当前的电源状态。

别名:foreman_host_power

要求

执行此模块的主机需要以下要求。

  • requests

参数

参数

注释

name

别名:hostname

字符串 / 必需

主机的名称(FQDN)

password

字符串 / 必需

访问 Foreman 服务器的用户的密码。

如果任务中未指定此值,则将使用环境变量 FOREMAN_PASSWORD 的值。

server_url

字符串 / 必需

Foreman 服务器的 URL。

如果任务中未指定此值,则将使用环境变量 FOREMAN_SERVER_URL 的值。

state

字符串

所需的电源状态

选项

  • "on"

  • "start"

  • "off"

  • "stop"

  • "soft"

  • "reboot"

  • "cycle"

  • "reset"

  • "state" ← (默认)

  • "status"

username

字符串 / 必需

访问 Foreman 服务器的用户名。

如果任务中未指定此值,则将使用环境变量 FOREMAN_USERNAME 的值。

validate_certs

布尔值

是否验证 Foreman 服务器的 TLS 证书。

如果任务中未指定此值,则将使用环境变量 FOREMAN_VALIDATE_CERTS 的值。

选项

  • false

  • true ← (默认)

属性

属性

支持

描述

check_mode

支持:完全支持

可以在 check_mode 下运行,并在不修改实体的情况下返回更改状态预测

diff_mode

支持:完全支持

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

示例

- name: "Switch a host on"
  theforeman.foreman.host_power:
    username: "admin"
    password: "changeme"
    server_url: "https://foreman.example.com"
    hostname: "test-host.domain.test"
    state: 'on'

- name: "Switch a host off"
  theforeman.foreman.host_power:
    username: "admin"
    password: "changeme"
    server_url: "https://foreman.example.com"
    hostname: "test-host.domain.test"
    state: 'off'

- name: "Query host power state"
  theforeman.foreman.host_power:
    username: "admin"
    password: "changeme"
    server_url: "https://foreman.example.com"
    hostname: "test-host.domain.test"
    state: state
    register: result
- debug:
    msg: "Host power state is {{ result.power_state }}"

返回值

常见的返回值已在 此处 记录,以下是此模块特有的字段

描述

power_state

字符串

主机的当前电源状态

返回:始终

示例: "off"

作者

  • Bernhard Hopfenmueller (@Fobhep) ATIX AG

  • Baptiste Agasse (@bagasse)