From 081e6ec032f1acbdb10689d3f84da460482670a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20=C5=A0tevko?= Date: Mon, 8 Aug 2016 17:49:18 +0200 Subject: [PATCH] Add support for managing OpenZFS pools (#2642) --- lib/ansible/modules/extras/system/zfs.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/lib/ansible/modules/extras/system/zfs.py b/lib/ansible/modules/extras/system/zfs.py index cf74c5b0b83..fb987017d13 100644 --- a/lib/ansible/modules/extras/system/zfs.py +++ b/lib/ansible/modules/extras/system/zfs.py @@ -33,7 +33,7 @@ options: required: true state: description: - - Whether to create (C(present)), or remove (C(absent)) a + - Whether to create (C(present)), or remove (C(absent)) a file system, snapshot or volume. All parents/children will be created/destroyed as needed to reach the desired state. choices: ['present', 'absent'] @@ -83,14 +83,27 @@ class Zfs(object): self.name = name self.properties = properties self.changed = False - self.is_solaris = os.uname()[0] == 'SunOS' - self.pool = name.split('/')[0] self.zfs_cmd = module.get_bin_path('zfs', True) self.zpool_cmd = module.get_bin_path('zpool', True) + self.pool = name.split('/')[0] + self.is_solaris = os.uname()[0] == 'SunOS' + self.is_openzfs = self.check_openzfs() self.enhanced_sharing = self.check_enhanced_sharing() + def check_openzfs(self): + cmd = [self.zpool_cmd] + cmd.extend(['get', 'version']) + cmd.append(self.pool) + (rc, out, err) = self.module.run_command(cmd, check_rc=True) + version = out.splitlines()[-1].split()[2] + if version == '-': + return True + if int(version) == 5000: + return True + return False + def check_enhanced_sharing(self): - if os.uname()[0] == 'SunOS': + if self.is_solaris and not self.is_openzfs: cmd = [self.zpool_cmd] cmd.extend(['get', 'version']) cmd.append(self.pool)