New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
k8s_raw unicode_error when using jinja lookup templating #40185
Comments
Files identified in the description: If these files are inaccurate, please update the |
Could you post an example of your |
Files identified in the description: If these files are inaccurate, please update the |
I am getting this exact error even without a Here's how to reproduce.
It fails on |
I see the same issue and it can be simplified down to the following. If you try to set |
so if you use |
@fabianvf Using Ansible 2.6 stable and latest openshift and kubernetes clients I get the following even with the cast to int:
|
it seems that doing ---
- name: K8s
hosts: localhost
gather_facts: no
vars:
test:
replicas: 4
testreplicas: 4
tasks:
- name: Create test deployment
debug: var=numreplicas
vars:
numreplicas:
replicas: "{{ test.replicas }}"
- name: Create test deployment
debug: var=numreplicas
vars:
numreplicas:
replicas: "{{ testreplicas }}"
Bizarrely, if I add cast testreplicas (the one that is properly an int) to int, it will turn into a string. ---
- name: K8s
hosts: localhost
gather_facts: no
vars:
testreplicas: 4
tasks:
- name: Create test deployment
debug: var=numreplicas
vars:
numreplicas:
replicas: "{{ testreplicas }}"
- name: Create test deployment
debug: var=numreplicas
vars:
numreplicas:
replicas: "{{ testreplicas|int }}"
|
Yes, this is a side effect of the interactions between Ansible and Jinja2. The new jinja2 native types functionality coming in Ansible 2.7 solves this (#32738) Unfortunately, with a module such as |
* workaround ansible/ansible#40185 * Create rolebinding with Ansible module * remove unnecessary oc command * explicitly define project with annotations * _exec -> exec * {openshift|k8s}_raw -> k8s * Update required ansible version * use oc command until ansible/ansible#42116 is fixed
I strongly recommend using a template
and then you can do things like |
Files identified in the description: If these files are inaccurate, please update the |
Files identified in the description: If these files are inaccurate, please update the |
Files identified in the description: If these files are inaccurate, please update the |
* workaround ansible/ansible#40185 * Create rolebinding with Ansible module * remove unnecessary oc command * explicitly define project with annotations * _exec -> exec * {openshift|k8s}_raw -> k8s * Update required ansible version * use oc command until ansible/ansible#42116 is fixed
close_me I think the proper resolution if you're hitting this issue is to put your definition into a template instead of inline, which will allow you to not add the quotes and will allow the yaml loader to properly recognize the type. |
Files identified in the description: If these files are incorrect, please update the |
ISSUE TYPE
COMPONENT NAME
k8s_raw
ANSIBLE VERSION
CONFIGURATION
DEFAULT_BECOME(/etc/ansible/ansible.cfg) = True
DEFAULT_BECOME_ASK_PASS(/etc/ansible/ansible.cfg) = False
DEFAULT_BECOME_METHOD(/etc/ansible/ansible.cfg) = sudo
DEFAULT_BECOME_USER(/etc/ansible/ansible.cfg) = root
DEFAULT_HASH_BEHAVIOUR(/etc/ansible/ansible.cfg) = merge
DEFAULT_MODULE_PATH(/etc/ansible/ansible.cfg) = [u'/etc/ansible/library']
DEFAULT_REMOTE_USER(/etc/ansible/ansible.cfg) = ansible
DEFAULT_ROLES_PATH(/etc/ansible/ansible.cfg) = [u'/etc/ansible/roles']
HOST_KEY_CHECKING(/etc/ansible/ansible.cfg) = False
PERSISTENT_CONNECT_TIMEOUT(/etc/ansible/ansible.cfg) = 30
OS / ENVIRONMENT
Centos
SUMMARY
We are trying to use the k8s_raw module with jinja template. The issue is that when we use the task like this:
k8s_raw:
state: present
definition: "{{ lookup('file', '/testing/deployment.yml') | from_yaml }}"
We are having exception:
The full traceback is:
Traceback (most recent call last):
File "/tmp/ansible_bpILrC/ansible_module_k8s_raw.py", line 163, in
main()
File "/tmp/ansible_bpILrC/ansible_module_k8s_raw.py", line 159, in main
KubernetesRawModule().execute_module()
File "/tmp/ansible_bpILrC/ansible_modlib.zip/ansible/module_utils/k8s/raw.py", line 121, in execute_module
File "/tmp/ansible_bpILrC/ansible_modlib.zip/ansible/module_utils/k8s/raw.py", line 170, in _create
UnicodeEncodeError: 'ascii' codec can't encode character u'\ufffd' in position 171: ordinal not in range(128)
fatal: [k8s -> localhost]: FAILED! => {
"changed": false,
"module_stderr": "Traceback (most recent call last):\n File "/tmp/ansible_bpILrC/ansible_module_k8s_raw.py", line 163, in \n main()\n File "/tmp/ansible_bpILrC/ansible_module_k8s_raw.py", line 159, in main\n KubernetesRawModule().execute_module()\n File "/tmp/ansible_bpILrC/ansible_modlib.zip/ansible/module_utils/k8s/raw.py", line 121, in execute_module\n File "/tmp/ansible_bpILrC/ansible_modlib.zip/ansible/module_utils/k8s/raw.py", line 170, in _create\nUnicodeEncodeError: 'ascii' codec can't encode character u'\ufffd' in position 171: ordinal not in range(128)\n",
"module_stdout": "",
"msg": "MODULE FAILURE",
"rc": 1
STEPS TO REPRODUCE
EXPECTED RESULTS
ACTUAL RESULTS
TASK [devops-k8s-service : Create a Service object from an inline definition] *************************************************************************************************************************************
task path: /etc/ansible/roles/devops-k8s-service/tasks/main.yml:1
looking for "service.yml" at "/etc/ansible/roles/devops-k8s-service/templates/service.yml"
File lookup using /etc/ansible/roles/devops-k8s-service/templates/service.yml as file
Using module file /usr/lib/python2.7/site-packages/ansible/modules/clustering/k8s/k8s_raw.py
ESTABLISH LOCAL CONNECTION FOR USER: ansible
EXEC /bin/sh -c 'echo ~ && sleep 0'
EXEC /bin/sh -c '( umask 77 && mkdir -p "
echo /home/ansible/.ansible/tmp/ansible-tmp-1526406851.13-36098482327457
" && echo ansible-tmp-1526406851.13-36098482327457="echo /home/ansible/.ansible/tmp/ansible-tmp-1526406851.13-36098482327457
" ) && sleep 0'PUT /home/ansible/.ansible/tmp/ansible-local-281449WIXrE/tmpr4OG3F TO /home/ansible/.ansible/tmp/ansible-tmp-1526406851.13-36098482327457/k8s_raw.py
EXEC /bin/sh -c 'chmod u+x /home/ansible/.ansible/tmp/ansible-tmp-1526406851.13-36098482327457/ /home/ansible/.ansible/tmp/ansible-tmp-1526406851.13-36098482327457/k8s_raw.py && sleep 0'
EXEC /bin/sh -c 'sudo -H -S -n -u root /bin/sh -c '"'"'echo BECOME-SUCCESS-sdpatlhciheqdvbadkknmlopegvqibfl; /usr/bin/python2 /home/ansible/.ansible/tmp/ansible-tmp-1526406851.13-36098482327457/k8s_raw.py'"'"' && sleep 0'
EXEC /bin/sh -c 'rm -f -r /home/ansible/.ansible/tmp/ansible-tmp-1526406851.13-36098482327457/ > /dev/null 2>&1 && sleep 0'
The full traceback is:
Traceback (most recent call last):
File "/tmp/ansible_bpILrC/ansible_module_k8s_raw.py", line 163, in
main()
File "/tmp/ansible_bpILrC/ansible_module_k8s_raw.py", line 159, in main
KubernetesRawModule().execute_module()
File "/tmp/ansible_bpILrC/ansible_modlib.zip/ansible/module_utils/k8s/raw.py", line 121, in execute_module
File "/tmp/ansible_bpILrC/ansible_modlib.zip/ansible/module_utils/k8s/raw.py", line 170, in _create
UnicodeEncodeError: 'ascii' codec can't encode character u'\ufffd' in position 171: ordinal not in range(128)
fatal: [k8s -> localhost]: FAILED! => {
"changed": false,
"module_stderr": "Traceback (most recent call last):\n File "/tmp/ansible_bpILrC/ansible_module_k8s_raw.py", line 163, in \n main()\n File "/tmp/ansible_bpILrC/ansible_module_k8s_raw.py", line 159, in main\n KubernetesRawModule().execute_module()\n File "/tmp/ansible_bpILrC/ansible_modlib.zip/ansible/module_utils/k8s/raw.py", line 121, in execute_module\n File "/tmp/ansible_bpILrC/ansible_modlib.zip/ansible/module_utils/k8s/raw.py", line 170, in _create\nUnicodeEncodeError: 'ascii' codec can't encode character u'\ufffd' in position 171: ordinal not in range(128)\n",
"module_stdout": "",
"msg": "MODULE FAILURE",
"rc": 1
}
The text was updated successfully, but these errors were encountered: