Repository: ansible/ansible

Issue:
(P1) nxos_ntp_options: module fails when stratum not provided in play
<!---
Verify first that your issue/request is not already reported on GitHub.
Also test if the latest release, and master branch are affected too.
-->

##### ISSUE TYPE
<!--- Pick one below and delete the rest: -->
 - Bug Report

##### COMPONENT NAME
<!--- Name of the module/plugin/task/feature -->
- nxos_ntp_options

##### ANSIBLE VERSION
<!--- Paste verbatim output from “ansible --version” between quotes below -->
```
ansible 2.4.0 (devel 6d015294c2) last updated 2017/08/21 23:19:24 (GMT -400)
  config file = None
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /root/agents-ci/ansible/lib/ansible
  executable location = /root/agents-ci/ansible/bin/ansible
  python version = 2.7.6 (default, Oct 26 2016, 20:30:19) [GCC 4.8.4]
```

##### OS / ENVIRONMENT
<!---
Mention the OS you are running Ansible from, and the OS you are
managing, or say “N/A” for anything that is not platform-specific.
Also mention the specific version of what you are trying to control,
e.g. if this is a network bug the version of firmware on the network device.
-->
Ubuntu 14.04

##### SUMMARY
<!--- Explain the problem briefly -->
Documentation says that stratum is optional and has a default value of '8', however applying a play with no 'stratum' leads to a failure.

##### STEPS TO REPRODUCE
<!---
For bugs, show exactly how to reproduce the problem, using a minimal test-case.
For new features, show how the feature would be used.
-->

<!--- Paste example playbooks or commands between quotes below -->
```yaml
  - name: Configure ntp with master and default stratum
    nxos_ntp_options: &configure_master_default_stratum
      master: true
      logging: true
      state: present
      provider: "{{ connection }}"
```

<!--- You can also paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
<!--- What did you expect to happen when running the steps above? -->
Expected stratum to get default value.

##### ACTUAL RESULTS
<!--- What actually happened? If possible run with extra verbosity (-vvvv) -->

<!--- Paste verbatim command output between quotes below -->
```
TASK [nxos_ntp_options : Configure ntp with master and default stratum] *******************************************
task path: /root/agents-ci/ansible/test/integration/targets/nxos_ntp_options/tests/common/sanity.yaml:14
<n9k-xxx.example.com> connection transport is cli
<n9k-xxx.example.com> using connection plugin network_cli
<n9k-xxx.example.com> socket_path: /root/.ansible/pc/3747b7341f
Using module file /root/agents-ci/ansible/lib/ansible/modules/network/nxos/nxos_ntp_options.py
<n9k-xxx.example.com> ESTABLISH LOCAL CONNECTION FOR USER: root
<n9k-xxx.example.com> EXEC /bin/sh -c 'echo ~ && sleep 0'
<n9k-xxx.example.com> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /root/.ansible/tmp/ansible-tmp-1503371991.22-185619034756066 `" && echo ansible-tmp-1503371991.22-185619034756066="` echo /root/.ansible/tmp/ansible-tmp-1503371991.22-185619034756066 `" ) && sleep 0'
<n9k-xxx.example.com> PUT /tmp/tmp5lgLyK TO /root/.ansible/tmp/ansible-tmp-1503371991.22-185619034756066/nxos_ntp_options.py
<n9k-xxx.example.com> EXEC /bin/sh -c 'chmod u+x /root/.ansible/tmp/ansible-tmp-1503371991.22-185619034756066/ /root/.ansible/tmp/ansible-tmp-1503371991.22-185619034756066/nxos_ntp_options.py && sleep 0'
<n9k-xxx.example.com> EXEC /bin/sh -c '/usr/bin/python /root/.ansible/tmp/ansible-tmp-1503371991.22-185619034756066/nxos_ntp_options.py; rm -rf "/root/.ansible/tmp/ansible-tmp-1503371991.22-185619034756066/" > /dev/null 2>&1 && sleep 0'
FAILED! => {
    "changed": false, 
    "failed": true, 
    "invocation": {
        "module_args": {
            "logging": true, 
            "master": true, 
            "provider": null, 
            "state": "present", 
            "transport": "cli"
        }
    }, 
    "msg": "parameters are required together: ('master', 'stratum')"
}
```

(P1) nxos_ntp_options: module fails when stratum not provided in play
<!---
Verify first that your issue/request is not already reported on GitHub.
Also test if the latest release, and master branch are affected too.
-->

##### ISSUE TYPE
<!--- Pick one below and delete the rest: -->
 - Bug Report

##### COMPONENT NAME
<!--- Name of the module/plugin/task/feature -->
- nxos_ntp_options

##### ANSIBLE VERSION
<!--- Paste verbatim output from “ansible --version” between quotes below -->
```
ansible 2.4.0 (devel 6d015294c2) last updated 2017/08/21 23:19:24 (GMT -400)
  config file = None
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /root/agents-ci/ansible/lib/ansible
  executable location = /root/agents-ci/ansible/bin/ansible
  python version = 2.7.6 (default, Oct 26 2016, 20:30:19) [GCC 4.8.4]
```

##### OS / ENVIRONMENT
<!---
Mention the OS you are running Ansible from, and the OS you are
managing, or say “N/A” for anything that is not platform-specific.
Also mention the specific version of what you are trying to control,
e.g. if this is a network bug the version of firmware on the network device.
-->
Ubuntu 14.04

##### SUMMARY
<!--- Explain the problem briefly -->
Documentation says that stratum is optional and has a default value of '8', however applying a play with no 'stratum' leads to a failure.

##### STEPS TO REPRODUCE
<!---
For bugs, show exactly how to reproduce the problem, using a minimal test-case.
For new features, show how the feature would be used.
-->

<!--- Paste example playbooks or commands between quotes below -->
```yaml
  - name: Configure ntp with master and default stratum
    nxos_ntp_options: &configure_master_default_stratum
      master: true
      logging: true
      state: present
      provider: "{{ connection }}"
```

<!--- You can also paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
<!--- What did you expect to happen when running the steps above? -->
Expected stratum to get default value.

##### ACTUAL RESULTS
<!--- What actually happened? If possible run with extra verbosity (-vvvv) -->

<!--- Paste verbatim command output between quotes below -->
```
TASK [nxos_ntp_options : Configure ntp with master and default stratum] *******************************************
task path: /root/agents-ci/ansible/test/integration/targets/nxos_ntp_options/tests/common/sanity.yaml:14
<n9k-xxx.example.com> connection transport is cli
<n9k-xxx.example.com> using connection plugin network_cli
<n9k-xxx.example.com> socket_path: /root/.ansible/pc/3747b7341f
Using module file /root/agents-ci/ansible/lib/ansible/modules/network/nxos/nxos_ntp_options.py
<n9k-xxx.example.com> ESTABLISH LOCAL CONNECTION FOR USER: root
<n9k-xxx.example.com> EXEC /bin/sh -c 'echo ~ && sleep 0'
<n9k-xxx.example.com> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /root/.ansible/tmp/ansible-tmp-1503371991.22-185619034756066 `" && echo ansible-tmp-1503371991.22-185619034756066="` echo /root/.ansible/tmp/ansible-tmp-1503371991.22-185619034756066 `" ) && sleep 0'
<n9k-xxx.example.com> PUT /tmp/tmp5lgLyK TO /root/.ansible/tmp/ansible-tmp-1503371991.22-185619034756066/nxos_ntp_options.py
<n9k-xxx.example.com> EXEC /bin/sh -c 'chmod u+x /root/.ansible/tmp/ansible-tmp-1503371991.22-185619034756066/ /root/.ansible/tmp/ansible-tmp-1503371991.22-185619034756066/nxos_ntp_options.py && sleep 0'
<n9k-xxx.example.com> EXEC /bin/sh -c '/usr/bin/python /root/.ansible/tmp/ansible-tmp-1503371991.22-185619034756066/nxos_ntp_options.py; rm -rf "/root/.ansible/tmp/ansible-tmp-1503371991.22-185619034756066/" > /dev/null 2>&1 && sleep 0'
FAILED! => {
    "changed": false, 
    "failed": true, 
    "invocation": {
        "module_args": {
            "logging": true, 
            "master": true, 
            "provider": null, 
            "state": "present", 
            "transport": "cli"
        }
    }, 
    "msg": "parameters are required together: ('master', 'stratum')"
}
```



Discussion:
cc @GGabriele @jedelman8 @mikewiebe @privateip @rcarrillocruz @trishnaguha
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
cc @GGabriele @jedelman8 @mikewiebe @privateip @rcarrillocruz @trishnaguha
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->

Resolving patch:
diff --git a/lib/ansible/modules/network/nxos/nxos_ntp_options.py b/lib/ansible/modules/network/nxos/nxos_ntp_options.py
--- a/lib/ansible/modules/network/nxos/nxos_ntp_options.py
+++ b/lib/ansible/modules/network/nxos/nxos_ntp_options.py
@@ -105,7 +105,7 @@ def get_current(module):
         master = False
         stratum = None
 
-    logging = 'Enabled' in output[1]
+    logging = 'enabled' in output[1].lower()
 
     return {'master': master, 'stratum': stratum, 'logging': logging}
 
@@ -113,17 +113,14 @@ def get_current(module):
 def main():
     argument_spec = dict(
         master=dict(required=False, type='bool'),
-        stratum=dict(type='str'),
+        stratum=dict(required=False, type='str', default='8'),
         logging=dict(required=False, type='bool'),
         state=dict(choices=['absent', 'present'], default='present'),
     )
 
     argument_spec.update(nxos_argument_spec)
 
-    required_together = [('master', 'stratum')]
-
     module = AnsibleModule(argument_spec=argument_spec,
-                           required_together=required_together,
                            supports_check_mode=True)
 
     warnings = list()


Test patch: