Repository: ansible/ansible-modules-extras

Issue:
modprobe module's "params" argument only handles a single parameter
Issue Type:
Bugfix Pull Request

Ansible Version:
1.7.1 - this is a very small issue and can be identified easily in the modprobe module.  It exists in the devel branch too.

Ansible Configuration:
This seems to be the only difference not related to the differences in ansible version.  The used the devel branch version of ansible.cfg from the examples directory.
36a37

```
roles_path = /etc/ansible/roles:/etc/opt/cray/config/current/ansible/roles:/etc/opt/cray/config/global/ansible/roles
```

Environment:
SLES 12

Summary:
The modprobe module only provides a single word from the "params" argument.  The modprobe command allows multiple words to be passed allowing multiple module parameters to be set upon module insertion:
`# modprobe mymod msg="hi there" val=3`
for instance.

This change simply splits the params argument to provide for the ability to use a form like:

```
- name: Load a module with two command line supplied parameters
  modprobe: state=present name=mymod params='msg="hi there" val=3'
```
## Steps To Reproduce:

Invoke the following play:

```
    - name: modprobe test
      hosts: localhost
      tasks:
        - modprobe: state=present name=snd_oxygen params="index=0 id=bogus"
```

It will fail with "msg: modprobe: ERROR: could not insert 'snd_oxygen': Invalid argument"

Expected Results:

```
    PLAY [modprobe test] ********************************************************** 

    GATHERING FACTS *************************************************************** 
    ok: [localhost]

    TASK: [modprobe state=present name=snd_oxygen params="index=0 id=bogus"] *** 
    changed: [localhost]

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

Actual Results:

```
    failed: [localhost] => {"changed": false, "failed": true, "name": "snd_oxygen", "params": "index=0 id=bogus", "state": "present"}
    msg: modprobe: ERROR: could not insert 'snd_oxygen': Invalid argument


    FATAL: all hosts have already failed -- aborting

    PLAY RECAP ********************************************************************
```

modprobe module's "params" argument only handles a single parameter
Issue Type:
Bugfix Pull Request

Ansible Version:
1.7.1 - this is a very small issue and can be identified easily in the modprobe module.  It exists in the devel branch too.

Ansible Configuration:
This seems to be the only difference not related to the differences in ansible version.  The used the devel branch version of ansible.cfg from the examples directory.
36a37

```
roles_path = /etc/ansible/roles:/etc/opt/cray/config/current/ansible/roles:/etc/opt/cray/config/global/ansible/roles
```

Environment:
SLES 12

Summary:
The modprobe module only provides a single word from the "params" argument.  The modprobe command allows multiple words to be passed allowing multiple module parameters to be set upon module insertion:
`# modprobe mymod msg="hi there" val=3`
for instance.

This change simply splits the params argument to provide for the ability to use a form like:

```
- name: Load a module with two command line supplied parameters
  modprobe: state=present name=mymod params='msg="hi there" val=3'
```
## Steps To Reproduce:

Invoke the following play:

```
    - name: modprobe test
      hosts: localhost
      tasks:
        - modprobe: state=present name=snd_oxygen params="index=0 id=bogus"
```

It will fail with "msg: modprobe: ERROR: could not insert 'snd_oxygen': Invalid argument"

Expected Results:

```
    PLAY [modprobe test] ********************************************************** 

    GATHERING FACTS *************************************************************** 
    ok: [localhost]

    TASK: [modprobe state=present name=snd_oxygen params="index=0 id=bogus"] *** 
    changed: [localhost]

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

Actual Results:

```
    failed: [localhost] => {"changed": false, "failed": true, "name": "snd_oxygen", "params": "index=0 id=bogus", "state": "present"}
    msg: modprobe: ERROR: could not insert 'snd_oxygen': Invalid argument


    FATAL: all hosts have already failed -- aborting

    PLAY RECAP ********************************************************************
```



Discussion:

Resolving patch:
diff --git a/system/modprobe.py b/system/modprobe.py
--- a/system/modprobe.py
+++ b/system/modprobe.py
@@ -57,6 +57,9 @@
 - modprobe: name=dummy state=present params="numdummies=2"
 '''
 
+import shlex
+
+
 def main():
     module = AnsibleModule(
         argument_spec={
@@ -100,7 +103,9 @@ def main():
     # Add/remove module as needed
     if args['state'] == 'present':
         if not present:
-            rc, _, err = module.run_command([module.get_bin_path('modprobe', True), args['name'], args['params']])
+            command = [module.get_bin_path('modprobe', True), args['name']]
+            command.extend(shlex.split(args['params']))
+            rc, _, err = module.run_command(command)
             if rc != 0:
                 module.fail_json(msg=err, **args)
             args['changed'] = True


Test patch: