Repository: ansible/ansible-modules-extras

Issue:
ZFS module incorrectly reports change to sharesmb property
##### ISSUE TYPE
- Bug Report
##### COMPONENT NAME

ZFS module
##### ANSIBLE VERSION

```
ansible 2.1.1.0
  config file =
  configured module search path = Default w/o overrides
```
##### CONFIGURATION

Default
##### OS / ENVIRONMENT

Running Ansible on and managing Ubuntu 14.04.5 LTS (GNU/Linux 3.13.0-68-generic x86_64)
##### SUMMARY

The ZFS module incorrectly reports a change to an existing ZFS file system when `sharesmb: on` is among the properties specified in an Ansible task.
##### STEPS TO REPRODUCE
1. Note version of ZFS for Linux.
   
   ```
   $ dmesg | grep ZFS
   [    7.273084] ZFS: Loaded module v0.6.5.7-1~trusty, ZFS pool version 5000, ZFS filesystem version 5
   ```
2.  Observe that an existing ZFS filesystem has the _sharesmb_ property set.
   
   ```
   $ sudo zfs get sharesmb /kpool/media/Movies
   NAME                PROPERTY  VALUE     SOURCE
   kpool/media/Movies  sharesmb  on        local
   ```
3. Run ansible-playbook with the following playbook.
   
   ```
   ---
   
   - hosts: plexServers
     user: joel
     become: yes
   
     tasks:
   
     - name: Provide movie filesystem in ZFS
       zfs:
         name: kpool/media/Movies
         sharesmb: on
         state: present
   ```
4. Observe that the ZFS filesystem _sharesmb_ property is unchanged; it remains on.
   
   ```
   $ sudo zfs get sharesmb /kpool/media/Movies
   NAME                PROPERTY  VALUE     SOURCE
   kpool/media/Movies  sharesmb  on        local
   ```
##### EXPECTED RESULTS

Since the ZFS file system exists with the requested property on, I expect Ansible to report no changes. This was Ansible's behavior in version 1.9, which I was running last week.
##### ACTUAL RESULTS

<!--- What actually happened? If possible run with high verbosity (-vvvv) -->

<!--- Paste verbatim command output between quotes below -->

```
$ ansible-playbook testplay.yml -K -vvvv
No config file found; using defaults
SUDO password:
Loaded callback default of type stdout, v2.0

PLAYBOOK: testplay.yml *********************************************************
1 plays in testplay.yml

PLAY [plexServers] *************************************************************

TASK [setup] *******************************************************************
<krakatoa> ESTABLISH LOCAL CONNECTION FOR USER: joel
<krakatoa> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1473112233.95-74580936174074 `" && echo ansible-tmp-1473112233.95-74580936174074="` echo $HOME/.ansible/tmp/ansible-tmp-1473112233.95-74580936174074 `" ) && sleep 0'
<krakatoa> PUT /tmp/tmpZK4VqA TO /home/joel/.ansible/tmp/ansible-tmp-1473112233.95-74580936174074/setup
<krakatoa> EXEC /bin/sh -c 'sudo -H -S  -p "[sudo via ansible, key=deysqntucrnzvixhchewikgnwgsziqme] password: " -u root /bin/sh -c '"'"'echo BECOME-SUCCESS-deysqntucrnzvixhchewikgnwgsziqme; LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 /usr/bin/python /home/joel/.ansible/tmp/ansible-tmp-1473112233.95-74580936174074/setup; rm -rf "/home/joel/.ansible/tmp/ansible-tmp-1473112233.95-74580936174074/" > /dev/null 2>&1'"'"' && sleep 0'
ok: [krakatoa]

TASK [Provide movie filesystem in ZFS] *****************************************
task path: /etc/ansible/testplay.yml:9
<krakatoa> ESTABLISH LOCAL CONNECTION FOR USER: joel
<krakatoa> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1473112234.93-181082652648504 `" && echo ansible-tmp-1473112234.93-181082652648504="` echo $HOME/.ansible/tmp/ansible-tmp-1473112234.93-181082652648504 `" ) && sleep 0'
<krakatoa> PUT /tmp/tmplgsvDW TO /home/joel/.ansible/tmp/ansible-tmp-1473112234.93-181082652648504/zfs
<krakatoa> EXEC /bin/sh -c 'sudo -H -S  -p "[sudo via ansible, key=wzqqvfggcdxghikmrvrokyqcyvyoasch] password: " -u root /bin/sh -c '"'"'echo BECOME-SUCCESS-wzqqvfggcdxghikmrvrokyqcyvyoasch; LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 /usr/bin/python /home/joel/.ansible/tmp/ansible-tmp-1473112234.93-181082652648504/zfs; rm -rf "/home/joel/.ansible/tmp/ansible-tmp-1473112234.93-181082652648504/" > /dev/null 2>&1'"'"' && sleep 0'
changed: [krakatoa] => {"changed": true, "invocation": {"module_args": {"createparent": null, "sharesmb": true}, "module_name": "zfs"}, "name": "kpool/media/Movies", "sharesmb": "on", "state": "present"}

PLAY RECAP *********************************************************************
krakatoa                   : ok=2    changed=1    unreachable=0    failed=0

```



Discussion:
<!-- @jshprentz: Thanks for filing this bug report! -->

@johanwiren ping, this issue is waiting for your response.
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)

<!--- boilerplate: issue_bug_new --->

For what it's worth, this problem did not occur with the _compression_ property. 

That property already is set on my ZFS file system:

```
$ sudo zfs get compression /kpool/media/Movies
NAME                PROPERTY     VALUE     SOURCE
kpool/media/Movies  compression  lzjb      local
```

I changed the ZFS task in the playbook to:

```
  - name: Provide movie filesystem in ZFS
    zfs:
      name: kpool/media/Movies
      compression: lzjb
      state: present
```

Running ansible-playbook now shows zero changes, the desired result:

```
$ ansible-playbook testplay.yml -K -vvvv
No config file found; using defaults
SUDO password:
Loaded callback default of type stdout, v2.0

PLAYBOOK: testplay.yml *********************************************************
1 plays in testplay.yml

PLAY [plexServers] *************************************************************

TASK [setup] *******************************************************************
<krakatoa> ESTABLISH LOCAL CONNECTION FOR USER: joel
<krakatoa> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1473115242.83-168639174998726 `" && echo ansible-tmp-1473115242.83-168639174998726="` echo $HOME/.ansible/tmp/ansible-tmp-1473115242.83-168639174998726 `" ) && sleep 0'
<krakatoa> PUT /tmp/tmp9og5w6 TO /home/joel/.ansible/tmp/ansible-tmp-1473115242.83-168639174998726/setup
<krakatoa> EXEC /bin/sh -c 'sudo -H -S  -p "[sudo via ansible, key=enicbswnojvxnnrfxhtzlyjhqwhgzixg] password: " -u root /bin/sh -c '"'"'echo BECOME-SUCCESS-enicbswnojvxnnrfxhtzlyjhqwhgzixg; LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 /usr/bin/python /home/joel/.ansible/tmp/ansible-tmp-1473115242.83-168639174998726/setup; rm -rf "/home/joel/.ansible/tmp/ansible-tmp-1473115242.83-168639174998726/" > /dev/null 2>&1'"'"' && sleep 0'
ok: [krakatoa]

TASK [Provide movie filesystem in ZFS] *****************************************
task path: /etc/ansible/testplay.yml:9
<krakatoa> ESTABLISH LOCAL CONNECTION FOR USER: joel
<krakatoa> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1473115243.78-126110344156450 `" && echo ansible-tmp-1473115243.78-126110344156450="` echo $HOME/.ansible/tmp/ansible-tmp-1473115243.78-126110344156450 `" ) && sleep 0'
<krakatoa> PUT /tmp/tmppXJPjn TO /home/joel/.ansible/tmp/ansible-tmp-1473115243.78-126110344156450/zfs
<krakatoa> EXEC /bin/sh -c 'sudo -H -S  -p "[sudo via ansible, key=crsavxjllkofrzzzddxxxnupkolgcvfh] password: " -u root /bin/sh -c '"'"'echo BECOME-SUCCESS-crsavxjllkofrzzzddxxxnupkolgcvfh; LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 /usr/bin/python /home/joel/.ansible/tmp/ansible-tmp-1473115243.78-126110344156450/zfs; rm -rf "/home/joel/.ansible/tmp/ansible-tmp-1473115243.78-126110344156450/" > /dev/null 2>&1'"'"' && sleep 0'
ok: [krakatoa] => {"changed": false, "compression": "lzjb", "invocation": {"module_args": {"compression": "lzjb", "createparent": null}, "module_name": "zfs"}, "name": "kpool/media/Movies", "state": "present"}

PLAY RECAP *********************************************************************
krakatoa                   : ok=2    changed=0    unreachable=0    failed=0
```

I managed to reproduce this on Ubuntu 16.04. Will take a look.


Resolving patch:
diff --git a/system/zfs.py b/system/zfs.py
--- a/system/zfs.py
+++ b/system/zfs.py
@@ -198,8 +198,9 @@ def get_current_properties(self):
             if source == 'local':
                 properties[prop] = value
         # Add alias for enhanced sharing properties
-        properties['sharenfs'] = properties.get('share.nfs', None)
-        properties['sharesmb'] = properties.get('share.smb', None)
+        if self.enhanced_sharing:
+            properties['sharenfs'] = properties.get('share.nfs', None)
+            properties['sharesmb'] = properties.get('share.smb', None)
         return properties
 
 


Test patch: