Repository: ansible/ansible-modules-core

Issue:
apt module throws `UnboundLocalError` when installing ctags on Ubuntu 15.10
##### Bug Report
##### COMPONENT NAME

apt
##### ANSIBLE VERSION

```
ansible 2.2.0 (devel 1fc44e4103) last updated 2016/05/02 10:25:32 (GMT +800)
  lib/ansible/modules/core: (devel 82aeaed45d) last updated 2016/05/02 12:06:05 (GMT +800)
  lib/ansible/modules/extras: (detached HEAD 1846de2809) last updated 2016/05/02 10:25:32 (GMT +800)
  config file = 
  configured module search path = Default w/o overrides
```
##### CONFIGURATION

None.
##### OS / ENVIRONMENT

Running Ansible on Ubuntu 15.10, managing localhost.
##### SUMMARY

apt module throws `UnboundLocalError` when installing ctags.
##### STEPS TO REPRODUCE

Run in command line:

```
ansible localhost -m apt -a name=ctags -s
```
##### EXPECTED RESULTS

Install as normal.
##### ACTUAL RESULTS

```
 [WARNING]: Host file not found: /etc/ansible/hosts

An exception occurred during task execution. To see the full traceback, use -vvv. The error was: UnboundLocalError: local variable 'upgradable' referenced before assignment
localhost | FAILED! => {
    "changed": false, 
    "failed": true, 
    "module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_krsG0i/ansible_module_apt.py\", line 826, in <module>\n    main()\n  File \"/tmp/ansible_krsG0i/ansible_module_apt.py\", line 805, in main\n    allow_unauthenticated=allow_unauthenticated)\n  File \"/tmp/ansible_krsG0i/ansible_module_apt.py\", line 404, in install\n    installed, upgradable, has_files = package_status(m, name, version, cache, state='install')\n  File \"/tmp/ansible_krsG0i/ansible_module_apt.py\", line 272, in package_status\n    return is_installed, upgradable, False\nUnboundLocalError: local variable 'upgradable' referenced before assignment\n", 
    "module_stdout": "", 
    "msg": "MODULE FAILURE", 
    "parsed": false
}
```

apt module throws `UnboundLocalError` when installing ctags on Ubuntu 15.10
##### Bug Report
##### COMPONENT NAME

apt
##### ANSIBLE VERSION

```
ansible 2.2.0 (devel 1fc44e4103) last updated 2016/05/02 10:25:32 (GMT +800)
  lib/ansible/modules/core: (devel 82aeaed45d) last updated 2016/05/02 12:06:05 (GMT +800)
  lib/ansible/modules/extras: (detached HEAD 1846de2809) last updated 2016/05/02 10:25:32 (GMT +800)
  config file = 
  configured module search path = Default w/o overrides
```
##### CONFIGURATION

None.
##### OS / ENVIRONMENT

Running Ansible on Ubuntu 15.10, managing localhost.
##### SUMMARY

apt module throws `UnboundLocalError` when installing ctags.
##### STEPS TO REPRODUCE

Run in command line:

```
ansible localhost -m apt -a name=ctags -s
```
##### EXPECTED RESULTS

Install as normal.
##### ACTUAL RESULTS

```
 [WARNING]: Host file not found: /etc/ansible/hosts

An exception occurred during task execution. To see the full traceback, use -vvv. The error was: UnboundLocalError: local variable 'upgradable' referenced before assignment
localhost | FAILED! => {
    "changed": false, 
    "failed": true, 
    "module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_krsG0i/ansible_module_apt.py\", line 826, in <module>\n    main()\n  File \"/tmp/ansible_krsG0i/ansible_module_apt.py\", line 805, in main\n    allow_unauthenticated=allow_unauthenticated)\n  File \"/tmp/ansible_krsG0i/ansible_module_apt.py\", line 404, in install\n    installed, upgradable, has_files = package_status(m, name, version, cache, state='install')\n  File \"/tmp/ansible_krsG0i/ansible_module_apt.py\", line 272, in package_status\n    return is_installed, upgradable, False\nUnboundLocalError: local variable 'upgradable' referenced before assignment\n", 
    "module_stdout": "", 
    "msg": "MODULE FAILURE", 
    "parsed": false
}
```



Discussion:

Resolving patch:
diff --git a/packaging/os/apt.py b/packaging/os/apt.py
--- a/packaging/os/apt.py
+++ b/packaging/os/apt.py
@@ -263,6 +263,7 @@ def package_status(m, pkgname, version, cache, state):
                 provided_packages = cache.get_providing_packages(pkgname)
                 if provided_packages:
                     is_installed = False
+                    upgradable = False
                     # when virtual package providing only one package, look up status of target package
                     if cache.is_virtual_package(pkgname) and len(provided_packages) == 1:
                         package = provided_packages[0]


Test patch: