Repository: ansible/ansible

Issue:
Yum doesn't see new packages with long name


##### ISSUE TYPE
Bug Report

##### COMPONENT NAME
`modules/packaging/os/yum.py`

##### ANSIBLE VERSION
```
ansible 2.3.0.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = Default w/o overrides
  python version = 2.7.5 (default, Jun 24 2015, 00:41:19) [GCC 4.8.3 20140911 (Red Hat 4.8.3-9)]
```

##### OS / ENVIRONMENT
CentOS7
```
$ rpm -qi ansible
Name        : ansible
Version     : 2.3.0.0
Release     : 1.el7
Architecture: noarch
Install Date: Tue 18 Apr 2017 02:21:15 AM PDT
Group       : Development/Libraries
Size        : 28579660
License     : GPLv3+
Signature   : RSA/SHA256, Wed 12 Apr 2017 03:12:54 PM PDT, Key ID 6a2faea2352c64e5
Source RPM  : ansible-2.3.0.0-1.el7.src.rpm
Build Date  : Wed 12 Apr 2017 02:06:18 PM PDT
Build Host  : buildhw-09.phx2.fedoraproject.org
Relocations : (not relocatable)
Packager    : Fedora Project
Vendor      : Fedora Project
URL         : http://ansible.com
Summary     : SSH-based configuration management, deployment, and task execution system
Description :

Ansible is a radically simple model-driven configuration management,
multi-node deployment, and remote task execution system. Ansible works
over SSH and does not require any software or daemons to be installed
on remote nodes. Extension modules can be written in any language and
are transferred to managed machines automatically.
```

##### SUMMARY
When trying to get latest version of a package on target server, ansible doesn't report any new version, even though `yum check-update` does. The package name and repository name are long and I can see (when doing print debugging) ansible gets them broken into multiple lines. I can also see the regex that is supposed to fix this isn't working correctly and puts `'\x01'` in the output instead.

##### STEPS TO REPRODUCE
One way to reproduce is to setup new CentOS7, add repository with long name and update package with long name via ansible yum module.

Since this is troublesome (I have done this in our production, but I don't expect anyone to create the same environment to test this), it is possible to just try the regex in question, located in `modules/packaging/os/yum.py::parse_check_output()` function.

```
>>> re.sub('\n[^\w]\W+(.*)', ' \1', '\n  abc')
' \x01'
```

Obviously, there should be `r` literal like so.

```
>>> re.sub(r'\n[^\w]\W+(.*)', r' \1', '\n  abc')
' abc'
```

##### EXPECTED RESULTS
Multi-line output of `yum check-update` is properly parsed by the `parse_check_output()`  function.

##### ACTUAL RESULTS
The parsing function breaks the output and omits packages with long names.

Related issues: #20608, #20043


Discussion:

Resolving patch:
diff --git a/lib/ansible/modules/packaging/os/yum.py b/lib/ansible/modules/packaging/os/yum.py
--- a/lib/ansible/modules/packaging/os/yum.py
+++ b/lib/ansible/modules/packaging/os/yum.py
@@ -885,7 +885,7 @@ def parse_check_update(check_update_output):
     # ceph.x86_64                               1:11.2.0-0.el7                    ceph
 
     # preprocess string and filter out empty lines so the regex below works
-    out = re.sub('\n[^\w]\W+(.*)', ' \1',
+    out = re.sub(r'\n[^\w]\W+(.*)', r' \1',
                  check_update_output)
 
     available_updates = out.split('\n')


Test patch: