Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix validate_role_spec for nested spec #198

Merged

Conversation

ganeshrn
Copy link
Member

@ganeshrn ganeshrn commented Nov 15, 2018

Fixes #189

  • Adds support to validate nested subspecs for conditional like mutually_exclusive, required_if,
    required_one_of and required_together.
  • Returns the expanded role spec params initialized with default values as result of
    validate_role_spec task, this result can be used in later task to set the expanded role spec
    variables to it's default value

eg Playbook:

---
- hosts: localhost
  connection: local
  gather_facts: no
  vars:
    mlag_setup:
      peer: test
      ipaddr: value
  tasks:
  - name: set role path
    set_fact:
      role_path: ../ansible-network.network-engine

  - name: import role
    import_role:
      name: ../ansible-network.network-engine

  - name: validate spec
    validate_role_spec:
      spec: mlag_setup_spec.yaml
    register: role_spec

  - name: set role params
    set_fact:
      "{{ item.key }}": "{{ item.value }}"
    loop: "{{ lookup('dict', role_spec.role_params, wantlist=True) }}"

  - name: print role variables
    debug:
      msg: "{{ mlag_setup }}"

Contents of spec file:

$ cat mlag_setup_spec.yaml
---
argument_spec:
  mlag_setup:
    type: dict
    options:
      state:
        type: str
        required: false
        default: present
        choices:
          - "present"
          - "absent"
        description:
          - "Desired state: present, absent"

      peer:
        type: str
        required: true
        description:
          - "The MLAG peer switch hostname (inventory_hostname)"

      vlan:
        type: int
        required: false
        default: "4094"
        description:
          - "VLAN to use for peer communication."
          - "VLAN is used to create the interface vlan for MLAG_CONTROL_PLANE."

      domain:
        type: int
        required: false
        default: "1"
        description:
          - "Represents the MLAG domain."
          - "The ID must be the same only for members of the same MLAG domain."
          - "Domain is used to create the MLAG_CONTROL_PLANE VRF with RD <site>:<domain>"

      site:
        type: int
        required: false
        default: "1"
        description:
          - "Represents the site where the domain is located."
          - "Site is used to create the MLAG_CONTROL_PLANE interface with address 169.254.<domain>.<site><device>"
          - "Site is used to create the MLAG_CONTROL_PLANE VRF with RD <site>:<domain>"

      device:
        type: int
        required: false
        default: "1"
        description:
          - "Unique ID to represent the device member of the MLAG domain"
          - "The ID is used to create the peer communication address 169.254.<domain>.<site><device>"

      linkagg:
        type: int
        required: false
        default: "1"
        description:
          - "Linkagg to use for the peer-to-peer communication."

      vlans:
        type: list
        required: false
        default:
          - "all"
        description:
          - "List of vlans member of the MLAG domain"
          - "VLANs are NOT created if they do not exist"

      interlinks:
        type: list
        required: false
        default:
          - "Ethernet1"
        description:
          - "List of physical interfaces used by linkagg as interlinks for the peer-to-peer communication"

      heartbeat:
        type: int
        default: "10000"
        required: false
        description:
          - "Timer for heartbeat in ms"

      reload_delay:
        type: int
        default: "150"
        required: false
        description:
          - "Delay to bring MLAGs up after reload."
          - "Helps to ensure that MLAGs comes up only when adjacency is done and tables are pre-populated."
          - "Prevents blackhole of traffic when device is converging and tables being populated after a reboot."

      ipv4:
        type: str
        required: true
        description:
          - "IPV4 address to use for the MLAG intercommunication"
        aliases:
        - ipaddr

      vrf:
        type: str
        required: false
        default: "mlag_control"
        description:
          - "The VRF name for the MLAG intercommunication"

      extension:
        type: dict
        required: false
        description:
          - "Extension of specs with platform-specific keys/values"

Ansible run output logs:

PLAY [localhost] ***********************************************************************************************************

TASK [set role path] *******************************************************************************************************
ok: [localhost]

TASK [validate spec] *******************************************************************************************************
ok: [localhost]

TASK [set role params] *****************************************************************************************************
ok: [localhost] => (item={'key': u'mlag_setup', 'value': {u'domain': 1, u'interlinks': [u'Ethernet1'], u'extension': None, u'vlan': 4094, 'ipaddr': u'value', u'site': 1, 'peer': u'test', u'state': u'present', u'vrf': u'mlag_control', u'reload_delay': 150, u'device': 1, u'heartbeat': 10000, u'vlans': [u'all'], u'linkagg': 1, u'ipv4': u'value'}})

TASK [print role variables] *********************************************************************************************************
ok: [localhost] => {
    "msg": {
        "device": 1,
        "domain": 1,
        "extension": null,
        "heartbeat": 10000,
        "interlinks": [
            "Ethernet1"
        ],
        "ipaddr": "value",
        "ipv4": "value",
        "linkagg": 1,
        "peer": "test",
        "reload_delay": 150,
        "site": 1,
        "state": "present",
        "vlan": 4094,
        "vlans": [
            "all"
        ],
        "vrf": "mlag_control"
    }
}

PLAY RECAP *****************************************************************************************************************
localhost                  : ok=4    changed=0    unreachable=0    failed=0    skipped=0

@softwarefactory-project-zuul
Copy link
Contributor

Build failed.

@softwarefactory-project-zuul
Copy link
Contributor

Build succeeded.

@softwarefactory-project-zuul
Copy link
Contributor

Build succeeded (gate pipeline).

@softwarefactory-project-zuul softwarefactory-project-zuul bot merged commit 6d2643b into ansible-network:devel Nov 19, 2018
@ganeshrn ganeshrn deleted the validate_spec_fix branch November 22, 2018 05:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gate Gate PR in Zuul CI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants