Repository: ansible/ansible-modules-extras

Issue:
Freshly installed bower raises json error
I ran into an issue where the ansible bower module when attempting to run bower install can't parse the json from `bower list --json`

Here is the stacktrace

```
failed: [default] => {"failed": true, "parsed": false}
BECOME-SUCCESS-bcokpjdhrlrcdlrfpmvdgmahrbmtzoqk
Traceback (most recent call last):
  File "/home/vagrant/.ansible/tmp/ansible-tmp-1427221462.07-279423510478512/bower", line 1781, in <module>
    main()
  File "/home/vagrant/.ansible/tmp/ansible-tmp-1427221462.07-279423510478512/bower", line 168, in main
    installed, missing, outdated = bower.list()
  File "/home/vagrant/.ansible/tmp/ansible-tmp-1427221462.07-279423510478512/bower", line 116, in list
    data = json.loads(self._exec(cmd, True, False))
  File "/usr/lib/python2.7/json/__init__.py", line 338, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python2.7/json/decoder.py", line 366, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python2.7/json/decoder.py", line 384, in raw_decode
    raise ValueError("No JSON object could be decoded")
```

So, when I logged into run the bower list --json command manually I saw this

```
vagrant@vagrant-ubuntu-trusty-64:~/catdoor/opus$ bower list --json
[?] May bower anonymously report usage statistics to improve the tool over time? Yes
```

Which makes me wonder if a freshly installed bower will always ask that question, thus not producing json output.

When i subsquently run the provision it fails the same way.



Discussion:
I dug into this a little more. This happens when you try and run the bower command as root. I got the stderr and this is what I saw

```
Errr [{
  "code": "ESUDO",
  "details": "Since bower is a user command, there is no need to execute it with superuser permissions.\nIf you're having permission errors when using bower without sudo, please spend a few minutes learning more about how your system should work and make any necessary repairs.\n\nhttp://www.joyent.com/blog/installing-node-and-npm\nhttps://gist.github.com/isaacs/579814\n\nYou can however run a command with sudo using --allow-root option",
  "id": "ESUDO",
  "level": "error",
  "data": {},
  "message": "Cannot be run with sudo",
  "stacktrace": "Error: Cannot be run with sudo\n    at createError (/usr/local/lib/node_modules/bower/lib/util/createError.js:4:15)\n    at rootCheck (/usr/local/lib/node_modules/bower/lib/util/rootCheck.js:27:24)\n    at Object.<anonymous> (/usr/local/lib/node_modules/bower/bin/bower:37:1)\n    at Module._compile (module.js:456:26)\n    at Object.Module._extensions..js (module.js:474:10)\n    at Module.load (module.js:356:32)\n    at Function.Module._load (module.js:312:12)\n    at Function.Module.runMain (module.js:497:10)\n    at startup (node.js:119:16)\n    at node.js:902:3"
}]
```

So, I ran the command sudo_user: vagrant and everything worked out fine. 

I'd suggest adding a param that lets a user turn on --allow-root option, or adding a note explaining that they can't do this as root.


Resolving patch:
diff --git a/packaging/language/bower.py b/packaging/language/bower.py
--- a/packaging/language/bower.py
+++ b/packaging/language/bower.py
@@ -108,7 +108,7 @@ def _exec(self, args, run_in_check_mode=False, check_rc=True):
         return ''
 
     def list(self):
-        cmd = ['list', '--json']
+        cmd = ['list', '--json', '--config.interactive=false', '--allow-root']
 
         installed = list()
         missing = list()


Test patch: