ansible / network

Ansible collection for network devices
16 stars 16 forks source link

Network Interfaces Resource Module #1

Open trishnaguha opened 5 years ago

trishnaguha commented 5 years ago

Proposal: network interfaces resource module

Author: Trishna Guha <@trishnaguha>

Date: 2019-03-06

Motivation

Problems

Implementing resource module with a Provider Role

Solution Proposal

Model

{{ ansible_network_os }}_interfaces:
  state: { default: merged, choices: [merged, replaced, overriden, deleted] }
  config:
    - name: {required=True}
      description: { type: str }
      enable: { type: bool }
      speed: { type: str }
      mtu: { type: str }
      duplex: { type: str, choices: [full, half, auto] }
      mode: { type: str, choices: [layer2, layer3])

Module has a parent “config” and “operation” key

argument_spec = {
  'state: dict(default='merged', choices=['merged', 'replaced', 'overriden', 'deleted']),
  'config': dict(type='list', elements='dict', options=config_spec)
}

"State"

Playbook

- hosts: nxos
  connection: network_cli
  gather_facts: yes
  #gather_subset: net_configuration_interfaces

- nxos_interfaces:
    state: merged
    # config: "{{ ansible_facts['net_configuration']['interfaces'] }}"
    config:
      - name: Ethernet1/1
        description: 'Configured by Ansible'
        enable: False
      - name: Ethernet1/2
        mode: layer3

Return

Gathered Facts Facts gathered when gather_facts or gather_subset is enabled.

gather_subset: net_configuration_interfaces

"ansible_facts": {
        "net_configuration": {
            "interfaces": [
                {
                    "description": "Configured by Ansible", 
                    "duplex": null, 
                    "enable": false, 
                    "fabric_forwarding_anycast_gateway": null, 
                    "ip_forward": null, 
                    "mode": null, 
                    "mtu": null, 
                    "name": "Ethernet1/1", 
                    "speed": null
                },
                {
                    "description": "Configured by Ansible Network", 
                    "duplex": null, 
                    "enable": false, 
                    "fabric_forwarding_anycast_gateway": null, 
                    "ip_forward": null, 
                    "mode": null, 
                    "mtu": null, 
                    "name": "Ethernet1/2", 
                    "speed": null
                },
                {
                    "description": null, 
                    "duplex": null, 
                    "enable": true, 
                    "fabric_forwarding_anycast_gateway": null, 
                    "ip_forward": null, 
                    "mode": layer2, 
                    "mtu": null, 
                    "name": "Ethernet1/3", 
                    "speed": null
                }
            ]
        }
  }

Implementation

ganeshrn commented 5 years ago

Since the operational and configuration facts are different can we have separate top level keys to store the facts? For eg.

{ 
    ansible_net_operational: 
        {
             interfaces: [...],
             bgp: [...]
        }
      ansible_net_configuration:
        {
            interfaces: [...],
            bgp: [....]
        }
}

This also is in sync with the two prompt modes supported by most vendors (operational and configuration mode) on the device.

The facts extracted from show commands (except show running-config) executed in the operational mode (eg. show interfaces) can be stored under ansible_net_operational

and the facts extracted from show commands executed under config mode including show running-config can be stored under ansible_net_configuration key.

The proposed resource modules will provide the individual configuration facts in the module arspec pattern that can be stored in ansible_net_configuration key within ansible_facts.