Hello Everyone,
I'm trying to pass the numeric values of an variable into JSON.
- name: Device ID
  set_fact:
    "device_id": "{{ device_item_netbox.id }}"

- name: DEBUG - DEVICE ID
  debug: msg="{{ device_id }}"

Output - 
TASK [DEBUG - DEVICE ID] 
********************************************************************************************************************************************
ok: [localhost] => 
  msg: '3483'

When I try to pass the same into JSON body-
- name: Create Interface - Netbox
  uri:
    url: "{{ netbox_url }}/api/dcim/interfaces/"
    return_content: yes
    method: POST
    validate_certs: false
    status_code: 200,201
    headers:
      Authorization: "Token {{ netbox_server_token }}"
    body_format: json
    body:
      {
        "device": "{{ device_id }}",
        "name": "GigabitEthernet0/0",
        "mac_address": "xxxxx231",
        "type": "10gbase-t",
        "enabled": "true",
        "description": "GigabitEthernet0/0"
      }

Verbose output -
fatal: [localhost]: FAILED! => changed=false 
  allow: GET, POST, HEAD, OPTIONS, TRACE
  api_version: '2.8'
  content: '{"non_field_errors":["The fields device, name must make a 
unique set."]}'
  content_length: '72'
  content_type: application/json
  elapsed: 0
  invocation:
    module_args:
      attributes: null
      body:
        description: GigabitEthernet0/0
        device: '3483'
        enabled: 'true'
        mac_address: xxxxx231
        name: GigabitEthernet0/0
        type: 10gbase-t

But when I add something with variables like below, it removes adding 
quotes -
    body:
      {
        "device": "{{ device_id }} m",

Verbose output -
   module_args:
      attributes: null
      body:
        description: GigabitEthernet0/0
        device: 3483 m

Please advise how can I fetch/pass only numeric digits without quotes.

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/8ef279de-8250-483c-829f-626a67096ccfn%40googlegroups.com.

Reply via email to