Developer

last person joined: 3 days ago 

Expand all | Collapse all

Ansible add multiple ports to vlan

Jump to Best Answer
  • 1.  Ansible add multiple ports to vlan

    Posted Apr 30, 2020 08:14 AM

    Hi,
    The last couple of days i created a nice playbook for our switches to be configured out of the box. Everything is done via Ansible and works fine. The only thing i cant get to work is add ports a vlan via a loop.

    I want to have a list like: untagged_ports: [1/1, 1/2, 1/3].
    Than Ansible needs to do something like:

     

    port_id: "{{ item.data_vlan_ports}}"
            port_mode: "{{ item.mode}}"       
          with_items:
            - {mode: POM_UNTAGGED, data_vlan_ports: "{{untagged_ports}}"}

     

    The following code gives me the error:
    HTTP Error 400: Bad Request", "requestid": "", "server": "eHTTP v2.0", "status": 400, "transfer-encoding": "chunked".

     

    what do i wrong?
    Can someone please point me in the right direction. I found many tutorials about lists and in a debug it works. Only in combination with aruba vlan it doesnt work.

    In the end i want to achieve something like this:

    vlan_1_ports:
    	- tagged:
    		[1, 2, 3, 7]
    	- untagged:
    		[10, 11, 12]
    
    vlan_2_ports:
    	- tagged:
    		[1,2]
    	- untagged:
    		[23, 24]


    Thanks in advance.

     



  • 2.  RE: Ansible add multiple ports to vlan
    Best Answer

    Posted May 01, 2020 05:32 PM

    Hey jangenent!

     

    It looks like you're using the arubaoss_vlan module to do this, right?

     

    We actually have an example of how to achieve what you're looking for here:

     

    https://github.com/aruba/aruba-ansible-modules/blob/master/example_playbooks/arubaoss/vlan.yml

     

    On line 57, we're using a loop to remove multiple ports from a VLAN. What you're trying to do is essentially the same except this example is a subtractive operation as opposed to an additive operation. But hopefully this example gives you an idea of how to structure your loop!

     

    Cheers,

    Derek