Skip to content
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

int() argument must be a string, a bytes-like object or a number, not 'NoneType' #3844

Closed
1 task done
bitshiftnetau opened this issue Dec 4, 2021 · 22 comments · Fixed by #3874
Closed
1 task done
Labels
bug This issue/PR relates to a bug cloud module module plugins plugin (any type)

Comments

@bitshiftnetau
Copy link

bitshiftnetau commented Dec 4, 2021

Summary

When I try to create a container on Proxmox, it fails saying that "fatal: [central.local]: FAILED! => {"changed": false, "msg": "creation of lxc VM 810 failed with exception: int() argument must be a string, a bytes-like object or a number, not 'NoneType'"}"

Issue Type

Bug Report

Component Name

community.general.proxmox

Ansible Version

$ ansible --version
ansible [core 2.12.0]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.9/site-packages/ansible
  ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.9.9 (main, Nov 20 2021, 21:30:06) [GCC 11.1.0]
  jinja version = 3.0.3
  libyaml = True

Community.general Version

$ ansible-galaxy collection list community.general
# /usr/lib/python3.9/site-packages/ansible_collections
Collection        Version
----------------- -------
community.general 4.0.2  

# /root/.ansible/collections/ansible_collections
Collection        Version
----------------- -------
community.general 4.1.0 

Configuration

$ ansible-config dump --only-changed
INVENTORY_ENABLED(/etc/ansible/ansible.cfg) = ['yaml', 'ini']

OS / Environment

Arch Linux in LXC on Proxmox (although I get the exact same errors running from a bare-metal install of Arch Linux)

Steps to Reproduce

---Playbook extracted from proxmox documentation---

- name: Create new LXC container in Proxmox
  hosts: central.local
  tasks:
    - name: testing
      proxmox:
        vmid: 810
        node: central
        api_user: root@pam
        api_password: <password>
        api_host: central
        password: 123456
        hostname: example.org
        ostemplate: 'local:vztmpl/archlinux-base_20210420-1_amd64.tar.gz'


---Custom playbook---

- name: Create new LXC container in Proxmox
  hosts: 'central.local'
  tasks:
    - name: 'Create container'
      proxmox:
- name: Create new LXC container in Proxmox
  hosts: 'central.local'
  tasks:
    - name: 'Create container'
      proxmox:
        vmid: '810' # specifying container ID
        api_user: 'root@pam' # Proxmox user
        api_password: '' # password in plaintext
        api_host: 'central.local' # proxmox hostname
        password: 'password' # container password in plaintext
        hostname: 'CT-Prometheus-ArchLinux' # container hostname
        node: 'central' # name of proxmox host
        cores: '1'
        cpus: '2'
        cpuunits: '1000'
        ostemplate: 'local:vztmpl/archlinux-base_20210420-1_amd64.tar.gz'
        storage: 'VMs'
        disk: '16'
        memory: '512'
        nameserver: '8.8.8.8'
        netif: '{"net0":"name=eth0,ip=dhcp,bridge=vmbr10"}'
        state: 'present'

Expected Results

I expect it to connect and create a container.

Actual Results

ansible-playbook playbooks/vm_template_2.yml --user root@pam --ask-pass
SSH password: 

PLAY [Create new LXC container in Proxmox] *********************************************

TASK [Gathering Facts] *****************************************************************
ok: [central.local]

TASK [testing] *************************************************************************
fatal: [central.local]: FAILED! => {"changed": false, "msg": "creation of lxc VM 810 failed with exception: int() argument must be a string, a bytes-like object or a number, not 'NoneType'"}

PLAY RECAP *****************************************************************************
central.local              : ok=1    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   

Code of Conduct

  • I agree to follow the Ansible Code of Conduct
@ansibullbot
Copy link
Collaborator

Files identified in the description:

  • plugins/modules/cloud/misc/proxmox

If these files are incorrect, please update the component name section of the description or use the !component bot command.

click here for bot help

@ansibullbot
Copy link
Collaborator

@ansibullbot ansibullbot added bug This issue/PR relates to a bug cloud module module plugins plugin (any type) labels Dec 4, 2021
@bitshiftnetau
Copy link
Author

bitshiftnetau commented Dec 4, 2021

This issue is resolved following a full system reboot of proxmox. Cannot say for other systems but it should be noted in the community docs if anyone else can replicate this error.

EDIT: this was a false positive. System reboot did not restore. See below.

@bitshiftnetau
Copy link
Author

I spoke too soon. It appears incapable of creating a new container.

If I use the following playbook:

  • name: Create new LXC container in Proxmox
    hosts: central.local
    tasks:
    • name: testing
      proxmox:
      vmid: 810
      node: central
      api_user: root@pam
      api_password:
      api_host: central
      password: 123456
      hostname: example.org
      ostemplate: 'local:vztmpl/archlinux-base_20210420-1_amd64.tar.gz'

It will return "ok", HOWEVER a container at id 810 already exists on the proxmox installation.

Which means two things:

  1. this "ok" is a false positive
  2. Nothing happens, no container is created

Altering this number exactly to any other number not yet assigned to a VM or container returns the error in OP. This example comes directly from the examples in your docs.

@bitshiftnetau bitshiftnetau reopened this Dec 4, 2021
@bitshiftnetau
Copy link
Author

Anyone going to address this? Not expecting an immediate fix, but this error renders Ansible completely useless in Proxmox.

@felixfontein
Copy link
Collaborator

felixfontein commented Dec 6, 2021

Nobody seems to be working on this. I think this is caused because you don't set the onboot parameter; the code handling it ignores that it can not be specified, and will likely (judging from glancing over it) produce this exact error when you don't specify it.

Changing line 608 to

                            onboot=int(module.params['onboot']) if module.params['onboot'] is not None else None,

should fix it (assuming my guess is correct).

@russoz
Copy link
Collaborator

russoz commented Dec 8, 2021

Wouldn't it be slightly better to add default=False to the argument spec?

@felixfontein
Copy link
Collaborator

No, because we just spent quite some amount of work to get rid of that default.

@bitshiftnetau
Copy link
Author

onboot=int(module.params['onboot']) if module.params['onboot'] is not None else None

Could we do is not None else 0 ?

@felixfontein
Copy link
Collaborator

No, for exactly the same reason: that would re-introduce the default.

@bitshiftnetau
Copy link
Author

Oh right of course haha I totally read that wrong.

What about making onboot a mandatory value? That way there is no default. The user either defines it to boot on startup or defines it to not boot on startup.

@felixfontein
Copy link
Collaborator

That's a breaking change and will not be accepted without a long deprecation period.

@bitshiftnetau
Copy link
Author

That's a breaking change and will not be accepted without a long deprecation period.

Technically yes? But also isn't that kind of a moot point as this is a major bug which results in this value needing to be set as a workaround (tested and confirmed) regardless? Else it doesn't work at all?

Either way, software development protocol yadda yadda... all good, I gets how it be 😅

Ok cool, so should we define that as a workaround? For now we note that without defining this value, it throws this error and won't work.

@felixfontein
Copy link
Collaborator

If someone wants to touch the module, how about simply fixing the bug, instead of adding some other random restriction which will avoid the bug to happen? Fixing the bug requires less effort (considering possible deprecations, required documentation, explanation in changelog etc.) than all the other things proposed here.

@bitshiftnetau
Copy link
Author

Happy to do that, but do you have a known solution? Do we know what the fundamental issue is under the hood?

If not, then I don't have the resources atm to commit for known unknowns. From my pov, it's simply easier to push through the deprecation cycle and stick with a workaround.

Either way, the workaround exists in the interim.

@felixfontein
Copy link
Collaborator

I'm pretty sure #3844 (comment) fixes the issue (since the fundamental reason is that int(None) gets called when you don't specify onboot as a module parameter), but I have no way to verify this because I don't use proxmox.

@bitshiftnetau
Copy link
Author

We seem to be going in circles. That solution is unfortunately out of the question, given the removal of default behaviour which I happen to agree with at the very least from a maintainer's pov.

Making this flag mandatory has other benefits in terms of basic operations hygene and makes sense also from the Ansible/config mgmt pov.

Does it boot? Does it not boot? Unacceptable unknown imo. Setting should be forced on the user.

Deprecation cycles aren't so bad, workarounds are very normal.

@felixfontein
Copy link
Collaborator

We seem to be going in circles. That solution is unfortunately out of the question, given the removal of default behaviour which I happen to agree with at the very least from a maintainer's pov.

I don't understand what you are saying. The comment I linked to is handling the option correctly when it is not provided by the user.

@bitshiftnetau
Copy link
Author

We seem to be going in circles. That solution is unfortunately out of the question, given the removal of default behaviour which I happen to agree with at the very least from a maintainer's pov.

I don't understand what you are saying. The comment I linked to is handling the option correctly when it is not provided by the user.

Oh sorry, I'm really not reading properly today.

Well no, coz the error is related to passing through None when the option isn't set in the first place right? If we then just give it None then we're not really fixing anything.

@felixfontein
Copy link
Collaborator

Please look closely. None is not passed to int(). But it is passed on as the value of onboot (which is correct and required) if the user provided None.

@Ajpantuso
Copy link
Collaborator

Ajpantuso commented Dec 8, 2021

I can pick this up later today. I'll add the inverse operation of

def proxmox_to_ansible_bool(value):
'''Convert Proxmox representation of a boolean to be ansible-friendly'''
return True if value == 1 else False
to the module_utils and wrap all the bool parameters in it. The other bool parameters have defaults so they are not affected currently, but obviously could be if defaults are removed.

EDIT: By inverse I mean True -> 1, False -> 0, None -> None.

@bitshiftnetau
Copy link
Author

Please look closely. None is not passed to int(). But it is passed on as the value of onboot (which is correct and required) if the user provided None.

I was operating under the assumption that the value passed to onboot was the issue in question, not the value passed to int() but now I understand.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue/PR relates to a bug cloud module module plugins plugin (any type)
Projects
None yet
5 participants