Repository: ansible/ansible

Issue:
nxos_template: Not reading transport/provider correctly
##### ISSUE TYPE
 - Bug Report
##### COMPONENT NAME
nxos_template

##### ANSIBLE VERSION
```
b8d308d919c89d86dc72d4fd62335b9f948544f1
```

##### SUMMARY
Looks like `nxos_template` isn't correctly reading in the `transport` option from `provider`.

I wonder if this is because `nxos_template` is using `NetworkModule` rather than `AnsibleModule`
```yaml
- name: configure device with config
  nxos_template:
    src: basic/config.j2
    provider: "{{ cli }}"
    force: yes
  register: result

```

Gives
```yaml
fatal: [nxos01]: FAILED! => {
    "changed": false, 
    "failed": true, 
    "invocation": {
        "module_args": {
            "authorize": false, 
            "backup": false, 
            "force": true, 
            "host": "nxos01", 
            "include_defaults": true, 
            "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", 
            "provider": {
                "host": "nxos01", 
                "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", 
                "port": null, 
                "ssh_keyfile": null, 
                "timeout": null, 
                "transport": "cli", 
                "use_ssl": null, 
                "username": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", 
                "validate_certs": null
            }, 
            "src": "interface Ethernet2/5\n   description this is a test\n   shutdown\n\n", 
            "timeout": 10, 
            "transport": "cli", 
            "username": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER"
        }
    }, 
    "msg": "value of transport must be one of: , got: cli"
}
```

Noteice that `transport` *is* returned in the above both at the top level, and under provider
##### STEPS TO REPRODUCE
`
time ANSIBLE_ROLES_PATH=targets  ansible-playbook -vvvvv  -i  inventory.network nxos.yaml  -e "limit_to=nxos_template"
`


##### ACTUAL RESULTS



Discussion:
cc @jedelman8 @GGabriele @privateip @Qalthos
[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_template.py b/lib/ansible/modules/network/nxos/_nxos_template.py
--- a/lib/ansible/modules/network/nxos/_nxos_template.py
+++ b/lib/ansible/modules/network/nxos/_nxos_template.py
@@ -15,10 +15,12 @@
 # You should have received a copy of the GNU General Public License
 # along with Ansible.  If not, see <http://www.gnu.org/licenses/>.
 #
-ANSIBLE_METADATA = {'status': ['deprecated'],
-                    'supported_by': 'community',
-                    'version': '1.0'}
 
+ANSIBLE_METADATA = {
+    'status': ['deprecated'],
+    'supported_by': 'community',
+    'version': '1.0'
+}
 
 DOCUMENTATION = """
 ---
@@ -34,7 +36,6 @@
     commands that are not already configured.  The config source can
     be a set of commands or a template.
 deprecated: Deprecated in 2.2. Use M(nxos_config) instead.
-extends_documentation_fragment: nxos
 options:
   src:
     description:
@@ -114,20 +115,23 @@
   type: list
   sample: ['...', '...']
 """
-import ansible.module_utils.nxos
+from ansible.module_utils.nxos import load_config, get_config
+from ansible.module_utils.nxos import nxos_argument_spec
+from ansible.module_utils.basic import AnsibleModule
 from ansible.module_utils.netcfg import NetworkConfig, dumps
-from ansible.module_utils.network import NetworkModule
 
-def get_config(module):
-    config = module.params['config'] or dict()
+def get_current_config(module):
+    config = module.params.get('config')
     if not config and not module.params['force']:
-        config = module.config.get_config()
+        flags = []
+        if module.params['include_defaults']:
+            flags.append('all')
+        config = get_config(module, flags)
     return config
 
 def main():
     """ main entry point for module execution
     """
-
     argument_spec = dict(
         src=dict(),
         force=dict(default=False, type='bool'),
@@ -136,9 +140,11 @@ def main():
         config=dict(),
     )
 
+    argument_spec.update(nxos_argument_spec)
+
     mutually_exclusive = [('config', 'backup'), ('config', 'force')]
 
-    module = NetworkModule(argument_spec=argument_spec,
+    module = AnsibleModule(argument_spec=argument_spec,
                            mutually_exclusive=mutually_exclusive,
                            supports_check_mode=True)
 
@@ -146,10 +152,10 @@ def main():
 
     candidate = NetworkConfig(contents=module.params['src'], indent=2)
 
-    contents = get_config(module)
+    contents = get_current_config(module)
     if contents:
         config = NetworkConfig(contents=contents, indent=2)
-        result['_backup'] = str(contents)
+        result['__backup__'] = str(contents)
 
     if not module.params['force']:
         commands = candidate.difference(config)
@@ -160,11 +166,12 @@ def main():
 
     if commands:
         if not module.check_mode:
-            response = module.config(commands)
-            result['responses'] = response
+            load_config(module, commands)
         result['changed'] = True
 
     result['updates'] = commands
+    result['commands'] = commands
+
     module.exit_json(**result)
 
 


Test patch: