# Ansible switch Configuration

**URL:** <https://forum.ansible.com/t/ansible-switch-configuration/5091>\
**Category:** Get Help\
**Tags:** ansible\
**Created:** [April 23, 2024, 2:55pm UTC](https://forum.ansible.com/t/ansible-switch-configuration/5091 "2024-04-23T14:55:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kumar\_Sunny](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/kumar_sunny/32/2971_2.png) [@Kumar\_Sunny](https://forum.ansible.com/u/Kumar_Sunny)\
**Post date:** [April 23, 2024, 2:55pm UTC](https://forum.ansible.com/t/ansible-switch-configuration/5091/1 "2024-04-23T14:55:51Z")

</div>

I have a main Ansible playbook “Vlan\_configuration.yml “ . I have a ticketing tool “Solve “ which is as similar as Service now . I have a list of network switches present in the drop-down of “ Network Switches “ .there are 200 list of network switches . Now , I have different roles called inside a main playbook and the one role is “Manage\_Engine\_Update “ . I have created a task inside this role which is “api\_test”.yml … now I have a url which fetches all the details of network switches and the output is present in the JSON format of “request\_data “. this output has all switch attributes like switch name , switch ip address . Request\_data is the name of the register … Now my question is , I need to create a variable such that whenever the user selects any network switches in the drop-down , I should have the list of available network switches present in the variable so that whenever user selects from the ticketing tenplate , it should check from the variable and if it is found , it will fetch the ip address of that particular switch from the “request\_data “ register .

I want to create a variable that should have the list of the available network switches , if I am able to create a variable , then I can compare this variable with the available list of switch names whatever user will be selecting . If that gets compared and the switch is found , we can get the ip address of the particular switches …I don’t know how to create that . I am not getting any idea , for it … can anyone let me know , how can we create the variable for all the network switches ?

---

<div class="post-metadata">

**Author:** ![atul\_mohan](https://avatars.discourse-cdn.com/v4/letter/a/f04885/32.png) [@atul\_mohan](https://forum.ansible.com/u/atul_mohan)\
**Post date:** [January 13, 2025, 6:15am UTC](https://forum.ansible.com/t/ansible-switch-configuration/5091/2 "2025-01-13T06:15:26Z")

</div>

```auto
---
- name: Configure OPNsense interfaces
  hosts: localhost
  gather_facts: no
  module_defaults:
    group/ansibleguy.opnsense.all:
      firewall: 'opnsense.template.ansibleguy.net'
      api_credential_file: '/home/guy/.secret/opn.key'
  tasks:
    - name: Adding VLAN
      ansibleguy.opnsense.interface_vlan:
        description: 'Home Network'
        interface: 'vtnet0'
        device: vlan0.30
        vlan: 30
      register: vlan_result

    - name: Assigning the newly created VLAN to interface
      ansibleguy.opnsense.interface:
        name: "vlan{{ vlan_result.created.vlan_id }}"
        description: 'Home Network'
        type: 'VLAN'
        if: "{{ vlan_result.created.interface }}"
      when: vlan_result is changed

    - name: Listing interfaces to check assignment
      ansibleguy.opnsense.list:
        target: 'interface'
      register: existing_interfaces

    - name: Displaying interface assignments
      debug:
        var: existing_interfaces.data

```
