Issue 1:
From @gcs-github on 2016-11-24T20:14:54Z

ISSUE TYPE

Bug Report

COMPONENT NAME

zfs

ANSIBLE VERSION

ansible 2.2.0.0

CONFIGURATION

hash_behavior = merge
force_handlers = True
pipelining = True
control_path = %(directory)s/%%p-%%h-%%r

OS / ENVIRONMENT

Managing from macOS 10.12

Managing Gentoo Linux hosts

SUMMARY

Currently, the ZFS module will only consider local settings while comparing the current state of a ZFS filesystem and its intended target state. This can lead to unwanted set operations to occur even when the target filesystem is in the state described in the play, hurting idempotence.

A good example of this is with the "mountpoint" property. If ZFS dataset B exists as a child of dataset A, but dataset A was previously restored from a backup with zfs receive, therefore having most of its properties not flagged as local, but as received instead (including mountpoint), a run of the ZFS module on A will attempt to first unmount B so that it can perform a mountpoint property change on A even though A already has its mountpoint property set to the correct value.

In some cases the above will fail (for example if a file is open in dataset B so that B can't be unmounted), but in other cases this will still yield an unwanted side effect where an unmount will be forced to occur even when it shouldn't.

I'm not sure why only local properties are being considered at present when comparing current dataset state and target dataset state. Unless I'm missing something, I believe a valid fix could be to simply delete the following line: https://github.com/ansible/ansible-modules-extras/blob/9760ec2538f8b44cb7f27924617a8e024a694724/system/zfs.py#L198

STEPS TO REPRODUCE

zfs receive any dataset containing children in place of one normally managed by an ansible play

run something on the server making use of a file in the one of the children datasets and keeping it open

run the play containing the zfs module call that tries to ensure zfs dataset properties are set correctly

EXPECTED RESULTS

no zfs set command should be issued for dataset properties which are already set to the correct value

ACTUAL RESULTS

zfs set commands are issued on the managed host to set properties to a value they are already set at, in some cases causing unwanted side effects on the managed dataset and its children.

Using module file /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/ansible/modules/extras/system/zfs.py
<xxx.yyy.zzz> ESTABLISH SSH CONNECTION FOR USER: root
<xxx.yyy.zzz> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=root -o ConnectTimeout=10 -o ControlPath=/Users/guillaume/.ansible/cp/%p-%h-%r xxx.yyy.zzz '/bin/sh -c '"'"'/usr/bin/python2 && sleep 0'"'"''
fatal: [xxx.yyy.zzz]: FAILED! => {
"changed": false,
"failed": true,
"invocation": {
"module_args": {
"atime": "off",
"canmount": "on",
"casesensitivity": "sensitive",
"checksum": "fletcher4",
"compression": "lz4",
"copies": "1",
"createparent": null,
"devices": "off",
"exec": "off",
"logbias": "latency",
"mountpoint": "/var/lib/mysql",
"nbmand": "off",
"normalization": "formD",
"primarycache": "metadata",
"quota": "none",
"readonly": "off",
"recordsize": "16K",
"refquota": "none",
"refreservation": "none",
"reservation": "none",
"secondarycache": "none",
"setuid": "off",
"sharenfs": "off",
"sharesmb": "off",
"snapdir": "hidden",
"utf8only": "on",
"xattr": "off"
},
"module_name": "zfs"
},
"msg": "umount: /var/lib/mysql/relay_log: target is busy\n (In some cases useful info about processes that\n use the device is found by lsof(8) or fuser(1).)\ncannot unmount '/var/lib/mysql/relay_log': umount failed\n"
}

Copied from original issue: ansible/ansible-modules-extras#3543

Issue 2:
ISSUE TYPE

Bug Report

COMPONENT NAME

module system/zfs

ANSIBLE VERSION

ansible 2.2.0.0

CONFIGURATION

hash_behavior = merge
force_handlers = True
pipelining = True
control_path = %(directory)s/%%p-%%h-%%r

OS / ENVIRONMENT

Managing from macOS 10.12

Managing Gentoo Linux hosts

SUMMARY

(this issue was ported over from ansible/ansible-modules-extras#3543 following the repository merge of ansible/ansible-modules-extras into ansible/ansible)

Currently, the ZFS module will only consider local settings while comparing the current state of a ZFS filesystem and its intended target state. This can lead to unwanted set operations to occur even when the target filesystem is in the state described in the play, hurting idempotence.

A good example of this is with the "mountpoint" property. If ZFS dataset B exists as a child of dataset A, but dataset A was previously restored from a backup with zfs receive, therefore having most of its properties not flagged as local, but as received instead (including mountpoint), a run of the ZFS module on A will attempt to first unmount B so that it can perform a mountpoint property change on A even though A already has its mountpoint property set to the correct value.

In some cases the above will fail (for example if a file is open in dataset B so that B can't be unmounted), but in other cases this will still yield an unwanted side effect where an unmount will be forced to occur even when it shouldn't.

I'm not sure why only local properties are being considered at present when comparing current dataset state and target dataset state. Unless I'm missing something, I believe a valid fix could be to simply delete the following line: https://github.com/ansible/ansible-modules-extras/blob/9760ec2538f8b44cb7f27924617a8e024a694724/system/zfs.py#L198

STEPS TO REPRODUCE

zfs receive any dataset containing children in place of one normally managed by an ansible play

run something on the server making use of a file in the one of the children datasets and keeping it open

run the play containing the zfs module call that tries to ensure zfs dataset properties are set correctly

EXPECTED RESULTS

no zfs set command should be issued for dataset properties which are already set to the correct value

ACTUAL RESULTS

zfs set commands are issued on the managed host to set properties to a value they are already set at, in some cases causing unwanted side effects on the managed dataset and its children.

Using module file /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/ansible/modules/extras/system/zfs.py
<xxx.yyy.zzz> ESTABLISH SSH CONNECTION FOR USER: root
<xxx.yyy.zzz> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=root -o ConnectTimeout=10 -o ControlPath=/Users/guillaume/.ansible/cp/%p-%h-%r xxx.yyy.zzz '/bin/sh -c '"'"'/usr/bin/python2 && sleep 0'"'"''
fatal: [xxx.yyy.zzz]: FAILED! => {
"changed": false,
"failed": true,
"invocation": {
"module_args": {
"atime": "off",
"canmount": "on",
"casesensitivity": "sensitive",
"checksum": "fletcher4",
"compression": "lz4",
"copies": "1",
"createparent": null,
"devices": "off",
"exec": "off",
"logbias": "latency",
"mountpoint": "/var/lib/mysql",
"nbmand": "off",
"normalization": "formD",
"primarycache": "metadata",
"quota": "none",
"readonly": "off",
"recordsize": "16K",
"refquota": "none",
"refreservation": "none",
"reservation": "none",
"secondarycache": "none",
"setuid": "off",
"sharenfs": "off",
"sharesmb": "off",
"snapdir": "hidden",
"utf8only": "on",
"xattr": "off"
},
"module_name": "zfs"
},
"msg": "umount: /var/lib/mysql/relay_log: target is busy\n (In some cases useful info about processes that\n use the device is found by lsof(8) or fuser(1).)\ncannot unmount '/var/lib/mysql/relay_log': umount failed\n"
}