community.general.ce_switchport (0.1.1) — module

Manages Layer 2 switchport interfaces on HUAWEI CloudEngine switches.

Authors: QijunPan (@QijunPan)

preview | supported by community

Install collection

Install with ansible-galaxy collection install community.general:==0.1.1


Add to requirements.yml

  collections:
    - name: community.general
      version: 0.1.1

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
      default_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
      pvid_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
      pvid_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
    - hybrid
    - dot1qtunnel
    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

pvid_vlan:
    description:
    - If C(mode=trunk, or mode=hybrid), 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.

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

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

untagged_vlans:
    description:
    - If C(mode=hybrid), 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:
    default_vlan: '20'
    interface: 10GE1/0/22
    mode: access
    switchport: enable
  type: dict
existing:
  description: k/v pairs of existing switchport
  returned: always
  sample:
    default_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:
    default_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