ansible-collections / community.general

Ansible Community General Collection
https://galaxy.ansible.com/ui/repo/published/community/general/
GNU General Public License v3.0
823 stars 1.52k forks source link

lxd_container: Documentation could mention that config values need to be string #8307

Open nilsmeyer opened 6 months ago

nilsmeyer commented 6 months ago

Summary

When lxd_container passes the configuration from the config option to LXD or Incus and the values used aren't strings you might end up seeing an error "json: cannot unmarshal number into Go struct field InstancesPost.config of type string", an example:

- name: Create molecule instance(s)
  community.general.lxd_container:
    name: "mycontainer"
    state: started
    config: 
      "limits.cpu": 2
    source:
      type: image
      mode: pull
      protocol: simplestreams
      alias: almalinux/9/cloud
    wait_for_ipv4_addresses: true

While correct synax would be:

- name: Create molecule instance(s)
  community.general.lxd_container:
    name: "mycontainer"
    state: started
    config: 
      "limits.cpu": "2"
    source:
      type: image
      mode: pull
      protocol: simplestreams
      alias: almalinux/9/cloud
    wait_for_ipv4_addresses: true

It took me a while to figure this out. My suggestion would be to add a point to the Documentation for the config: parameter that LXD/Incus expect the values to always be strings.

Issue Type

Documentation Report

Component Name

lxd_container

Ansible Version

ansible [core 2.16.6]
  config file = /home/nils/.ansible.cfg
  configured module search path = ['/home/nils/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/nils/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
  ansible collection location = /home/nils/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/nils/.local/bin/ansible
  python version = 3.11.6 (main, Oct  8 2023, 05:06:43) [GCC 13.2.0] (/home/nils/.local/pipx/venvs/ansible/bin/python)
  jinja version = 3.1.2
  libyaml = True

Community.general Version


# /home/nils/.ansible/collections/ansible_collections
Collection        Version
----------------- -------
community.general 8.5.0  

# /home/nils/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible_collections
Collection        Version
----------------- -------
community.general 8.6.0

Configuration

CONFIG_FILE() = /home/nils/.ansible.cfg
DEFAULT_VAULT_PASSWORD_FILE(env: ANSIBLE_VAULT_PASSWORD_FILE) = /home/nils/.local/bin/vault_pass.sh
EDITOR(env: EDITOR) = vim
PAGER(env: PAGER) = less

OS / Environment

Additional Information

Clarify the format of the config parameter to lxd_container

Code of Conduct

ansibullbot commented 6 months ago

Files identified in the description:

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