ansible.builtin.ce_switchport (v2.8.20) — module

Manages Layer 2 switchport interfaces on HUAWEI CloudEngine switches.

| "added in version" 2.4 of ansible.builtin"

Authors: QijunPan (@QijunPan)

preview | supported by community

Install Ansible via pip

Install with pip install ansible==2.8.20

Description

Manages Layer 2 switchport interfaces on HUAWEI CloudEngine switches.

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: switchport module test
  hosts: cloudengine
  connection: local
  gather_facts: no
  vars:
    cli:
      host: "{{ inventory_hostname }}"
      port: "{{ ansible_ssh_port }}"
      username: "{{ username }}"
      password: "{{ password }}"
      transport: cli

  tasks:
  - name: Ensure 10GE1/0/22 is in its default switchport state
    ce_switchport:
      interface: 10GE1/0/22
      state: unconfigured
      provider: '{{ cli }}'

  - name: Ensure 10GE1/0/22 is configured for access vlan 20
    ce_switchport:
      interface: 10GE1/0/22
      mode: access
      access_vlan: 20
      provider: '{{ cli }}'

  - name: Ensure 10GE1/0/22 only has vlans 5-10 as trunk vlans
    ce_switchport:
      interface: 10GE1/0/22
      mode: trunk
      native_vlan: 10
      trunk_vlans: 5-10
      provider: '{{ cli }}'

  - name: Ensure 10GE1/0/22 is a trunk port and ensure 2-50 are being tagged (doesn't mean others aren't also being tagged)
    ce_switchport:
      interface: 10GE1/0/22
      mode: trunk
      native_vlan: 10
      trunk_vlans: 2-50
      provider: '{{ cli }}'

  - name: Ensure these VLANs are not being tagged on the trunk
    ce_switchport:
      interface: 10GE1/0/22
      mode: trunk
      trunk_vlans: 51-4000
      state: absent
      provider: '{{ cli }}'

Inputs

    
mode:
    choices:
    - access
    - trunk
    description:
    - The link type of an interface.

state:
    choices:
    - present
    - absent
    - unconfigured
    default: present
    description:
    - Manage the state of the resource.

interface:
    description:
    - Full name of the interface, i.e. 40GE1/0/22.
    required: true

access_vlan:
    description:
    - If C(mode=access), used as the access VLAN ID, in the range from 1 to 4094.

native_vlan:
    description:
    - If C(mode=trunk), used as the trunk native VLAN ID, in the range from 1 to 4094.

trunk_vlans:
    description:
    - If C(mode=trunk), used as the VLAN range to ADD or REMOVE from the trunk, such as
      2-10 or 2,5,10-15, etc.

Outputs

changed:
  description: check to see if a change was made on the device
  returned: always
  sample: true
  type: bool
end_state:
  description: k/v pairs of switchport after module execution
  returned: always
  sample:
    access_vlan: '20'
    interface: 10GE1/0/22
    mode: access
    switchport: enable
  type: dict
existing:
  description: k/v pairs of existing switchport
  returned: always
  sample:
    access_vlan: '10'
    interface: 10GE1/0/22
    mode: access
    switchport: enable
  type: dict
proposed:
  description: k/v pairs of parameters passed into module
  returned: always
  sample:
    access_vlan: '20'
    interface: 10GE1/0/22
    mode: access
  type: dict
updates:
  description: command string sent to the device
  returned: always
  sample:
  - 10GE1/0/22
  - port default vlan 20
  type: list