Updates for Solaris 11

pull/18777/head
Paul Markham 10 years ago committed by Matt Clay
parent ecd5b22f59
commit 30f6995939

@ -32,7 +32,7 @@ description:
version_added: "2.0" version_added: "2.0"
author: Paul Markham author: Paul Markham
requirements: requirements:
- Solaris 10 or later - Solaris 10 or 11
options: options:
state: state:
required: true required: true
@ -84,6 +84,12 @@ options:
- 'Extra options to the zonecfg(1M) create command.' - 'Extra options to the zonecfg(1M) create command.'
required: false required: false
default: empty string default: empty string
install_options:
required: false
description:
- 'Extra options to the zoneadm(1M) install command. To automate Solaris 11 zone creation,
use this to specify the profile XML file, e.g. install_options="-c sc_profile.xml"'
required: false
attach_options: attach_options:
required: false required: false
description: description:
@ -130,23 +136,34 @@ solaris_zone: name=zone1 state=attached attach_options='-u'
class Zone(object): class Zone(object):
def __init__(self, module): def __init__(self, module):
self.changed = False self.changed = False
self.msg = [] self.msg = []
self.module = module self.module = module
self.path = self.module.params['path'] self.path = self.module.params['path']
self.name = self.module.params['name'] self.name = self.module.params['name']
self.sparse = self.module.params['sparse'] self.sparse = self.module.params['sparse']
self.root_password = self.module.params['root_password'] self.root_password = self.module.params['root_password']
self.timeout = self.module.params['timeout'] self.timeout = self.module.params['timeout']
self.config = self.module.params['config'] self.config = self.module.params['config']
self.create_options = self.module.params['create_options'] self.create_options = self.module.params['create_options']
self.attach_options = self.module.params['attach_options'] self.install_options = self.module.params['install_options']
self.attach_options = self.module.params['attach_options']
self.zoneadm_cmd = self.module.get_bin_path('zoneadm', True) self.zoneadm_cmd = self.module.get_bin_path('zoneadm', True)
self.zonecfg_cmd = self.module.get_bin_path('zonecfg', True) self.zonecfg_cmd = self.module.get_bin_path('zonecfg', True)
self.ssh_keygen_cmd = self.module.get_bin_path('ssh-keygen', True) self.ssh_keygen_cmd = self.module.get_bin_path('ssh-keygen', True)
if self.module.check_mode:
self.msg.append('Running in check mode')
if platform.system() != 'SunOS':
self.module.fail_json(msg='This module requires Solaris')
(self.os_major, self.os_minor) = platform.release().split('.')
if int(self.os_minor) < 10:
self.module.fail_json(msg='This module requires Solaris 10 or later')
def configure(self): def configure(self):
if not self.path: if not self.path:
self.module.fail_json(msg='Missing required argument: path') self.module.fail_json(msg='Missing required argument: path')
@ -176,11 +193,12 @@ class Zone(object):
def install(self): def install(self):
if not self.module.check_mode: if not self.module.check_mode:
cmd = '%s -z %s install' % (self.zoneadm_cmd, self.name) cmd = '%s -z %s install %s' % (self.zoneadm_cmd, self.name, self.install_options)
(rc, out, err) = self.module.run_command(cmd) (rc, out, err) = self.module.run_command(cmd)
if rc != 0: if rc != 0:
self.module.fail_json(msg='Failed to install zone. %s' % (out + err)) self.module.fail_json(msg='Failed to install zone. %s' % (out + err))
self.configure_sysid() if int(self.os_minor) == 10:
self.configure_sysid()
self.configure_password() self.configure_password()
self.configure_ssh_keys() self.configure_ssh_keys()
self.changed = True self.changed = True
@ -273,7 +291,7 @@ class Zone(object):
while True: while True:
if elapsed > self.timeout: if elapsed > self.timeout:
self.module.fail_json(msg='timed out waiting for zone to boot') self.module.fail_json(msg='timed out waiting for zone to boot')
rc = os.system('ps -z %s -o args|grep "/usr/lib/saf/ttymon.*-d /dev/console" > /dev/null 2>/dev/null' % self.name) rc = os.system('ps -z %s -o args|grep "ttymon.*-d /dev/console" > /dev/null 2>/dev/null' % self.name)
if rc == 0: if rc == 0:
break break
time.sleep(10) time.sleep(10)
@ -341,9 +359,10 @@ class Zone(object):
def status(self): def status(self):
cmd = '%s -z %s list -p' % (self.zoneadm_cmd, self.name) cmd = '%s -z %s list -p' % (self.zoneadm_cmd, self.name)
(rc, out, err) = self.module.run_command(cmd) (rc, out, err) = self.module.run_command(cmd)
if rc != 0: if rc == 0:
self.module.fail_json(msg='Failed to determine zone state. %s' % (out + err)) return out.split(':')[2]
return out.split(':')[2] else:
return 'undefined'
def state_present(self): def state_present(self):
if self.exists(): if self.exists():
@ -398,27 +417,21 @@ class Zone(object):
def main(): def main():
module = AnsibleModule( module = AnsibleModule(
argument_spec = dict( argument_spec = dict(
name = dict(required=True), name = dict(required=True),
state = dict(default='present', choices=['running', 'started', 'present', 'installed', 'stopped', 'absent', 'configured', 'detached', 'attached']), state = dict(default='present', choices=['running', 'started', 'present', 'installed', 'stopped', 'absent', 'configured', 'detached', 'attached']),
path = dict(defalt=None), path = dict(defalt=None),
sparse = dict(default=False, type='bool'), sparse = dict(default=False, type='bool'),
root_password = dict(default=None), root_password = dict(default=None),
timeout = dict(default=600, type='int'), timeout = dict(default=600, type='int'),
config = dict(default=''), config = dict(default=''),
create_options = dict(default=''), create_options = dict(default=''),
attach_options = dict(default=''), install_options = dict(default=''),
attach_options = dict(default=''),
), ),
supports_check_mode=True supports_check_mode=True
) )
if platform.system() == 'SunOS':
(major, minor) = platform.release().split('.')
if minor < 10:
module.fail_json(msg='This module requires Solaris 10 or later')
else:
module.fail_json(msg='This module requires Solaris')
zone = Zone(module) zone = Zone(module)
state = module.params['state'] state = module.params['state']

Loading…
Cancel
Save