Skip to content
This repository has been archived by the owner on Jul 17, 2023. It is now read-only.

Create Server Fails - UnicodeEncodeError: 'ascii' codec can't encode character u'\\xe3' in position 1: ordinal not in range(128)\n #31

Open
stuevansuk opened this issue Jun 8, 2022 · 10 comments

Comments

@stuevansuk
Copy link

Not sure if this is due to the API change, but my Ansible Runs are failing with the following output, the only change in my playbook is around the plan definition, this has now changed on the Vultr API to "vc2-2c-4gb"

ESTABLISH LOCAL CONNECTION FOR USER: root
EXEC /bin/sh -c 'echo ~root && sleep 0'
EXEC /bin/sh -c '( umask 77 && mkdir -p "echo /root/.ansible/tmp"&& mkdir "echo /root/.ansible/tmp/ansible-tmp-1654631972.6608722-30354-211416328878133" && echo ansible-tmp-1654631972.6608722-30354-211416328878133="echo /root/.ansible/tmp/ansible-tmp-1654631972.6608722-30354-211416328878133" ) && sleep 0'
redirecting (type: modules) ansible.builtin.vultr_server to ngine_io.vultr.vultr_server
Using module file /root/.local/lib/python3.6/site-packages/ansible_collections/ngine_io/vultr/plugins/modules/vultr_server.py
PUT /root/.ansible/tmp/ansible-local-30249c_wa2x6q/tmpy541dbze TO /root/.ansible/tmp/ansible-tmp-1654631972.6608722-30354-211416328878133/AnsiballZ_vultr_server.py
EXEC /bin/sh -c 'chmod u+x /root/.ansible/tmp/ansible-tmp-1654631972.6608722-30354-211416328878133/ /root/.ansible/tmp/ansible-tmp-1654631972.6608722-30354-211416328878133/AnsiballZ_vultr_server.py && sleep 0'
EXEC /bin/sh -c '/usr/bin/python /root/.ansible/tmp/ansible-tmp-1654631972.6608722-30354-211416328878133/AnsiballZ_vultr_server.py && sleep 0'
EXEC /bin/sh -c 'rm -f -r /root/.ansible/tmp/ansible-tmp-1654631972.6608722-30354-211416328878133/ > /dev/null 2>&1 && sleep 0'
The full traceback is:
Traceback (most recent call last):
File "/root/.ansible/tmp/ansible-tmp-1654631972.6608722-30354-211416328878133/AnsiballZ_vultr_server.py", line 100, in
_ansiballz_main()
File "/root/.ansible/tmp/ansible-tmp-1654631972.6608722-30354-211416328878133/AnsiballZ_vultr_server.py", line 92, in _ansiballz_main
invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
File "/root/.ansible/tmp/ansible-tmp-1654631972.6608722-30354-211416328878133/AnsiballZ_vultr_server.py", line 41, in invoke_module
run_name='main', alter_sys=True)
File "/usr/lib64/python2.7/runpy.py", line 176, in run_module
fname, loader, pkg_name)
File "/usr/lib64/python2.7/runpy.py", line 82, in _run_module_code
mod_name, mod_fname, mod_loader, pkg_name)
File "/usr/lib64/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File "/tmp/ansible_vultr_server_payload_hLoMA8/ansible_vultr_server_payload.zip/ansible_collections/ngine_io/vultr/plugins/modules/vultr_server.py", line 933, in
File "/tmp/ansible_vultr_server_payload_hLoMA8/ansible_vultr_server_payload.zip/ansible_collections/ngine_io/vultr/plugins/modules/vultr_server.py", line 926, in main
File "/tmp/ansible_vultr_server_payload_hLoMA8/ansible_vultr_server_payload.zip/ansible_collections/ngine_io/vultr/plugins/modules/vultr_server.py", line 508, in present_server
File "/tmp/ansible_vultr_server_payload_hLoMA8/ansible_vultr_server_payload.zip/ansible_collections/ngine_io/vultr/plugins/modules/vultr_server.py", line 529, in _create_server
File "/tmp/ansible_vultr_server_payload_hLoMA8/ansible_vultr_server_payload.zip/ansible_collections/ngine_io/vultr/plugins/modules/vultr_server.py", line 444, in get_region
File "/tmp/ansible_vultr_server_payload_hLoMA8/ansible_vultr_server_payload.zip/ansible_collections/ngine_io/vultr/plugins/module_utils/vultr.py", line 248, in query_resource_by_key
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe3' in position 1: ordinal not in range(128)
fatal: [localhost -> localhost]: FAILED! => {
"changed": false,
"module_stderr": "Traceback (most recent call last):\n File "/root/.ansible/tmp/ansible-tmp-1654631972.6608722-30354-211416328878133/AnsiballZ_vultr_server.py", line 100, in \n _ansiballz_main()\n File "/root/.ansible/tmp/ansible-tmp-1654631972.6608722-30354-211416328878133/AnsiballZ_vultr_server.py", line 92, in _ansiballz_main\n invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n File "/root/.ansible/tmp/ansible-tmp-1654631972.6608722-30354-211416328878133/AnsiballZ_vultr_server.py", line 41, in invoke_module\n run_name='main', alter_sys=True)\n File "/usr/lib64/python2.7/runpy.py", line 176, in run_module\n fname, loader, pkg_name)\n File "/usr/lib64/python2.7/runpy.py", line 82, in _run_module_code\n mod_name, mod_fname, mod_loader, pkg_name)\n File "/usr/lib64/python2.7/runpy.py", line 72, in _run_code\n exec code in run_globals\n File "/tmp/ansible_vultr_server_payload_hLoMA8/ansible_vultr_server_payload.zip/ansible_collections/ngine_io/vultr/plugins/modules/vultr_server.py", line 933, in \n File "/tmp/ansible_vultr_server_payload_hLoMA8/ansible_vultr_server_payload.zip/ansible_collections/ngine_io/vultr/plugins/modules/vultr_server.py", line 926, in main\n File "/tmp/ansible_vultr_server_payload_hLoMA8/ansible_vultr_server_payload.zip/ansible_collections/ngine_io/vultr/plugins/modules/vultr_server.py", line 508, in present_server\n File "/tmp/ansible_vultr_server_payload_hLoMA8/ansible_vultr_server_payload.zip/ansible_collections/ngine_io/vultr/plugins/modules/vultr_server.py", line 529, in _create_server\n File "/tmp/ansible_vultr_server_payload_hLoMA8/ansible_vultr_server_payload.zip/ansible_collections/ngine_io/vultr/plugins/modules/vultr_server.py", line 444, in get_region\n File "/tmp/ansible_vultr_server_payload_hLoMA8/ansible_vultr_server_payload.zip/ansible_collections/ngine_io/vultr/plugins/module_utils/vultr.py", line 248, in query_resource_by_key\nUnicodeEncodeError: 'ascii' codec can't encode character u'\xe3' in position 1: ordinal not in range(128)\n",
"module_stdout": "",
"msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
"rc": 1
}

@resmo
Copy link
Member

resmo commented Jun 8, 2022

@stuevansuk I think, there is typo in your configs for creating a vultr server with an unexpected unicode char. According to my quick research, this should be an ã (a-tilde). Could you check that?

@stuevansuk
Copy link
Author

Had a good look and cant see anything, created a simple playbook and this is still failing with the same error;


- name: Provision & Bootstrap New node
  hosts: localhost
  connection: local
  gather_facts: true

  tasks:

  - name: Provision Node.....

    block:

      - name: Provision - Create Vultr Instance
        local_action:
          module: vultr_server
          name: "test"
          os: "CentOS 7 x64"
          plan: "vc2-2c-4gb"
          firewall_group: "desktops"
          ssh_key: "macbookpro"
          region: "AMS"
        register: vultr

Not sure if I'm missing somehing or you can validate?

@resmo
Copy link
Member

resmo commented Jun 8, 2022

I see so, the thing is, this modules still uses the old API v1 and plan "vc2-2c-4gb" is a plan of the API v2. To get the v1 plans you have to use the vultr-cli https://github.com/vultr/vultr-cli/releases/tag/v1.0.0

the plan "vc2-c2-4gb" would be the ID 203 or "4096 MB RAM,80 GB SSD,3.00 TB BW"
the region AMS would be "Amsterdam" or ID 7

@stuevansuk
Copy link
Author

Oh nice that's great! I hadn't realised the v1 view was available in that formMany thanks for your help, I can transfer across now and continue to work..

Looking forward to your new module deployment and instance management within that.

Many thanks again, great work!

@resmo
Copy link
Member

resmo commented Jun 8, 2022

You're welcome, thanks for your patience, I'll let you know when the new instance module is ready.

@stuevansuk
Copy link
Author

stuevansuk commented Jun 8, 2022

I think I spoke too soon! Still no luck with the following playbook;

- name: Provision & Bootstrap New node
  hosts: localhost
  connection: local
  gather_facts: true

  tasks:

  - name: Provision Node.....

    block:

          - name: Provision - Create Vultr Instance
            local_action:
              module: vultr_server
              name: "test"
              os: "CentOS 7 x64"
              plan:  "4096 MB RAM,80 GB SSD,3.00 TB BW"
              firewall_group: "desktops"
              ssh_key: "macbookpro"
              region: "Amsterdam"
            register: vultr

Also comes with the same error;

An exception occurred during task execution. To see the full traceback, use -vvv. The error was: UnicodeEncodeError: 'ascii' codec can't encode character u'\xe3' in position 1: ordinal not in range(128)
fatal: [localhost -> localhost]: FAILED! => {"changed": false, "module_stderr": "Traceback (most recent call last):\n File "/root/.ansible/tmp/ansible-tmp-1654709592.784049-1281-244008263945931/AnsiballZ_vultr_server.py", line 100, in \n _ansiballz_main()\n File "/root/.ansible/tmp/ansible-tmp-1654709592.784049-1281-244008263945931/AnsiballZ_vultr_server.py", line 92, in _ansiballz_main\n invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n File "/root/.ansible/tmp/ansible-tmp-1654709592.784049-1281-244008263945931/AnsiballZ_vultr_server.py", line 41, in invoke_module\n run_name='main', alter_sys=True)\n File "/usr/lib64/python2.7/runpy.py", line 176, in run_module\n fname, loader, pkg_name)\n File "/usr/lib64/python2.7/runpy.py", line 82, in _run_module_code\n mod_name, mod_fname, mod_loader, pkg_name)\n File "/usr/lib64/python2.7/runpy.py", line 72, in _run_code\n exec code in run_globals\n File "/tmp/ansible_vultr_server_payload_nOUmTd/ansible_vultr_server_payload.zip/ansible_collections/ngine_io/vultr/plugins/modules/vultr_server.py", line 933, in \n File "/tmp/ansible_vultr_server_payload_nOUmTd/ansible_vultr_server_payload.zip/ansible_collections/ngine_io/vultr/plugins/modules/vultr_server.py", line 926, in main\n File "/tmp/ansible_vultr_server_payload_nOUmTd/ansible_vultr_server_payload.zip/ansible_collections/ngine_io/vultr/plugins/modules/vultr_server.py", line 508, in present_server\n File "/tmp/ansible_vultr_server_payload_nOUmTd/ansible_vultr_server_payload.zip/ansible_collections/ngine_io/vultr/plugins/modules/vultr_server.py", line 529, in _create_server\n File "/tmp/ansible_vultr_server_payload_nOUmTd/ansible_vultr_server_payload.zip/ansible_collections/ngine_io/vultr/plugins/modules/vultr_server.py", line 444, in get_region\n File "/tmp/ansible_vultr_server_payload_nOUmTd/ansible_vultr_server_payload.zip/ansible_collections/ngine_io/vultr/plugins/module_utils/vultr.py", line 248, in query_resource_by_key\nUnicodeEncodeError: 'ascii' codec can't encode character u'\xe3' in position 1: ordinal not in range(128)\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}

Running Centos 7 with Python 3.9 and Python System on 2.6

@resmo
Copy link
Member

resmo commented Jun 8, 2022

I can not reproduce:
created a playbook, quite identical to yours

- name: Provision & Bootstrap New node
  hosts: localhost
  connection: local
  gather_facts: false
  tasks:
    - name: Provision Node.....
      block:
        - name: Provision - Create Vultr Instance
          vultr_server:
            name: "test"
            os: "CentOS 7 x64"
            plan: "4096 MB RAM,80 GB SSD,3.00 TB BW"
            firewall_group: "default"
            ssh_key: "resmo"
            region: "Amsterdam"
          register: vultr

ran it:

 $ ansible-playbook test.yml
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'

PLAY [Provision & Bootstrap New node] *******************************************************************************************************************************

TASK [Provision - Create Vultr Instance] ****************************************************************************************************************************
changed: [localhost]

PLAY RECAP **********************************************************************************************************************************************************
localhost                  : ok=1    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

verified it

 $ vultr-cli instance list
ID                                      IP              LABEL   OS              STATUS  Region  CPU     RAM     DISK    BANDWIDTH
7e2ac4c8-9397-40cd-9fed-dd4797af3602    78.141.222.137  test    CentOS 7 x64    active  ams     2       4096    80      3000

what does ansible --version return?

@stuevansuk
Copy link
Author

Interesting? What OS are you using? Im wondering if its due to some OS makeup?

ansible [core 2.11.11]
config file = /etc/ansible/ansible.cfg
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /root/.local/lib/python3.6/site-packages/ansible
ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
executable location = /root/.local/bin/ansible
python version = 3.6.8 (default, Nov 16 2020, 16:55:22) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)]
jinja version = 3.0.3
libyaml = True

@stuevansuk
Copy link
Author

Deployed a Centos 8 Stream Machine with Ansible and works fine, issue seems to be related to be with Centos 7, deployed a Centos 7 machine from scratch and failed with same result. Will research more.

@resmo
Copy link
Member

resmo commented Dec 17, 2022

i wanted to let you know that vultr.cloud (https://github.com/vultr/ansible-collection-vultr) now includes an instance module. The arguments have changed a bit but not that much. Give it a shot https://docs.ansible.com/ansible/latest/collections/vultr/cloud/instance_module.html#ansible-collections-vultr-cloud-instance-module (btw, VPC support in the module is ready in 1.5.0)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants