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

vmware_dvswitch_pvlans: For "primaryVlanId" expected type int, but got str #2216

Open
mihkelvain opened this issue Oct 22, 2024 · 0 comments

Comments

@mihkelvain
Copy link

SUMMARY

Getting vlan_id's from variables results in type error

ISSUE TYPE
  • Bug Report
COMPONENT NAME
ANSIBLE VERSION
ansible [core 2.16.10]
  config file = /var/home/mihkel/src/git/cp-ansible-vmware/ansible.cfg
  configured module search path = ['/var/home/mihkel/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /var/home/mihkel/virtual_envs/ansible/lib64/python3.12/site-packages/ansible
  ansible collection location = /var/home/mihkel/.ansible/collections:/usr/share/ansible/collections
  executable location = /var/home/mihkel/virtual_envs/ansible/bin/ansible
  python version = 3.12.6 (main, Sep  9 2024, 00:00:00) [GCC 14.2.1 20240801 (Red Hat 14.2.1-1)] (/var/home/mihkel/virtual_envs/ansible/bin/python3)
  jinja version = 3.1.2
  libyaml = True

COLLECTION VERSION
Collection        Version
----------------- -------
community.vmware 4.7.1

CONFIGURATION
CONFIG_FILE() = /var/home/mihkel/src/git/cp-ansible-vmware/ansible.cfg
DEFAULT_HOST_LIST(/var/home/mihkel/src/git/cp-ansible-vmware/ansible.cfg) = ['/var/home/mihkel/src/git/cp-ansible-vmware/inventory']
DEFAULT_MANAGED_STR(/var/home/mihkel/src/git/cp-ansible-vmware/ansible.cfg) = Ansible managed
DEFAULT_VAULT_PASSWORD_FILE(/var/home/mihkel/src/git/cp-ansible-vmware/ansible.cfg) = /var/home/mihkel/.ansible/vault_vmware.txt
EDITOR(env: EDITOR) = vi

OS / ENVIRONMENT
STEPS TO REPRODUCE
Task:

- name: Create PVLANs on a Distributed Switch
  community.vmware.vmware_dvswitch_pvlans:
    hostname: '{{ vcenter_hostname }}'
    username: '{{ vcenter_username }}'
    password: '{{ vcenter_password }}'
    switch: '{{ item.0.0.cp_datacenter | lower }}-dsw01-vm'
    primary_pvlans:
      - primary_pvlan_id: "{{ item.1.primary_pvlan_id }}"
    secondary_pvlans:
      - primary_pvlan_id: "{{ item.1.primary_pvlan_id }}"
        secondary_pvlan_id: "{{ item.1.secondary_pvlan_id }}"
        pvlan_type: isolated
    validate_certs: "{{ validate_vcenter_certs }}"
  loop: "{{ cp_vmware_structure | ansible.builtin.subelements('cp_clusters', skip_missing=True) | ansible.builtin.product(cp_pvlan_portgroups) }}"
  run_once: true
  delegate_to: localhost

vars:

cp_pvlan_portgroups:
  - { pvlan_pg_name: "some-isolated-pvlan", primary_pvlan_id: 1700, secondary_pvlan_id: 1701 }

This results in:

failed: [x.x.x.x -> localhost] (item=[[{'cp_datacenter': 'DC03', 'cp_clusters': ['dc03-bsod', 'dc03-panic']}, 'dc03-bsod'], {'pvlan_pg_name': 'some-storage-client-isolated-pvlan', 'primary_pvlan_id': 1700, 'secondary_pvlan_id': 1701}]) => {"ansible_loop_var": "item", "changed": false, "item": [[{"cp_clusters": ["dc03-bsod", "dc03-panic"], "cp_datacenter": "DC03"}, "dc03-bsod"], {"primary_pvlan_id": 1700, "pvlan_pg_name": "some-storage-client-isolated-pvlan", "secondary_pvlan_id": 1701}], "module_stderr": "Traceback (most recent call last):\n  File \"/var/home/mihkel/.ansible/tmp/ansible-tmp-1729598792.0353694-526397-181662945735310/AnsiballZ_vmware_dvswitch_pvlans.py\", line 107, in <module>\n    _ansiballz_main()\n  File \"/var/home/mihkel/.ansible/tmp/ansible-tmp-1729598792.0353694-526397-181662945735310/AnsiballZ_vmware_dvswitch_pvlans.py\", line 99, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/var/home/mihkel/.ansible/tmp/ansible-tmp-1729598792.0353694-526397-181662945735310/AnsiballZ_vmware_dvswitch_pvlans.py\", line 47, in invoke_module\n    runpy.run_module(mod_name='ansible_collections.community.vmware.plugins.modules.vmware_dvswitch_pvlans', init_globals=dict(_module_fqn='ansible_collections.community.vmware.plugins.modules.vmware_dvswitch_pvlans', _modlib_path=modlib_path),\n  File \"<frozen runpy>\", line 226, in run_module\n  File \"<frozen runpy>\", line 98, in _run_module_code\n  File \"<frozen runpy>\", line 88, in _run_code\n  File \"/tmp/ansible_community.vmware.vmware_dvswitch_pvlans_payload_3vs2emf8/ansible_community.vmware.vmware_dvswitch_pvlans_payload.zip/ansible_collections/community/vmware/plugins/modules/vmware_dvswitch_pvlans.py\", line 527, in <module>\n  File \"/tmp/ansible_community.vmware.vmware_dvswitch_pvlans_payload_3vs2emf8/ansible_community.vmware.vmware_dvswitch_pvlans_payload.zip/ansible_collections/community/vmware/plugins/modules/vmware_dvswitch_pvlans.py\", line 523, in main\n  File \"/tmp/ansible_community.vmware.vmware_dvswitch_pvlans_payload_3vs2emf8/ansible_community.vmware.vmware_dvswitch_pvlans_payload.zip/ansible_collections/community/vmware/plugins/modules/vmware_dvswitch_pvlans.py\", line 259, in ensure\n  File \"/tmp/ansible_community.vmware.vmware_dvswitch_pvlans_payload_3vs2emf8/ansible_community.vmware.vmware_dvswitch_pvlans_payload.zip/ansible_collections/community/vmware/plugins/modules/vmware_dvswitch_pvlans.py\", line 480, in create_pvlan_config_spec\n  File \"/var/home/mihkel/virtual_envs/ansible/lib64/python3.12/site-packages/pyVmomi/VmomiSupport.py\", line 557, in __setattr__\n    CheckField(self._GetPropertyInfo(name), val)\n  File \"/var/home/mihkel/virtual_envs/ansible/lib64/python3.12/site-packages/pyVmomi/VmomiSupport.py\", line 1118, in CheckField\n    raise TypeError('For \"%s\" expected type %s, but got %s' %\nTypeError: For \"primaryVlanId\" expected type int, but got str\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: TypeError: For "primaryVlanId" expected type int, but got str

But if I define vlan_id's inside task as int, then it works:

- name: Create PVLANs on a Distributed Switch
  community.vmware.vmware_dvswitch_pvlans:
    hostname: '{{ vcenter_hostname }}'
    username: '{{ vcenter_username }}'
    password: '{{ vcenter_password }}'
    switch: '{{ item.0.0.cp_datacenter | lower }}-dsw01-vm'
    primary_pvlans:
      - primary_pvlan_id: 1700
    secondary_pvlans:
      - primary_pvlan_id: 1700
        secondary_pvlan_id: 1701
        pvlan_type: isolated
    validate_certs: "{{ validate_vcenter_certs }}"
  loop: "{{ cp_vmware_structure | ansible.builtin.subelements('cp_clusters', skip_missing=True) | ansible.builtin.product(cp_pvlan_portgroups) }}"
  run_once: true
  delegate_to: localhost

Debug task

- name: Debug task
  debug:
    msg:  "{{ item.1.primary_pvlan_id }} and type is {{ item.1.primary_pvlan_id | type_debug }}"
  loop: "{{ cp_vmware_structure | ansible.builtin.product(cp_pvlan_portgroups) }}"

outputs:


ok: [172.16.8.221] => (item=[{'cp_datacenter': 'DC02', 'cp_clusters': ['dc02-bsod', 'dc02-panic']}, {'pvlan_pg_name': 'some-storage-client-isolated-pvlan', 'primary_pvlan_id': 1700, 'secondary_pvlan_id': 1701}]) => {
    "msg": "1700 and type is int"
}
ok: [172.16.8.221] => (item=[{'cp_datacenter': 'DC03', 'cp_clusters': ['dc03-bsod', 'dc03-panic']}, {'pvlan_pg_name': 'some-storage-client-isolated-pvlan', 'primary_pvlan_id': 1700, 'secondary_pvlan_id': 1701}]) => {
    "msg": "1700 and type is int"
}
EXPECTED RESULTS

Reading int from variable should result in working task :)

ACTUAL RESULTS

An exception occurred during task execution. To see the full traceback, use -vvv. The error was: TypeError: For "primaryVlanId" expected type int, but got str


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

No branches or pull requests

1 participant