# Mapping Netbox Value to ansible\_host

**URL:** <https://forum.ansible.com/t/mapping-netbox-value-to-ansible-host/41389>\
**Category:** Get Help\
**Created:** [March 28, 2025, 8:48am UTC](https://forum.ansible.com/t/mapping-netbox-value-to-ansible-host/41389 "2025-03-28T08:48:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![hagen\_bauer\_regioit](https://avatars.discourse-cdn.com/v4/letter/h/ed655f/32.png) [@hagen\_bauer\_regioit](https://forum.ansible.com/u/hagen_bauer_regioit)\
**Post date:** [March 28, 2025, 8:48am UTC](https://forum.ansible.com/t/mapping-netbox-value-to-ansible-host/41389/1 "2025-03-28T08:48:26Z")

</div>

I have successfully connected my ansible playbook to a netbox host. Within this netbox installation i want to manage the IP address of a host in a custom field. (I understand that it should be done via interfaces but creating IP Adresses and interfaces is a lot of work that I would like to avoid.)

The value “local\_ip” is visible when running

```auto
ansible-inventory --host hostname -i netbox_inventory.yml       
....
...
  "local_ip": "10.xxx.yyy.zz",

```

Then I want to use the compose statement in the inventory defintion to map that IP to my ansible\_host variable

```auto
compose:
  ansible_host: local_ip

```

Unfortunatly ansible\_host is not set when running playbooks or ansible-inventory.

Any hints or ideas?

---

<div class="post-metadata">

**Author:** ![SixteenOne](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sixteenone/32/459_2.png) [@SixteenOne](https://forum.ansible.com/u/SixteenOne)\
**Post date:** [March 29, 2025, 9:38pm UTC](https://forum.ansible.com/t/mapping-netbox-value-to-ansible-host/41389/2 "2025-03-29T21:38:57Z")

</div>

I have only started to play with Netbox, the best command line you can use with any Inventory is:

`ansible-inventory -i netbox_inv.yml --list --yaml`

Replace `netbox_inv.yml` with your inventory name and this will return the Hosts with their Variables. I have a Test Device below and you can see my `custom_fields` section

So your `local_ip`, should be something like `custom_fields.local_ip` and therefore no need to set the `compose` part ?

```yaml
    cluster_oberon:
      hosts:
        Test3:
          cluster: oberon
          cluster_device:
            description: ''
            display: oberon
            id: 1
            name: oberon
            url: https://...
          cluster_type: proxmox
          custom_fields:
            proxmox_onboot: 'true'
            proxmox_template: local:vztmpl/ubuntu-24.04-standard_24.04-2_amd64.tar.zst
            proxmox_vmid: '109'
          disk: 32
          is_virtual: true
...

```

---

<div class="post-metadata">

**Author:** ![hagen\_bauer\_regioit](https://avatars.discourse-cdn.com/v4/letter/h/ed655f/32.png) [@hagen\_bauer\_regioit](https://forum.ansible.com/u/hagen_bauer_regioit)\
**Post date:** [April 1, 2025, 6:20am UTC](https://forum.ansible.com/t/mapping-netbox-value-to-ansible-host/41389/3 "2025-04-01T06:20:27Z")

</div>

I appreaciate your help but thats not what I asked. I want the local\_ip to be mapped as ansible\_host

---

<div class="post-metadata">

**Author:** ![SixteenOne](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sixteenone/32/459_2.png) [@SixteenOne](https://forum.ansible.com/u/SixteenOne)\
**Post date:** [April 1, 2025, 6:54am UTC](https://forum.ansible.com/t/mapping-netbox-value-to-ansible-host/41389/4 "2025-04-01T06:54:36Z")

</div>

I have just tested this with my Netbox data and my answer given does have the answer in it

Your Custom Fields will display in your Inventory like the below, so your `local_ip` can be referenced as `custom_fields.local_ip`

```yaml
...
          custom_fields:
            proxmox_onboot: 'true'
            proxmox_template: local:vztmpl/ubuntu-24.04-standard_24.04-2_amd64.tar.zst
            proxmox_vmid: '109'
...

```

So as a test, I used one of my existing custom fields `proxmox_vmid` and put that as `ansible_host` as a quick test in my `netbox_inv.yml` file

```yaml
compose:
  ansible_host: custom_fields.proxmox_vmid

```

Then running the Ansible Inventory command given above, I can now see I have a new field of `ansible_host` which has been populated with `proxmox_vmid`

```yaml
...
        test6:
          ansible_host: '109'
          cluster: oberon
...

```

I hope this helps

---

<div class="post-metadata">

**Author:** ![hagen\_bauer\_regioit](https://avatars.discourse-cdn.com/v4/letter/h/ed655f/32.png) [@hagen\_bauer\_regioit](https://forum.ansible.com/u/hagen_bauer_regioit)\
**Post date:** [April 1, 2025, 10:51am UTC](https://forum.ansible.com/t/mapping-netbox-value-to-ansible-host/41389/5 "2025-04-01T10:51:41Z")

</div>

yes. that helped. When adding the field as custom\_fields its working. My first approach was to add a new value via json in local\_context\_data. That data was there but it seem data in local\_context\_data cannot be used in compose directiv
