Repository: openshift/openshift-ansible

Issue:
installation of Logging fails on "Gather OpenShift Logging Facts"
#### Description

On a developer setup, using Fedora 25 as the OS and executing `cd ${GOPATH}/src/github.com/openshift/origin/_output/local/bin/linux/amd64 && sudo ./openshift start` for an OpenShift cluster, the Ansible Playbook for Logging fails during the task "Gather OpenShift Logging Facts".

This is the script that is used to install Logging via the playbook:

https://paste.fedoraproject.org/paste/TAxemZhC59HT-WMGxTiVBl5M1UNdIGYhyRLivL9gydE=
```bash
#!/bin/bash

cat > /tmp/metrics.inventory <<EOF
[oo_first_master]
openshift

[oo_first_master:vars]
#openshift_deployment_type=origin
#openshift_release=v3.6
#openshift_image_tag=v3.6.0
#openshift_metrics_image_prefix=registry.ops.openshift.com/openshift3
#openshift_metrics_image_version=3.6.0

openshift_deployment_type=origin
openshift_release=v1.5
openshift_image_tag=v1.5.0
openshift_logging_install_logging=true

# for more options, see https://github.com/openshift/openshift-ansible/blob/master/roles/openshift_logging/defaults/main.yml
EOF

sudo ansible-playbook /mnt/storage/jpkroehling/Projects/ansible/src/github.com/openshift/openshift-ansible/playbooks/byo/openshift-cluster/openshift-logging.yml \
	-vv \
	-e 'ansible_python_interpreter=/usr/bin/python3' \
	-c local \
	-i /tmp/metrics.inventory
```

This is the actual message:

https://paste.fedoraproject.org/paste/IZ06Z5xI2bmOxGg8nK4RRl5M1UNdIGYhyRLivL9gydE=
```
TASK [openshift_logging : Gather OpenShift Logging Facts] *********************************************************************************************************************************************************
task path: /mnt/storage/jpkroehling/Projects/ansible/src/github.com/openshift/openshift-ansible/roles/openshift_logging/tasks/install_logging.yaml:2
fatal: [openshift]: FAILED! => {"changed": false, "failed": true, "msg": "There was an exception trying to run the command 'oc get routes -n logging --user=system:admin/192-168-2-111:8443 --config=/tmp/openshift-logging-ansible-QNj1vf/admin.kubeconfig -o json -l component=support, logging-infra=support, provider=openshift' a bytes-like object is required, not 'str'"}
	to retry, use: --limit @/mnt/storage/jpkroehling/Projects/ansible/src/github.com/openshift/openshift-ansible/playbooks/byo/openshift-cluster/openshift-logging.retry

PLAY RECAP ********************************************************************************************************************************************************************************************************
localhost                  : ok=2    changed=0    unreachable=0    failed=0   
openshift                  : ok=19   changed=0    unreachable=0    failed=1   
```

##### Version

```bash
$ 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.13 (default, Jan 12 2017, 17:59:37) [GCC 6.3.1 20161221 (Red Hat 6.3.1-1)]
$ git describe
openshift-ansible-3.6.67-1-28-g74e4c9d
```


Discussion:
This is similar to issue #4182. One can modify the return in OCBaseCommand (openshift_logging_facts.py) to return `json.loads(out.decode())`, but perhaps six should be used instead.

For the record, this was the second of three issues hit while trying to use python 3. The third issue was in Ansible and has already been fixed: https://github.com/ansible/ansible/commit/08a3ea22210f17731ea94c077625cc9bb85dd45b
I updated that line to `json.loads(out.decode())` but then I still get this:

```
The full traceback is:
  File "/tmp/ansible_2e3oc5a0/ansible_module_openshift_logging_facts.py", line 334, in main
    ansible_facts={"openshift_logging_facts": cmd.build_facts()}
  File "/tmp/ansible_2e3oc5a0/ansible_module_openshift_logging_facts.py", line 313, in build_facts
    self.facts_for_rolebindings(self.namespace)
  File "/tmp/ansible_2e3oc5a0/ansible_module_openshift_logging_facts.py", line 275, in facts_for_rolebindings
    role = self.oc_command("get", "rolebindings", namespace=namespace, name="logging-elasticsearch-view-role")
  File "/tmp/ansible_2e3oc5a0/ansible_module_openshift_logging_facts.py", line 86, in oc_command
    raise Exception(err)

fatal: [master1]: FAILED! => {
    "changed": false, 
    "failed": true, 
    "invocation": {
        "module_args": {
            "admin_kubeconfig": "/etc/origin/master/admin.kubeconfig", 
            "oc_bin": "/usr/local/bin/oc", 
            "openshift_logging_namespace": "logging"
        }
    }, 
    "msg": "There was an exception trying to run the command '/usr/local/bin/oc get rolebindings logging-elasticsearch-view-role -n logging --user=system:admin/ip-172-31-14-163-ec2-internal:8443 --config=/etc/origin/master/admin.kubeconfig -o json' a bytes-like object is required, not 'str'"
```

looks like the same bug but can't pinpoint where to change anything

ansible 2.4.0.0
python 2.7.5 (on bastion)
fedora 26 atomic (python 3 on those hosts)
latest release-3.6
I do also have the issue trying to enable logging in origin 3.7 on Fedora 27 Atomic (python3 enforced).
The funny thing is that when I try to execute the command on the targeted host directly:
```
[fedora@master-0 ~]$ sudo /usr/local/bin/oc get rolebindings logging-elasticsearch-view-role -n logging --user=system:admin/openshift-oc-example-com:8443 --config=/etc/origin/master/admin.kubeconfig 
Error from server (NotFound): rolebindings "logging-elasticsearch-view-role" not found
```
I have tested this against 3.6 with Fedora Atomic 27 and Centos-7 Atomic, and Centos works fine.  Maybe the python3 stuff?

It's too bad that fedora doesn't get more love here, since it's build as "Optimized for Kubernetes and OpenShift" on the Atomic website :(

Also hitting this on Fedora 28 Atomic Host and OpenShift Origin 3.10.

Resolving patch:
diff --git a/roles/openshift_logging/library/openshift_logging_facts.py b/roles/openshift_logging/library/openshift_logging_facts.py
--- a/roles/openshift_logging/library/openshift_logging_facts.py
+++ b/roles/openshift_logging/library/openshift_logging_facts.py
@@ -75,6 +75,7 @@ def oc_command(self, sub, kind, namespace=None, name=None, add_options=None):
         try:
             process = Popen(cmd, stdout=PIPE, stderr=PIPE)   # noqa: F405
             out, err = process.communicate(cmd)
+            err = err.decode(encoding='utf8', errors='replace')
             if len(err) > 0:
                 if 'not found' in err:
                     return {'items': []}


Test patch: