2015-06-25 04:46:35 +02:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
2015-07-03 06:28:28 +02:00
|
|
|
# (c) 2015, Paul Markham <pmarkham@netrefinery.com>
|
2015-06-25 04:46:35 +02:00
|
|
|
#
|
|
|
|
# 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/>.
|
|
|
|
|
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
import platform
|
|
|
|
import tempfile
|
|
|
|
|
|
|
|
DOCUMENTATION = '''
|
|
|
|
---
|
2015-06-26 01:44:33 +02:00
|
|
|
module: solaris_zone
|
2015-06-25 04:46:35 +02:00
|
|
|
short_description: Manage Solaris zones
|
|
|
|
description:
|
|
|
|
- Create, start, stop and delete Solaris zones. This module doesn't currently allow
|
|
|
|
changing of options for a zone that's already been created.
|
2015-06-26 01:44:33 +02:00
|
|
|
version_added: "2.0"
|
2015-06-25 04:46:35 +02:00
|
|
|
author: Paul Markham
|
|
|
|
requirements:
|
2015-07-10 05:15:47 +02:00
|
|
|
- Solaris 10 or 11
|
2015-06-25 04:46:35 +02:00
|
|
|
options:
|
|
|
|
state:
|
|
|
|
required: true
|
|
|
|
description:
|
2015-07-03 06:28:28 +02:00
|
|
|
- C(present), configure and install the zone.
|
|
|
|
- C(installed), synonym for C(present).
|
|
|
|
- C(running), if the zone already exists, boot it, otherwise, configure and install
|
|
|
|
the zone first, then boot it.
|
2015-06-29 03:00:30 +02:00
|
|
|
- C(started), synonym for C(running).
|
2015-06-26 01:44:33 +02:00
|
|
|
- C(stopped), shutdown a zone.
|
|
|
|
- C(absent), destroy the zone.
|
2015-07-03 06:28:28 +02:00
|
|
|
- C(configured), configure the ready so that it's to be attached.
|
|
|
|
- C(attached), attach a zone, but do not boot it.
|
2015-07-04 03:10:30 +02:00
|
|
|
- C(detached), shutdown and detach a zone
|
2015-07-03 06:28:28 +02:00
|
|
|
choices: ['present', 'installed', 'started', 'running', 'stopped', 'absent', 'configured', 'attached', 'detached']
|
|
|
|
default: present
|
2015-06-25 04:46:35 +02:00
|
|
|
name:
|
|
|
|
description:
|
|
|
|
- Zone name.
|
|
|
|
required: true
|
|
|
|
path:
|
|
|
|
description:
|
|
|
|
- The path where the zone will be created. This is required when the zone is created, but not
|
|
|
|
used otherwise.
|
|
|
|
required: false
|
|
|
|
default: null
|
2015-06-29 03:00:30 +02:00
|
|
|
sparse:
|
2015-06-25 04:46:35 +02:00
|
|
|
description:
|
2015-06-29 03:00:30 +02:00
|
|
|
- Whether to create a sparse (C(true)) or whole root (C(false)) zone.
|
2015-06-25 04:46:35 +02:00
|
|
|
required: false
|
2015-06-29 03:00:30 +02:00
|
|
|
default: false
|
2015-06-25 04:46:35 +02:00
|
|
|
root_password:
|
|
|
|
description:
|
|
|
|
- The password hash for the root account. If not specified, the zone's root account
|
|
|
|
will not have a password.
|
|
|
|
required: false
|
|
|
|
default: null
|
|
|
|
config:
|
|
|
|
description:
|
2015-07-03 06:28:28 +02:00
|
|
|
- 'The zonecfg configuration commands for this zone. See zonecfg(1M) for the valid options
|
|
|
|
and syntax. Typically this is a list of options separated by semi-colons or new lines, e.g.
|
|
|
|
"set auto-boot=true;add net;set physical=bge0;set address=10.1.1.1;end"'
|
2015-06-25 04:46:35 +02:00
|
|
|
required: false
|
2015-07-03 06:28:28 +02:00
|
|
|
default: empty string
|
2015-06-25 04:46:35 +02:00
|
|
|
create_options:
|
|
|
|
description:
|
2015-07-03 06:28:28 +02:00
|
|
|
- 'Extra options to the zonecfg(1M) create command.'
|
2015-06-25 04:46:35 +02:00
|
|
|
required: false
|
2015-07-03 06:28:28 +02:00
|
|
|
default: empty string
|
2015-07-10 05:15:47 +02:00
|
|
|
install_options:
|
|
|
|
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
|
2015-07-11 02:08:51 +02:00
|
|
|
default: empty string
|
2015-07-03 06:28:28 +02:00
|
|
|
attach_options:
|
|
|
|
description:
|
|
|
|
- 'Extra options to the zoneadm attach command. For example, this can be used to specify
|
|
|
|
whether a minimum or full update of packages is required and if any packages need to
|
|
|
|
be deleted. For valid values, see zoneadm(1M)'
|
|
|
|
required: false
|
|
|
|
default: empty string
|
2015-06-25 04:46:35 +02:00
|
|
|
timeout:
|
|
|
|
description:
|
|
|
|
- Timeout, in seconds, for zone to boot.
|
|
|
|
required: false
|
|
|
|
default: 600
|
|
|
|
'''
|
|
|
|
|
|
|
|
EXAMPLES = '''
|
2015-07-03 06:28:28 +02:00
|
|
|
# Create and install a zone, but don't boot it
|
2015-06-29 03:00:30 +02:00
|
|
|
solaris_zone: name=zone1 state=present path=/zones/zone1 sparse=true root_password="Be9oX7OSwWoU."
|
2015-07-03 06:28:28 +02:00
|
|
|
config='set autoboot=true; add net; set physical=bge0; set address=10.1.1.1; end'
|
2015-06-25 04:46:35 +02:00
|
|
|
|
2015-07-03 06:28:28 +02:00
|
|
|
# Create and install a zone and boot it
|
2015-06-29 03:00:30 +02:00
|
|
|
solaris_zone: name=zone1 state=running path=/zones/zone1 root_password="Be9oX7OSwWoU."
|
2015-07-03 06:28:28 +02:00
|
|
|
config='set autoboot=true; add net; set physical=bge0; set address=10.1.1.1; end'
|
2015-06-25 04:46:35 +02:00
|
|
|
|
2015-07-03 06:28:28 +02:00
|
|
|
# Boot an already installed zone
|
2015-06-26 01:44:33 +02:00
|
|
|
solaris_zone: name=zone1 state=running
|
2015-06-25 04:46:35 +02:00
|
|
|
|
|
|
|
# Stop a zone
|
2015-06-26 01:44:33 +02:00
|
|
|
solaris_zone: name=zone1 state=stopped
|
2015-06-25 04:46:35 +02:00
|
|
|
|
|
|
|
# Destroy a zone
|
2015-06-26 01:44:33 +02:00
|
|
|
solaris_zone: name=zone1 state=absent
|
2015-07-03 06:28:28 +02:00
|
|
|
|
|
|
|
# Detach a zone
|
|
|
|
solaris_zone: name=zone1 state=detached
|
|
|
|
|
|
|
|
# Configure a zone, ready to be attached
|
|
|
|
solaris_zone: name=zone1 state=configured path=/zones/zone1 root_password="Be9oX7OSwWoU."
|
|
|
|
config='set autoboot=true; add net; set physical=bge0; set address=10.1.1.1; end'
|
|
|
|
|
|
|
|
# Attach a zone
|
|
|
|
solaris_zone: name=zone1 state=attached attach_options='-u'
|
2015-06-25 04:46:35 +02:00
|
|
|
'''
|
|
|
|
|
|
|
|
class Zone(object):
|
|
|
|
def __init__(self, module):
|
2015-07-10 05:15:47 +02:00
|
|
|
self.changed = False
|
|
|
|
self.msg = []
|
|
|
|
|
|
|
|
self.module = module
|
|
|
|
self.path = self.module.params['path']
|
|
|
|
self.name = self.module.params['name']
|
|
|
|
self.sparse = self.module.params['sparse']
|
|
|
|
self.root_password = self.module.params['root_password']
|
|
|
|
self.timeout = self.module.params['timeout']
|
|
|
|
self.config = self.module.params['config']
|
|
|
|
self.create_options = self.module.params['create_options']
|
|
|
|
self.install_options = self.module.params['install_options']
|
|
|
|
self.attach_options = self.module.params['attach_options']
|
2015-06-25 04:46:35 +02:00
|
|
|
|
|
|
|
self.zoneadm_cmd = self.module.get_bin_path('zoneadm', True)
|
|
|
|
self.zonecfg_cmd = self.module.get_bin_path('zonecfg', True)
|
|
|
|
self.ssh_keygen_cmd = self.module.get_bin_path('ssh-keygen', True)
|
|
|
|
|
2015-07-10 05:15:47 +02:00
|
|
|
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')
|
|
|
|
|
2015-07-03 06:28:28 +02:00
|
|
|
def configure(self):
|
2015-06-25 04:46:35 +02:00
|
|
|
if not self.path:
|
|
|
|
self.module.fail_json(msg='Missing required argument: path')
|
|
|
|
|
2015-07-03 06:28:28 +02:00
|
|
|
if not self.module.check_mode:
|
|
|
|
t = tempfile.NamedTemporaryFile(delete = False)
|
2015-06-25 04:46:35 +02:00
|
|
|
|
2015-07-03 06:28:28 +02:00
|
|
|
if self.sparse:
|
|
|
|
t.write('create %s\n' % self.create_options)
|
|
|
|
self.msg.append('creating sparse-root zone')
|
|
|
|
else:
|
|
|
|
t.write('create -b %s\n' % self.create_options)
|
|
|
|
self.msg.append('creating whole-root zone')
|
2015-06-25 04:46:35 +02:00
|
|
|
|
2015-07-03 06:28:28 +02:00
|
|
|
t.write('set zonepath=%s\n' % self.path)
|
|
|
|
t.write('%s\n' % self.config)
|
|
|
|
t.close()
|
2015-06-25 04:46:35 +02:00
|
|
|
|
2015-07-03 06:28:28 +02:00
|
|
|
cmd = '%s -z %s -f %s' % (self.zonecfg_cmd, self.name, t.name)
|
|
|
|
(rc, out, err) = self.module.run_command(cmd)
|
|
|
|
if rc != 0:
|
|
|
|
self.module.fail_json(msg='Failed to create zone. %s' % (out + err))
|
|
|
|
os.unlink(t.name)
|
2015-06-25 04:46:35 +02:00
|
|
|
|
2015-07-03 06:28:28 +02:00
|
|
|
self.changed = True
|
|
|
|
self.msg.append('zone configured')
|
2015-06-25 04:46:35 +02:00
|
|
|
|
2015-07-03 06:28:28 +02:00
|
|
|
def install(self):
|
|
|
|
if not self.module.check_mode:
|
2015-07-10 05:15:47 +02:00
|
|
|
cmd = '%s -z %s install %s' % (self.zoneadm_cmd, self.name, self.install_options)
|
2015-07-03 06:28:28 +02:00
|
|
|
(rc, out, err) = self.module.run_command(cmd)
|
|
|
|
if rc != 0:
|
|
|
|
self.module.fail_json(msg='Failed to install zone. %s' % (out + err))
|
2015-07-10 05:15:47 +02:00
|
|
|
if int(self.os_minor) == 10:
|
|
|
|
self.configure_sysid()
|
2015-07-03 06:28:28 +02:00
|
|
|
self.configure_password()
|
|
|
|
self.configure_ssh_keys()
|
|
|
|
self.changed = True
|
|
|
|
self.msg.append('zone installed')
|
|
|
|
|
|
|
|
def uninstall(self):
|
|
|
|
if self.is_installed():
|
|
|
|
if not self.module.check_mode:
|
|
|
|
cmd = '%s -z %s uninstall -F' % (self.zoneadm_cmd, self.name)
|
|
|
|
(rc, out, err) = self.module.run_command(cmd)
|
|
|
|
if rc != 0:
|
|
|
|
self.module.fail_json(msg='Failed to uninstall zone. %s' % (out + err))
|
|
|
|
self.changed = True
|
|
|
|
self.msg.append('zone uninstalled')
|
2015-06-25 04:46:35 +02:00
|
|
|
|
|
|
|
def configure_sysid(self):
|
2015-06-29 04:43:14 +02:00
|
|
|
if os.path.isfile('%s/root/etc/.UNCONFIGURED' % self.path):
|
|
|
|
os.unlink('%s/root/etc/.UNCONFIGURED' % self.path)
|
2015-06-25 04:46:35 +02:00
|
|
|
|
|
|
|
open('%s/root/noautoshutdown' % self.path, 'w').close()
|
|
|
|
|
|
|
|
node = open('%s/root/etc/nodename' % self.path, 'w')
|
|
|
|
node.write(self.name)
|
|
|
|
node.close
|
|
|
|
|
|
|
|
id = open('%s/root/etc/.sysIDtool.state' % self.path, 'w')
|
|
|
|
id.write('1 # System previously configured?\n')
|
|
|
|
id.write('1 # Bootparams succeeded?\n')
|
|
|
|
id.write('1 # System is on a network?\n')
|
|
|
|
id.write('1 # Extended network information gathered?\n')
|
|
|
|
id.write('0 # Autobinder succeeded?\n')
|
|
|
|
id.write('1 # Network has subnets?\n')
|
|
|
|
id.write('1 # root password prompted for?\n')
|
|
|
|
id.write('1 # locale and term prompted for?\n')
|
|
|
|
id.write('1 # security policy in place\n')
|
|
|
|
id.write('1 # NFSv4 domain configured\n')
|
|
|
|
id.write('0 # Auto Registration Configured\n')
|
|
|
|
id.write('vt100')
|
|
|
|
id.close()
|
|
|
|
|
|
|
|
def configure_ssh_keys(self):
|
|
|
|
rsa_key_file = '%s/root/etc/ssh/ssh_host_rsa_key' % self.path
|
|
|
|
dsa_key_file = '%s/root/etc/ssh/ssh_host_dsa_key' % self.path
|
|
|
|
|
|
|
|
if not os.path.isfile(rsa_key_file):
|
|
|
|
cmd = '%s -f %s -t rsa -N ""' % (self.ssh_keygen_cmd, rsa_key_file)
|
|
|
|
(rc, out, err) = self.module.run_command(cmd)
|
|
|
|
if rc != 0:
|
|
|
|
self.module.fail_json(msg='Failed to create rsa key. %s' % (out + err))
|
|
|
|
|
|
|
|
if not os.path.isfile(dsa_key_file):
|
|
|
|
cmd = '%s -f %s -t dsa -N ""' % (self.ssh_keygen_cmd, dsa_key_file)
|
|
|
|
(rc, out, err) = self.module.run_command(cmd)
|
|
|
|
if rc != 0:
|
|
|
|
self.module.fail_json(msg='Failed to create dsa key. %s' % (out + err))
|
|
|
|
|
|
|
|
def configure_password(self):
|
|
|
|
shadow = '%s/root/etc/shadow' % self.path
|
|
|
|
if self.root_password:
|
|
|
|
f = open(shadow, 'r')
|
|
|
|
lines = f.readlines()
|
|
|
|
f.close()
|
|
|
|
|
2015-07-03 06:28:28 +02:00
|
|
|
for i in range(0, len(lines)):
|
|
|
|
fields = lines[i].split(':')
|
2015-06-25 04:46:35 +02:00
|
|
|
if fields[0] == 'root':
|
2015-07-03 06:28:28 +02:00
|
|
|
fields[1] = self.root_password
|
2015-06-25 04:46:35 +02:00
|
|
|
lines[i] = ':'.join(fields)
|
|
|
|
|
|
|
|
f = open(shadow, 'w')
|
|
|
|
for line in lines:
|
2015-07-03 06:28:28 +02:00
|
|
|
f.write(line)
|
2015-06-25 04:46:35 +02:00
|
|
|
f.close()
|
2015-07-03 06:28:28 +02:00
|
|
|
|
2015-06-25 04:46:35 +02:00
|
|
|
def boot(self):
|
2015-07-03 06:28:28 +02:00
|
|
|
if not self.module.check_mode:
|
|
|
|
cmd = '%s -z %s boot' % (self.zoneadm_cmd, self.name)
|
|
|
|
(rc, out, err) = self.module.run_command(cmd)
|
|
|
|
if rc != 0:
|
|
|
|
self.module.fail_json(msg='Failed to boot zone. %s' % (out + err))
|
|
|
|
|
|
|
|
"""
|
|
|
|
The boot command can return before the zone has fully booted. This is especially
|
|
|
|
true on the first boot when the zone initializes the SMF services. Unless the zone
|
|
|
|
has fully booted, subsequent tasks in the playbook may fail as services aren't running yet.
|
|
|
|
Wait until the zone's console login is running; once that's running, consider the zone booted.
|
|
|
|
"""
|
|
|
|
|
|
|
|
elapsed = 0
|
|
|
|
while True:
|
|
|
|
if elapsed > self.timeout:
|
|
|
|
self.module.fail_json(msg='timed out waiting for zone to boot')
|
2015-07-10 05:15:47 +02:00
|
|
|
rc = os.system('ps -z %s -o args|grep "ttymon.*-d /dev/console" > /dev/null 2>/dev/null' % self.name)
|
2015-07-03 06:28:28 +02:00
|
|
|
if rc == 0:
|
|
|
|
break
|
|
|
|
time.sleep(10)
|
|
|
|
elapsed += 10
|
|
|
|
self.changed = True
|
|
|
|
self.msg.append('zone booted')
|
2015-06-25 04:46:35 +02:00
|
|
|
|
|
|
|
def destroy(self):
|
2015-07-03 06:28:28 +02:00
|
|
|
if self.is_running():
|
|
|
|
self.stop()
|
|
|
|
if self.is_installed():
|
|
|
|
self.uninstall()
|
|
|
|
if not self.module.check_mode:
|
|
|
|
cmd = '%s -z %s delete -F' % (self.zonecfg_cmd, self.name)
|
|
|
|
(rc, out, err) = self.module.run_command(cmd)
|
|
|
|
if rc != 0:
|
|
|
|
self.module.fail_json(msg='Failed to delete zone. %s' % (out + err))
|
|
|
|
self.changed = True
|
|
|
|
self.msg.append('zone deleted')
|
2015-06-25 04:46:35 +02:00
|
|
|
|
|
|
|
def stop(self):
|
2015-07-03 06:28:28 +02:00
|
|
|
if not self.module.check_mode:
|
|
|
|
cmd = '%s -z %s halt' % (self.zoneadm_cmd, self.name)
|
|
|
|
(rc, out, err) = self.module.run_command(cmd)
|
|
|
|
if rc != 0:
|
|
|
|
self.module.fail_json(msg='Failed to stop zone. %s' % (out + err))
|
|
|
|
self.changed = True
|
|
|
|
self.msg.append('zone stopped')
|
|
|
|
|
|
|
|
def detach(self):
|
|
|
|
if not self.module.check_mode:
|
|
|
|
cmd = '%s -z %s detach' % (self.zoneadm_cmd, self.name)
|
|
|
|
(rc, out, err) = self.module.run_command(cmd)
|
|
|
|
if rc != 0:
|
|
|
|
self.module.fail_json(msg='Failed to detach zone. %s' % (out + err))
|
|
|
|
self.changed = True
|
|
|
|
self.msg.append('zone detached')
|
|
|
|
|
|
|
|
def attach(self):
|
|
|
|
if not self.module.check_mode:
|
|
|
|
cmd = '%s -z %s attach %s' % (self.zoneadm_cmd, self.name, self.attach_options)
|
|
|
|
(rc, out, err) = self.module.run_command(cmd)
|
|
|
|
if rc != 0:
|
|
|
|
self.module.fail_json(msg='Failed to attach zone. %s' % (out + err))
|
|
|
|
self.changed = True
|
|
|
|
self.msg.append('zone attached')
|
2015-06-25 04:46:35 +02:00
|
|
|
|
|
|
|
def exists(self):
|
|
|
|
cmd = '%s -z %s list' % (self.zoneadm_cmd, self.name)
|
|
|
|
(rc, out, err) = self.module.run_command(cmd)
|
|
|
|
if rc == 0:
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
return False
|
|
|
|
|
2015-07-03 06:28:28 +02:00
|
|
|
def is_running(self):
|
|
|
|
return self.status() == 'running'
|
|
|
|
|
|
|
|
def is_installed(self):
|
|
|
|
return self.status() == 'installed'
|
|
|
|
|
|
|
|
def is_configured(self):
|
|
|
|
return self.status() == 'configured'
|
|
|
|
|
|
|
|
def status(self):
|
2015-06-25 04:46:35 +02:00
|
|
|
cmd = '%s -z %s list -p' % (self.zoneadm_cmd, self.name)
|
|
|
|
(rc, out, err) = self.module.run_command(cmd)
|
2015-07-10 05:15:47 +02:00
|
|
|
if rc == 0:
|
|
|
|
return out.split(':')[2]
|
|
|
|
else:
|
|
|
|
return 'undefined'
|
2015-06-25 04:46:35 +02:00
|
|
|
|
|
|
|
def state_present(self):
|
|
|
|
if self.exists():
|
|
|
|
self.msg.append('zone already exists')
|
|
|
|
else:
|
2015-07-03 06:28:28 +02:00
|
|
|
self.configure()
|
|
|
|
self.install()
|
2015-06-25 04:46:35 +02:00
|
|
|
|
|
|
|
def state_running(self):
|
|
|
|
self.state_present()
|
2015-07-03 06:28:28 +02:00
|
|
|
if self.is_running():
|
2015-06-25 04:46:35 +02:00
|
|
|
self.msg.append('zone already running')
|
|
|
|
else:
|
2015-07-03 06:28:28 +02:00
|
|
|
self.boot()
|
2015-06-25 04:46:35 +02:00
|
|
|
|
|
|
|
def state_stopped(self):
|
|
|
|
if self.exists():
|
2015-07-03 06:28:28 +02:00
|
|
|
self.stop()
|
2015-06-25 04:46:35 +02:00
|
|
|
else:
|
|
|
|
self.module.fail_json(msg='zone does not exist')
|
|
|
|
|
|
|
|
def state_absent(self):
|
|
|
|
if self.exists():
|
2015-07-03 06:28:28 +02:00
|
|
|
if self.is_running():
|
|
|
|
self.stop()
|
|
|
|
self.destroy()
|
2015-06-25 04:46:35 +02:00
|
|
|
else:
|
|
|
|
self.msg.append('zone does not exist')
|
|
|
|
|
2015-07-03 06:28:28 +02:00
|
|
|
def state_configured(self):
|
|
|
|
if self.exists():
|
|
|
|
self.msg.append('zone already exists')
|
|
|
|
else:
|
|
|
|
self.configure()
|
|
|
|
|
|
|
|
def state_detached(self):
|
|
|
|
if not self.exists():
|
|
|
|
self.module.fail_json(msg='zone does not exist')
|
|
|
|
if self.is_configured():
|
|
|
|
self.msg.append('zone already detached')
|
|
|
|
else:
|
|
|
|
self.stop()
|
|
|
|
self.detach()
|
|
|
|
|
|
|
|
def state_attached(self):
|
|
|
|
if not self.exists():
|
|
|
|
self.msg.append('zone does not exist')
|
|
|
|
if self.is_configured():
|
|
|
|
self.attach()
|
|
|
|
else:
|
|
|
|
self.msg.append('zone already attached')
|
2015-06-25 04:46:35 +02:00
|
|
|
|
|
|
|
def main():
|
|
|
|
module = AnsibleModule(
|
2015-07-10 05:15:47 +02:00
|
|
|
argument_spec = dict(
|
|
|
|
name = dict(required=True),
|
|
|
|
state = dict(default='present', choices=['running', 'started', 'present', 'installed', 'stopped', 'absent', 'configured', 'detached', 'attached']),
|
|
|
|
path = dict(defalt=None),
|
|
|
|
sparse = dict(default=False, type='bool'),
|
|
|
|
root_password = dict(default=None),
|
|
|
|
timeout = dict(default=600, type='int'),
|
|
|
|
config = dict(default=''),
|
|
|
|
create_options = dict(default=''),
|
|
|
|
install_options = dict(default=''),
|
|
|
|
attach_options = dict(default=''),
|
2015-06-25 04:46:35 +02:00
|
|
|
),
|
|
|
|
supports_check_mode=True
|
|
|
|
)
|
|
|
|
|
|
|
|
zone = Zone(module)
|
2015-07-03 06:28:28 +02:00
|
|
|
|
2015-06-25 04:46:35 +02:00
|
|
|
state = module.params['state']
|
|
|
|
|
2015-06-29 03:00:30 +02:00
|
|
|
if state == 'running' or state == 'started':
|
2015-06-25 04:46:35 +02:00
|
|
|
zone.state_running()
|
2015-07-03 06:28:28 +02:00
|
|
|
elif state == 'present' or state == 'installed':
|
2015-06-25 04:46:35 +02:00
|
|
|
zone.state_present()
|
|
|
|
elif state == 'stopped':
|
|
|
|
zone.state_stopped()
|
|
|
|
elif state == 'absent':
|
|
|
|
zone.state_absent()
|
2015-07-03 06:28:28 +02:00
|
|
|
elif state == 'configured':
|
|
|
|
zone.state_configured()
|
|
|
|
elif state == 'detached':
|
|
|
|
zone.state_detached()
|
|
|
|
elif state == 'attached':
|
|
|
|
zone.state_attached()
|
2015-06-25 04:46:35 +02:00
|
|
|
else:
|
|
|
|
module.fail_json(msg='Invalid state: %s' % state)
|
|
|
|
|
2015-07-03 06:28:28 +02:00
|
|
|
module.exit_json(changed=zone.changed, msg=', '.join(zone.msg))
|
2015-06-25 04:46:35 +02:00
|
|
|
|
|
|
|
from ansible.module_utils.basic import *
|
|
|
|
main()
|