Repository: openshift/openshift-ansible

Issue:
re-run byo playbook fails on task: Create registry certificates
#### Description
Since I busted the metrics deployment I decided to re-run the playbook, which fails on the task *Create registry certificates* (see below).

With grep I found the file: `openshift-ansible/roles/lib_openshift/library/oc_adm_ca_server_cert.py` Where I added a `.decode()` method call to x509output (line 1507), which fixed it for me.

The problem is probably a incorrect use of `subprocess.Popen`. By default the std streams are byte encoded, thus we need to decode them before matching the regexp. 

##### Version

```
ansible 2.2.0.0
Python 3.5.3
Fedora 25
openshift-ansible git-commit b930b55451b
```

##### Steps To Reproduce
run `ansible-playbook playbooks/byo/config.yml` twice

##### Observed Results
The playbook fails with the message

```
TASK [openshift_hosted : Create registry certificates] *************************
fatal: [paas.example.com]: FAILED! => {"changed": false, "failed": true, "module_stderr": "Shared connection to paas.example.com closed.\r\n", "module_stdout": "Traceback (most recent call last):\r\n  File \"/tmp/ansible_952_ce4c/ansible_module_oc_adm_ca_server_cert.py\", line 1607, in <module>\r\n    main()\r\n  File \"/tmp/ansible_952_ce4c/ansible_module_oc_adm_ca_server_cert.py\", line 1599, in main\r\n    results = CAServerCert.run_ansible(module.params, module.check_mode)\r\n  File \"/tmp/ansible_952_ce4c/ansible_module_oc_adm_ca_server_cert.py\", line 1547, in run_ansible\r\n    if not server_cert.exists() or params['force']:\r\n  File \"/tmp/ansible_952_ce4c/ansible_module_oc_adm_ca_server_cert.py\", line 1507, in exists\r\n    match = regex.search(x509output)  # E501\r\nTypeError: cannot use a string pattern on a bytes-like object\r\n", "msg": "MODULE FAILURE"}
```

##### Additional Information

The Python manual says:
> communicate() returns a tuple (stdout_data, stderr_data). The data will be strings if streams were opened in text mode; otherwise, bytes.

and 

> If text mode is not used, stdin, stdout and stderr will be opened as binary streams.

Ref: https://docs.python.org/3.6/library/subprocess.html?highlight=subprocess#frequently-used-arguments


Discussion:
@ObviusOwl, Thanks for reporting this.  I'll test a few scenarios with the supported versions of python and hopefully have a PR soon.

Resolving patch:
diff --git a/roles/lib_openshift/library/oc_adm_ca_server_cert.py b/roles/lib_openshift/library/oc_adm_ca_server_cert.py
--- a/roles/lib_openshift/library/oc_adm_ca_server_cert.py
+++ b/roles/lib_openshift/library/oc_adm_ca_server_cert.py
@@ -1461,7 +1461,7 @@ def exists(self):
         x509output, _ = proc.communicate()
         if proc.returncode == 0:
             regex = re.compile(r"^\s*X509v3 Subject Alternative Name:\s*?\n\s*(.*)\s*\n", re.MULTILINE)
-            match = regex.search(x509output)  # E501
+            match = regex.search(x509output.decode())  # E501
             if not match:
                 return False
 
diff --git a/roles/lib_openshift/src/class/oc_adm_ca_server_cert.py b/roles/lib_openshift/src/class/oc_adm_ca_server_cert.py
--- a/roles/lib_openshift/src/class/oc_adm_ca_server_cert.py
+++ b/roles/lib_openshift/src/class/oc_adm_ca_server_cert.py
@@ -77,7 +77,7 @@ def exists(self):
         x509output, _ = proc.communicate()
         if proc.returncode == 0:
             regex = re.compile(r"^\s*X509v3 Subject Alternative Name:\s*?\n\s*(.*)\s*\n", re.MULTILINE)
-            match = regex.search(x509output)  # E501
+            match = regex.search(x509output.decode())  # E501
             if not match:
                 return False
 


Test patch: