Repository: ansible/ansible

Issue:
apt_repository doesn't check if line is None
##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
apt_repository

##### ANSIBLE VERSION
```
ansible 2.4.3.0
  config file = .../ansible.cfg
  configured module search path = ['.../.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = .../venv/lib/python3.6/site-packages/ansible
  executable location = .../venv/bin/ansible
  python version = 3.6.4 (default, Dec 25 2017, 14:57:56) [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)]
```

##### CONFIGURATION
```
DEFAULT_CALLBACK_WHITELIST(.../ansible.cfg) = ['timer', 'profile_tasks']
DEFAULT_FORKS(.../ansible.cfg) = 300
DEFAULT_VAULT_PASSWORD_FILE(env: ANSIBLE_VAULT_PASSWORD_FILE) = .../.vault_password
```

##### OS / ENVIRONMENT
Ubuntu 16.04 as target host

##### SUMMARY
apt_repository doesn't check if line is None

##### STEPS TO REPRODUCE
```yml
apt_repositories:
   # - 'commented out repository'
```

```yaml
- name: Add repos
  apt_repository:
    repo: '{{ item }}'
  with_items: '{{ apt_repositories }}'
```

##### EXPECTED RESULTS
do nothing

##### ACTUAL RESULTS
> failed: [test-host] (item=None) => {"changed": false, "item": null, "module_stderr": "Shared connection to test-host closed.\r\n", "module_stdout": "Traceback (most recent call last):\r\n  File \"/tmp/ansible_bk5VEP/ansible_module_apt_repository.py\", line 556, in <module>\r\n    main()\r\n  File \"/tmp/ansible_bk5VEP/ansible_module_apt_repository.py\", line 519, in main\r\n    sourceslist.add_source(repo)\r\n  File \"/tmp/ansible_bk5VEP/ansible_module_apt_repository.py\", line 422, in add_source\r\n    if line.startswith('ppa:'):\r\nAttributeError: 'NoneType' object has no attribute 'startswith'\r\n", "msg": "MODULE FAILURE", "rc": 0}




Discussion:
Files identified in the description:
* [lib/ansible/modules/packaging/os/apt_repository.py](https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/packaging/os/apt_repository.py)

If these files are inaccurate, please update the `component name` section of the description or use the `!component` bot command.

[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
cc @sashka
[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/packaging/os/apt_repository.py b/lib/ansible/modules/packaging/os/apt_repository.py
--- a/lib/ansible/modules/packaging/os/apt_repository.py
+++ b/lib/ansible/modules/packaging/os/apt_repository.py
@@ -503,6 +503,9 @@ def main():
         else:
             module.fail_json(msg='%s is not installed, and install_python_apt is False' % PYTHON_APT)
 
+    if not repo:
+        module.fail_json(msg='Please set argument \'repo\' to a non-empty value')
+
     if isinstance(distro, aptsources_distro.Distribution):
         sourceslist = UbuntuSourcesList(module, add_ppa_signing_keys_callback=get_add_ppa_signing_key_callback(module))
     else:


Test patch:
diff --git a/test/integration/targets/apt_repository/tasks/apt.yml b/test/integration/targets/apt_repository/tasks/apt.yml
--- a/test/integration/targets/apt_repository/tasks/apt.yml
+++ b/test/integration/targets/apt_repository/tasks/apt.yml
@@ -199,6 +199,28 @@
 - name: 'ensure ppa key is absent (expect: pass)'
   apt_key: id='{{test_ppa_key}}' state=absent
 
+- name: Test apt_repository with a null value for repo
+  apt_repository:
+    repo:
+  register: result
+  ignore_errors: yes
+
+- assert:
+    that:
+      - result is failed
+      - result.msg == 'Please set argument \'repo\' to a non-empty value'
+
+- name: Test apt_repository with an empty value for repo
+  apt_repository:
+    repo: ""
+  register: result
+  ignore_errors: yes
+
+- assert:
+    that:
+      - result is failed
+      - result.msg == 'Please set argument \'repo\' to a non-empty value'
+
 #
 # TEARDOWN
 #