def main(): """ main entry point for module execution """ element_spec = dict(vlan_id=dict(type='int'), name=dict(), tagged_interfaces=dict(type='list'), untagged_interfaces=dict(type='list'), excluded_interfaces=dict(type='list'), auto_tag=dict(type='bool'), auto_exclude=dict(type='bool'), auto_untag=dict(type='bool'), state=dict(default='present', choices=['present', 'absent'])) argument_spec = build_aggregate_spec( element_spec, ['vlan_id'], dict(purge=dict(default=False, type='bool'))) required_one_of = [['vlan_id', 'aggregate']] mutually_exclusive = [['vlan_id', 'aggregate'], ['auto_tag', 'auto_untag', 'auto_exclude']] module = AnsibleModule(argument_spec=argument_spec, required_one_of=required_one_of, mutually_exclusive=mutually_exclusive, supports_check_mode=True) result = {'changed': False} want = map_params_to_obj(module) have = map_config_to_obj(module) check_params(module, want) # vlans are not created/deleted in configure mode commands = map_vlans_to_commands(want, have, module) result['commands'] = commands if commands: if not module.check_mode: run_commands(module, commands, check_rc=False) result['changed'] = True ports = map_ports_to_obj(module) # interfaces vlan are set in configure mode commands = map_interfaces_to_commands(want, ports, module) result['commands'].extend(commands) if commands: if not module.check_mode: load_config(module, commands) result['changed'] = True module.exit_json(**result)
def run(self, cmd): return run_commands(self.module, commands=cmd, check_rc=False)
def populate(self): self.responses = run_commands(self.module, commands=self.COMMANDS, check_rc=False)
def map_config_to_obj(module): return parse_vlan_brief(run_commands(module, ['show vlan brief'])[0])
def map_ports_to_obj(module): return parse_interfaces_switchport( run_commands(module, ['show interfaces switchport'])[0])