1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

HP and vsphere modules are crazy awesome but I am thinking these belong in contrib not core.

This commit is contained in:
Michael DeHaan 2012-10-12 17:49:48 -04:00
parent 85d6af637a
commit aa98c84a62
8 changed files with 20 additions and 482 deletions

View file

@ -63,13 +63,10 @@ New Modules:
* ini_file module for manipulating INI files
* new LSB facts (release, distro, etc)
* new VMware ESX facts module (use with local_action or delegate_to)
* new HP ILO facts module (use with local_action or delegate_to)
* pause module -- (pause seconds=10) (pause minutes=1) (pause prompt=foo) -- it's an action plugin
* a module for adding entries to the main crontab (though you may still wish to just drop template files into cron.d)
* debug module can be used for outputing messages without using 'shell echo'
* a fail module is now available for causing errors, you might want to use it with only_if to fail in certain conditions
* virt_boot -- creates new virtual machines with libvirt
Other module Changes, Upgrades, and Fixes:

View file

@ -2,12 +2,12 @@
.\" Title: ansible-playbook
.\" Author: [see the "AUTHOR" section]
.\" Generator: DocBook XSL Stylesheets v1.75.2 <http://docbook.sf.net/>
.\" Date: 09/06/2012
.\" Date: 10/12/2012
.\" Manual: System administration commands
.\" Source: Ansible 0.8
.\" Language: English
.\"
.TH "ANSIBLE\-PLAYBOOK" "1" "09/06/2012" "Ansible 0\&.8" "System administration commands"
.TH "ANSIBLE\-PLAYBOOK" "1" "10/12/2012" "Ansible 0\&.8" "System administration commands"
.\" -----------------------------------------------------------------
.\" * set default formatting
.\" -----------------------------------------------------------------
@ -120,6 +120,15 @@ The following environment variables may specified\&.
ANSIBLE_HOSTS \(em Override the default ansible hosts file
.sp
ANSIBLE_LIBRARY \(em Override the default ansible module library path
.SH "FILES"
.sp
/etc/ansible/hosts \(em Default inventory file
.sp
/usr/share/ansible/ \(em Default module library
.sp
/etc/ansible/ansible\&.conf \(em Config file, used if present
.sp
~/\&.ansible\&.config \(em User config file, overrides the default config if present
.SH "AUTHOR"
.sp
Ansible was originally written by Michael DeHaan\&. See the AUTHORS file for a complete list of contributors\&.

View file

@ -2,12 +2,12 @@
.\" Title: ansible
.\" Author: [see the "AUTHOR" section]
.\" Generator: DocBook XSL Stylesheets v1.75.2 <http://docbook.sf.net/>
.\" Date: 10/10/2012
.\" Date: 10/12/2012
.\" Manual: System administration commands
.\" Source: Ansible 0.8
.\" Language: English
.\"
.TH "ANSIBLE" "1" "10/10/2012" "Ansible 0\&.8" "System administration commands"
.TH "ANSIBLE" "1" "10/12/2012" "Ansible 0\&.8" "System administration commands"
.\" -----------------------------------------------------------------
.\" * set default formatting
.\" -----------------------------------------------------------------
@ -166,6 +166,10 @@ Ranges of hosts are also supported\&. For more information and additional option
/etc/ansible/hosts \(em Default inventory file
.sp
/usr/share/ansible/ \(em Default module library
.sp
/etc/ansible/ansible\&.conf \(em Config file, used if present
.sp
~/\&.ansible\&.config \(em User config file, overrides the default config if present
.SH "ENVIRONMENT"
.sp
The following environment variables may specified\&.

File diff suppressed because one or more lines are too long

View file

@ -43,6 +43,7 @@ examples:
- code: |
action: fail msg="The system may not be provisioned according to the CMDB status." rc=100
only_if: "'$cmdb_status' != 'to-be-staged'"
description: "Example playbook using fail and only_if together"
author: Dag Wieers
@ -61,4 +62,4 @@ def main():
# this is magic, see lib/ansible/module_common.py
#<<INCLUDE_ANSIBLE_MODULE_COMMON>>
main()
main()

View file

@ -1,182 +0,0 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Copyright 2012 Dag Wieers <dag@wieers.com>
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
DOCUMENTATION = '''
---
author: Dag Wieers
module: hpilo_boot
short_description: Boot system using specific media through HP iLO interface
description:
- "This module boots a system through its HP iLO interface. The boot media
can be one of: cdrom, floppy, hdd, network or usb."
- This module requires the hpilo python module.
version_added: "0.8"
options:
host:
description:
- The HP iLO hostname/address that is linked to the physical system.
required: true
login:
description:
- The login name to authenticate to the HP iLO interface.
default: Administrator
password:
description:
- The password to authenticate to the HP iLO interface.
default: admin
media:
description:
- The boot media to boot the system from
default: network
choices: [ "cdrom", "floppy", "hdd", "network", "normal", "usb" ]
image:
description:
- "The URL of a cdrom, floppy or usb boot media image.
'protocol://username:password@hostname:port/filename'"
- protocol is either 'http' or 'https'
- "username:password is optional"
- port is optional
state:
description:
- The state of the boot media.
- "no_boot: Do not boot from the device"
- "boot_once: Boot from the device once and then notthereafter"
- "boot_always: Boot from the device each time the serveris rebooted"
- "connect: Connect the virtual media device and set to boot_always"
- "disconnect: Disconnects the virtual media device and set to no_boot"
- "poweroff: Power off the server"
default: boot_once
choices: [ "boot_always", "boot_once", "connect", "disconnect", "no_boot", "poweroff" ]
force:
description:
- Whether to force a reboot (even when the system is already booted).
- As a safeguard, without force, hpilo_boot will refuse to reboot a server that is already running.
default: no
choices: [ "yes", "no" ]
examples:
- description: Task to boot a system using an ISO from an HP iLO interface only if the system is an HP server
code: |
- local_action: fail msg="CMDB serial ($cmdb_serialno) does not match hardware serial ($hw_system_serial) !"
only_if: "'$cmdb_serialno' != '$hw_system_serial'"
- local_action: hpilo_boot host=$ilo_address login=$ilo_login password=$ilo_password media=cdrom image=$iso_url
only_if: "'$cmdb_hwmodel'.startswith('HP ')"
- description: Power off a server
code: "local_action: hpilo_boot host=$ilo_address login=$ilo_login password=$ilo_password state=poweroff"
notes:
- To use a USB key image you need to specify floppy as boot media.
- This module ought to be run from a system that can access the HP iLO
interface directly, either by using local_action or
using delegate_to.
'''
import sys
import time
import warnings
try:
import hpilo
except ImportError:
print "failed=True msg='hpilo python module unavailable'"
sys.exit(1)
# Surpress warnings from hpilo
warnings.simplefilter('ignore')
def main():
module = AnsibleModule(
argument_spec = dict(
host = dict(required=True),
login = dict(default='Administrator'),
password = dict(default='admin'),
media = dict(default=None, choices=['cdrom', 'floppy', 'hdd', 'network', 'normal', 'usb']),
image = dict(default=None),
state = dict(default='boot_once', choices=['boot_always', 'boot_once', 'connect', 'disconnect', 'no_boot', 'poweroff']),
force = dict(default='no', choices=BOOLEANS),
)
)
host = module.params.get('host')
login = module.params.get('login')
password = module.params.get('password')
media = module.params.get('media')
image = module.params.get('image')
state = module.params.get('state')
force = module.boolean(module.params.get('force'))
ilo = hpilo.Ilo(host, login=login, password=password)
changed = False
status = {}
power_status = 'UNKNOWN'
if media and state in ('boot_always', 'boot_once', 'connect', 'disconnect', 'no_boot'):
# Workaround for: Error communicating with iLO: Problem manipulating EV
try:
ilo.set_one_time_boot(media)
except hpilo.IloError:
time.sleep(60)
ilo.set_one_time_boot(media)
# TODO: Verify if image URL exists/works
if image:
ilo.insert_virtual_media(media, image)
changed = True
if media == 'cdrom':
ilo.set_vm_status('cdrom', state, True)
status = ilo.get_vm_status()
changed = True
elif media in ('floppy', 'usb'):
ilo.set_vf_status(state, True)
status = ilo.get_vf_status()
changed = True
# Only perform a boot when state is boot_once or boot_always, or in case we want to force a reboot
if state in ('boot_once', 'boot_always') or force:
power_status = ilo.get_host_power_status()
if not force and power_status == 'ON':
module.fail_json(rc=1, msg='HP iLO (%s) reports that the server is already powered on !' % host)
if power_status == 'ON':
# ilo.cold_boot_server()
ilo.warm_boot_server()
changed = True
else:
ilo.press_pwr_btn()
# ilo.reset_server()
# ilo.set_host_power(host_power=True)
changed = True
elif state in ('poweroff'):
power_status = ilo.get_host_power_status()
if not power_status == 'OFF':
ilo.hold_pwr_btn()
# ilo.set_host_power(host_power=False)
changed = True
module.exit_json(changed=changed, power=power_status, **status)
# this is magic, see lib/ansible/module_common.py
#<<INCLUDE_ANSIBLE_MODULE_COMMON>>
main()

View file

@ -1,152 +0,0 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Copyright 2012 Dag Wieers <dag@wieers.com>
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
DOCUMENTATION = '''
---
author: Dag Wieers
module: hpilo_facts
short_description: Gather facts through an HP iLO interface
description:
- This module gathers facts for a specific system using its HP iLO interface.
These facts include hardware and network related information useful
for provisioning (e.g. macaddress, uuid).
- This module requires the hpilo python module.
version_added: "0.8"
options:
host:
description:
- The HP iLO hostname/address that is linked to the physical system.
required: true
login:
description:
- The login name to authenticate to the HP iLO interface.
default: Administrator
password:
description:
- The password to authenticate to the HP iLO interface.
default: admin
examples:
- description: Task to gather facts from a HP iLO interface only if the system is an HP server
code: |
- local_action: hpilo_facts host=$ilo_address login=$ilo_login password=$ilo_password
only_if: "'$cmdb_hwmodel'.startswith('HP ')
- local_action: fail msg="CMDB serial ($cmdb_serialno) does not match hardware serial ($hw_system_serial) !"
only_if: "'$cmdb_serialno' != '$hw_system_serial'"
- description: Typical output of HP iLO_facts for a physical system
code: |
- hw_bios_date: "05/05/2011"
hw_bios_version: "P68"
hw_eth0:
- macaddress: "00:11:22:33:44:55"
macaddress_dash: "00-11-22-33-44-55"
hw_eth1:
- macaddress: "00:11:22:33:44:57"
macaddress_dash: "00-11-22-33-44-57"
hw_eth2:
- macaddress: "00:11:22:33:44:5A"
macaddress_dash: "00-11-22-33-44-5A"
hw_eth3:
- macaddress: "00:11:22:33:44:5C"
macaddress_dash: "00-11-22-33-44-5C"
hw_eth_ilo:
- macaddress: "00:11:22:33:44:BA"
macaddress_dash: "00-11-22-33-44-BA"
hw_product_name: "ProLiant DL360 G7"
hw_product_uuid: "ef50bac8-2845-40ff-81d9-675315501dac"
hw_system_serial: "ABC12345D6"
hw_uuid: "123456ABC78901D2"
notes:
- This module ought to be run from a system that can access the HP iLO
interface directly, either by using local_action or
using delegate_to.
'''
import sys
import warnings
try:
import hpilo
except ImportError:
print "failed=True msg='hpilo python module unavailable'"
sys.exit(1)
# Surpress warnings from hpilo
warnings.simplefilter('ignore')
def main():
module = AnsibleModule(
argument_spec = dict(
host = dict(required=True),
login = dict(default='Administrator'),
password = dict(default='admin'),
)
)
host = module.params.get('host')
login = module.params.get('login')
password = module.params.get('password')
ilo = hpilo.Ilo(host, login=login, password=password)
# TODO: Count number of CPUs, DIMMs and total memory
data = ilo.get_host_data()
facts = {
'module_hw': True,
}
for entry in data:
if not entry.has_key('type'): continue
if entry['type'] == 0: # BIOS Information
facts['hw_bios_version'] = entry['Family']
facts['hw_bios_date'] = entry['Date']
elif entry['type'] == 1: # System Information
facts['hw_uuid'] = entry['UUID']
facts['hw_system_serial'] = entry['Serial Number'].rstrip()
facts['hw_product_name'] = entry['Product Name']
facts['hw_product_uuid'] = entry['cUUID']
elif entry['type'] == 209: # Embedded NIC MAC Assignment
for (name, value) in [ (e['name'], e['value']) for e in entry['fields'] ]:
if name.startswith('Port'):
try:
factname = 'hw_eth' + str(int(value) - 1)
except:
factname = 'hw_eth_ilo'
elif name.startswith('MAC'):
facts[factname] = {
'macaddress': value.replace('-', ':'),
'macaddress_dash': value
}
elif entry['type'] == 209: # HPQ NIC iSCSI MAC Info
for (name, value) in [ (e['name'], e['value']) for e in entry['fields'] ]:
if name.startswith('Port'):
try:
factname = 'hw_iscsi' + str(int(value) - 1)
except:
factname = 'hw_iscsi_ilo'
elif name.startswith('MAC'):
facts[factname] = {
'macaddress': value.replace('-', ':'),
'macaddress_dash': value
}
module.exit_json(ansible_facts=facts)
# this is magic, see lib/ansible/module_common.py
#<<INCLUDE_ANSIBLE_MODULE_COMMON>>
main()

View file

@ -1,139 +0,0 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Copyright 2012 Dag Wieers <dag@wieers.com>
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
DOCUMENTATION = '''
---
author: Dag Wieers
module: vsphere_facts
short_description: Gather facts for a guest on VMWare vSphere
description:
- This module gathers facts for a specific guest on VMWare vSphere.
These facts include hardware and network related information useful
for provisioning (e.g. macaddress, uuid).
- This module requires the pysphere python module.
version_added: "0.8"
options:
host:
description:
- The vSphere server from the cluster the virtual server is located on.
required: true
login:
description:
- The login name to authenticate on the vSphere cluster.
required: true
password:
description:
- The password to authenticate on the vSphere cluster.
required: true
guest:
description:
- The virtual server to gather facts for on the vSphere cluster.
required: true
examples:
- description: Task to gather facts from a vSphere cluster only if the system is a VMWare guest
code: |
- local_action: vsphere_facts host=$esxserver login=$esxlogin password=$esxpassword guest=$inventory_hostname_short
only_if: "'$cmdb_hwmodel'.startswith('VMWare ')
- description: Typical output of a vsphere_facts run on a guest
code:
- hw_eth0:
- addresstype: "assigned"
label: "Network adapter 1"
macaddress: "00:11:22:33:44:55"
macaddress_dash: "00-11-22-33-44-55"
summary: "VLAN-321"
hw_guest_full_name: "Red Hat Enterprise Linux 6 (64-bit)"
hw_guest_id: "rhel6_64Guest"
hw_memtotal_mb: 2048
hw_name: "centos6"
hw_processor_count: 1
hw_product_uuid: "ef50bac8-2845-40ff-81d9-675315501dac"
notes:
- This module ought to be run from a system that can access vSphere directly.
Either by using local_action, or using delegate_to.
'''
import sys
try:
import pysphere
except ImportError:
print "failed=True msg='pysphere python module unavailable'"
sys.exit(1)
def main():
module = AnsibleModule(
argument_spec = dict(
host = dict(required=True),
login = dict(required=True),
password = dict(required=True),
guest = dict(required=True, aliases=['name']),
)
)
host = module.params.get('host')
login = module.params.get('login')
password = module.params.get('password')
guest = module.params.get('guest')
server = pysphere.VIServer()
try:
# server.connect(host, login, password, trace_file='debug.txt')
server.connect(host, login, password)
except Exception, e:
module.fail_json(rc=1, msg='Failed to connect to %s: %s' % (host, e))
try:
vm = server.get_vm_by_name(guest)
except pysphere.resources.vi_exception.VIException, e:
module.fail_json(rc=2, msg=e.message)
data = vm.get_properties()
facts = {
'module_hw': True,
'hw_name': vm.properties.name,
'hw_guest_full_name': vm.properties.config.guestFullName,
'hw_guest_id': vm.properties.config.guestId,
'hw_product_uuid': vm.properties.config.uuid,
'hw_processor_count': vm.properties.config.hardware.numCPU,
'hw_memtotal_mb': vm.properties.config.hardware.memoryMB,
}
ifidx = 0
for entry in vm.properties.config.hardware.device:
if not hasattr(entry, 'macAddress'): continue
factname = 'hw_eth' + str(ifidx)
facts[factname] = {
'addresstype': entry.addressType,
'label': entry.deviceInfo.label,
'macaddress': entry.macAddress,
'macaddress_dash': entry.macAddress.replace(':', '-'),
'summary': entry.deviceInfo.summary,
}
ifidx += 1
module.exit_json(ansible_facts=facts)
# this is magic, see lib/ansible/module_common.py
#<<INCLUDE_ANSIBLE_MODULE_COMMON>>
main()