Repository: ansible/ansible

Issue:
Explicitly pass HTTP method to fetch_url
##### SUMMARY

The `rollbar_deployment` module no longer works on the `HEAD` of `devel` due to changes made in the `fetch_url` method, which currently lives in `module_utils/urls.py` (I'm not exactly sure what, but my best guess is the default method was changed from `GET` to `POST` (there were recently non-trivial changes made to this module). 

Explicitly specifying the `method` in the call to `fetch_url` resolves the issue (note: I did not see any open issues referring to rollbar_deployment).

##### ISSUE TYPE
 - Bugfix Pull Request

##### COMPONENT NAME
rollbar_deployment

##### ANSIBLE VERSION
```
ansible 2.7.0.dev0 (devel cb1396b5be) last updated 2018/07/17 00:40:07 (GMT -400)
  config file = None
  configured module search path = [u'/home/ecoutu/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /home/ecoutu/dev/crowdstaffing/deploy/.venv/src/ansible/lib/ansible
  executable location = /home/ecoutu/dev/crowdstaffing/deploy/.venv/bin/ansible
  python version = 2.7.15rc1 (default, Apr 15 2018, 21:51:34) [GCC 7.3.0]
```

##### ADDITIONAL INFORMATION
<!--- Include additional information to help people understand the change here.
For bugs that don't have a linked bug report, a step-by-step reproduction
of the problem is helpful. -->

Minimal playbook to reproduce:

```yaml
- hosts: localhost
  connection: local
  tasks:
    - name: notify rollbar of deployment
      rollbar_deployment:
        environment: local
        revision: master
        token: "{{ rollbar_access_token }}"
```

Before patch:

```bash
$ ansible-playbook wat1.yml -i localdev

PLAY [localhost] ***************************************************************************************************************************************************************************************************************************************************************************

TASK [Gathering Facts] *********************************************************************************************************************************************************************************************************************************************************************
ok: [localhost]

TASK [notify rollbar of deployment] ********************************************************************************************************************************************************************************************************************************************************
fatal: [localhost]: FAILED! => {"changed": false, "msg": "HTTP result code: 400 connecting to https://api.rollbar.com/api/1/deploy/"}

PLAY RECAP *********************************************************************************************************************************************************************************************************************************************************************************
localhost              : ok=1    changed=0    unreachable=0    failed=1   
```
After patch:

```yaml
$ ansible-playbook wat1.yml -i localdev

PLAY [localhost] ***************************************************************************************************************************************************************************************************************************************************************************

TASK [Gathering Facts] *********************************************************************************************************************************************************************************************************************************************************************
ok: [localhost]

TASK [notify rollbar of deployment] ********************************************************************************************************************************************************************************************************************************************************
changed: [localhost]

PLAY RECAP *********************************************************************************************************************************************************************************************************************************************************************************
localhost              : ok=2    changed=1    unreachable=0    failed=0  
```


Discussion:
cc @kavu
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
The same for `rocketchat`. I would call this a regression which should be fixed instead of fixing each module on it's own.

See [here](https://github.com/ansible/ansible/pull/37622#discussion_r202369772) for my comment on the regression. @sivel @bcoca

Resolving patch:
diff --git a/lib/ansible/module_utils/urls.py b/lib/ansible/module_utils/urls.py
--- a/lib/ansible/module_utils/urls.py
+++ b/lib/ansible/module_utils/urls.py
@@ -1136,7 +1136,7 @@ def open_url(url, data=None, headers=None, method=None, use_proxy=True,
 
     Does not require the module environment
     '''
-    method = method or 'GET'
+    method = method or ('POST' if data else 'GET')
     return Request().open(method, url, data=data, headers=headers, use_proxy=use_proxy,
                           force=force, last_mod_time=last_mod_time, timeout=timeout, validate_certs=validate_certs,
                           url_username=url_username, url_password=url_password, http_agent=http_agent,


Test patch: