I am not able to pass integer variable to task without losing the integer type.
I am trying to populate netbox using ansible playbook.
ansible version: 2.17.7
python version = 3.10.12
jinja version = 3.1.5
My structure looks like this:
Inside vars.yml i have:
vm_lists:
- name: my-vm
status: Active
cluster: my-cluster
platform: 5
vcpus: 6
memory: 24
- name: my-vm
status: Active
cluster: my-cluster
platform: 5
vcpus: 6
memory: 24
inside the tasks/add_virtual_machines.yml i have:
- name: "Add Virtual Machine to NetBox"
netbox.netbox.netbox_virtual_machine:
netbox_url: "{{ lookup('env', 'NETBOX_URL') }}"
netbox_token: "{{ lookup('env', 'NETBOX_TOKEN') }}"
validate_certs: false # Disable SSL verification
data:
name: "{{ vm.name }}"
status: Active
cluster: "{{ vm.cluster }}"
platform: "{{ vm.platform }}"
vcpus: "{{ vm.vcpus }}"
memory: "{{ vm.memory}}"
state: present
loop: "{{ vm_lists }}"
loop_control:
loop_var: vm
When running the main.yml playbook i get this error:
“ansible_loop_var”: “vm”, “changed”: false, “msg”: “Could not resolve id of platform: 5”.
I understand that due to jinja2 template, it is unable to pass on this integer data type, but instead it get converted to string.
i have tried:
settings:
- jinja2_native=True in ansible.cfg but it did not work.
- using the {{item.parameter | int}} also does not work.