Closed thanos1983 closed 3 years ago
Hi @thanos1983,
The problem seems to actually be this error: readUint32: unexpected character: \\\\ufffd, error found in #10 byte of ...|nerPort
. It looks like you've got some unexpected characters either in the variable configuration file or maybe in the playbook itself. These UTF8 characters are not displayed by text-editor and may be hard to find.
Hi @thanos1983,
The problem seems to actually be this error:
readUint32: unexpected character: \\\\ufffd, error found in #10 byte of ...|nerPort
. It looks like you've got some unexpected characters either in the variable configuration file or maybe in the playbook itself. These UTF8 characters are not displayed by text-editor and may be hard to find.
Hello @goneri,
I do not think that the problem is there. In my vars file I pass the variable as e.g.:
containerPort: 80
I tried also to pass it as string e.g.:
containerPort: "80"
Then I cast it to int e.g.:
containerPort: "{{ containerPort | int }}"
But none of them worked.
My workaround for the moment is that I am using templates with the module e.g. (from documentation examples):
- name: Read definition template file from the Ansible controller file system
community.kubernetes.k8s:
state: present
template: '/testing/deployment.j2'
Where I can pass the variables without any problems. I think the error is misleading but it is up to you to close the ticket if you can not replicate it :).
BR / Thanos
I just took a look at our melecule test, and we pass a dict to the template
... and it works. So I'm a bit confused.
I just took a look at our melecule test, and we pass a dict to the
template
... and it works. So I'm a bit confused.
I get the same error when I replace also the var:
replicas: 2
In the example provided above I have used an int directly so the script is complaining when you use the plain text deployment. When using template I also use dictionaries with int variables on this values.
From my understanding it seems that the plain text is not able to parse the dictionary when it comes to int. I also tried to run:
cat -A k8s_sample_deployment.yml
But I did not see any weird characters that could explain the error. After all I am passing the var through dictionary that is coming from the vars file. Another alternative way that I was recommended by the stackoverflow/How to use k8s Ansible module without quotes? is to use Formatting data: YAML and JSON/from_yaml.
So in conclusion with plain text and int from vars it can not be used. Unless use template. The strings are parsed just fine the int is the problem. Some tricky is happening there.
Hope this helps.
BR / Thanos
Hi @thanos1983, May I ask you to playbook on a github repository that reproduce the issue?
Hi @thanos1983, May I ask you to playbook on a github repository that reproduce the issue?
Hello again @goneri,
I was replicating the code and I noticed that there was a new version of the package:
$ python3 -m pip show k8s
Name: k8s
Version: 0.17.0
Summary: Python client library for the Kubernetes API
Home-page: https://github.com/fiaas/k8s
Author: FiaaS developers
Author-email: fiaas@googlegroups.com
License: Apache License
Location: /usr/local/lib/python3.8/dist-packages
Requires: requests, pyrfc3339, six, cachetools
I updated and the problem is fixed.
We can close the ticket. :)
Thank you for your time and effort to help me.
Great! Thank you for the update.
SUMMARY
I am trying to use the module community.kubernetes.k8s – Manage Kubernetes (K8s) objects with variables from the role (e.g. role/sampleRole/vars file).
I am failing when it comes to the integer point e.g.:
When I deploy with this format obviously it will fail at it can not parse the "reference" to the var.
Sample of error:
When I use quotes on the variable e.g.
- containerPort: "{{ containerPort }}"
then I get the following error (part of it):I tried to cast the string to int by using
- containerPort: "{{ containerPort | int }}"
but it did not worked. The problem seems to be coming from the quotes, independently how I define the var in my var file e.g.containerPort: 80
orcontainerPort: "80"
.I found a similar question on the forum stackoverflow Ansible, k8s and variables but the user seems not to have the same problems that I am having.
I am running with the latest version of the module:
Is there any workaround this problem or is it a bug?
ISSUE TYPE
COMPONENT NAME
module community.kubernetes.k8s – Manage Kubernetes (K8s) objects
ANSIBLE VERSION
CONFIGURATION
OS / ENVIRONMENT
STEPS TO REPRODUCE
Simply create a small demo and try to deploy on a master node.
EXPECTED RESULTS
Expected result would be that the module can parse the string (or casted int) and not produce this error.
ACTUAL RESULTS