def main(): argument_spec = dict( server=dict(), source_int=dict(), restrict=dict(), auth=dict(type="bool", default=False), auth_key=dict(), key_id=dict(), state=dict(choices=["absent", "present"], default="present"), ) argument_spec.update(awplus_argument_spec) module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True) result = {"changed": False} warnings = list() if warnings: result["warnings"] = warnings want = map_params_to_obj(module) have = map_config_to_obj(module) commands = map_obj_to_commands(want, have, module) result["commands"] = commands if commands: if not module.check_mode: load_config(module, commands) result["changed"] = True module.exit_json(**result)
def main(): argument_spec = dict( hostname=dict(), domain_name=dict(), domain_list=dict(type="list"), name_servers=dict(type="list"), lookup_enabled=dict(type="bool"), state=dict(choices=["present", "absent"], default="present"), ) argument_spec.update(awplus_argument_spec) module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True) result = {"changed": False} warnings = list() result["warnings"] = warnings want = map_params_to_obj(module) have = map_config_to_obj(module) commands = map_obj_to_commands(want, have, module) result["commands"] = commands if commands: if not module.check_mode: load_config(module, commands) result["changed"] = True module.exit_json(**result)
def main(): """ main entry point for module execution """ element_spec = dict( group=dict(type="int"), mode=dict(choices=["active", "passive"]), members=dict(type="list"), state=dict(default="present", choices=["present", "absent"]), ) aggregate_spec = deepcopy(element_spec) aggregate_spec["group"] = dict(required=True) required_one_of = [["group", "aggregate"]] required_together = [["members", "mode"]] mutually_exclusive = [["group", "aggregate"]] # remove default in aggregate spec, to handle common arguments remove_default_spec(aggregate_spec) argument_spec = dict( aggregate=dict( type="list", elements="dict", options=aggregate_spec, required_together=required_together, ), purge=dict(default=False, type="bool"), ) argument_spec.update(element_spec) argument_spec.update(awplus_argument_spec) module = AnsibleModule( argument_spec=argument_spec, required_one_of=required_one_of, required_together=required_together, mutually_exclusive=mutually_exclusive, supports_check_mode=True, ) warnings = list() result = {"changed": False} if warnings: result["warnings"] = warnings want = map_params_to_obj(module) have = map_config_to_obj(module) commands = map_obj_to_commands((want, have), module) result["commands"] = commands if commands: if not module.check_mode: load_config(module, commands) result["changed"] = True module.exit_json(**result)
def main(): """ main entry point for module execution """ element_spec = dict( prefix=dict(type="str"), mask=dict(type="str"), next_hop=dict(type="str"), vrf=dict(type="str"), interface=dict(type="str"), admin_distance=dict(type="str"), state=dict(default="present", choices=["present", "absent"]), ) aggregate_spec = deepcopy(element_spec) aggregate_spec["prefix"] = dict(required=True) # remove default in aggregate spec, to handle common arguments remove_default_spec(aggregate_spec) argument_spec = dict( aggregate=dict(type="list", elements="dict", options=aggregate_spec), ) argument_spec.update(element_spec) argument_spec.update(awplus_argument_spec) required_one_of = [["aggregate", "prefix"]] required_together = [["prefix", "mask"]] mutually_exclusive = [["aggregate", "prefix"]] module = AnsibleModule( argument_spec=argument_spec, required_one_of=required_one_of, mutually_exclusive=mutually_exclusive, supports_check_mode=True, ) warnings = list() result = {"changed": False} if warnings: result["warnings"] = warnings want = map_params_to_obj(module, required_together=required_together) have = map_config_to_obj(module) commands = map_obj_to_commands(want, have) result["commands"] = commands if commands: if not module.check_mode: load_config(module, commands) result["changed"] = True module.exit_json(**result)
def main(): """ main entry point for module execution """ argument_spec = dict( vrfs=dict(type="list"), name=dict(), description=dict(), rd=dict(), route_export=dict(type="list"), route_import=dict(type="list"), route_both=dict(type="list"), interfaces=dict(type="list"), associated_interfaces=dict(type="list"), delay=dict(default=10, type="int"), purge=dict(type="bool", default=False), state=dict(default="present", choices=["present", "absent"]), ) argument_spec.update(awplus_argument_spec) mutually_exclusive = [("name", "vrfs")] module = AnsibleModule( argument_spec=argument_spec, mutually_exclusive=mutually_exclusive, supports_check_mode=True, ) result = {"changed": False} warnings = list() result["warnings"] = warnings want = map_params_to_obj(module) have = map_config_to_obj(module) commands = map_obj_to_commands(update_objects(want, have), module) if module.params["purge"]: want_vrfs = [x["name"] for x in want] have_vrfs = [x["name"] for x in have] for item in set(have_vrfs).difference(want_vrfs): cmd = "no ip vrf %s" % item if cmd not in commands: commands.append(cmd) result["commands"] = commands if commands: if not module.check_mode: load_config(module, commands) result["changed"] = True check_declarative_intent_params(want, module, result) module.exit_json(**result)
def main(): """ main entry point for module execution """ controller_spec = dict( name=dict(type="str"), protocol=dict(type="str", choices=["ssl", "tcp"], required=True), address=dict(type="str", required=True), ssl_port=dict(type="int", required=True), ) port_spec = dict(name=dict(type="str", required=True), openflow=dict(type="bool", default=True)) argument_spec = dict( controllers=dict(type="list", elements="dict", options=controller_spec), native_vlan=dict(type="int"), fail_mode=dict(type="str", choices=["secure", "standalone"]), ports=dict(type="list", elements="dict", options=port_spec), state=dict(type="str", default="present", choices=["present", "absent"]), ) argument_spec.update(awplus_argument_spec) module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True) warnings = list() result = {"changed": False, "warnings": warnings} want = map_params_to_obj(module) have = map_config_to_obj(module) commands = map_obj_to_commands(want, have, module) result["commands"] = commands if commands: if not module.check_mode: load_config(module, commands) result["changed"] = True module.exit_json(**result)
def main(): router_spec = { "state": { "choices": [PRESENT, ABSENT], "default": PRESENT }, "process_id": { "type": "int" }, "vrf_instance": { "type": "str" }, } argument_spec = { "router": { "type": "dict", "options": router_spec, "required": True }, } argument_spec.update(awplus_argument_spec) module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True) warnings = [] result = {"changed": False, "warnings": warnings} ospf, existing_config = get_existing_config(module) commands = get_commands(module, KEY_TO_COMMAND_MAP, router_ospf_map, ospf, existing_config) result["commands"] = commands if commands: if not module.check_mode: load_config(module, commands) result["changed"] = True module.exit_json(**result)
def main(): """ main entry point for module execution """ argument_spec = dict( banner=dict(required=True, choices=["motd", "exec"]), text=dict(), state=dict(default="present", choices=["present", "absent"]), ) argument_spec.update(awplus_argument_spec) required_if = [("state", "present", ("text",))] module = AnsibleModule( argument_spec=argument_spec, required_if=required_if, supports_check_mode=True ) warnings = list() result = {"changed": False} if warnings: result["warnings"] = warnings want = map_params_to_obj(module) have = map_config_to_obj(module) commands = map_obj_to_commands((want, have), module) result["commands"] = commands if commands: if not module.check_mode: load_config(module, commands) result["changed"] = True module.exit_json(**result)
def main(): argument_spec = dict( asn=dict(required=True, type="str"), vrf=dict(required=False, type="str", default="default"), bestpath_always_compare_med=dict(required=False, type="bool"), bestpath_compare_routerid=dict(required=False, type="bool"), bestpath_med_confed=dict(required=False, type="bool"), bestpath_med_missing_as_worst=dict(required=False, type="bool"), cluster_id=dict(required=False, type="str"), confederation_id=dict(required=False, type="str"), confederation_peers=dict(required=False, type="list"), enforce_first_as=dict(required=False, type="bool"), graceful_restart=dict(required=False, type="bool"), graceful_restart_timers_restart=dict(required=False, type="str"), graceful_restart_timers_stalepath_time=dict(required=False, type="str"), local_as=dict(required=False, type="str"), router_id=dict(required=False, type="str"), timer_bgp_hold=dict(required=False, type="str"), timer_bgp_keepalive=dict(required=False, type="str"), state=dict(choices=["present", "absent"], default="present", required=False), ) argument_spec.update(awplus_argument_spec) module = AnsibleModule( argument_spec=argument_spec, required_together=[["timer_bgp_hold", "timer_bgp_keepalive"]], supports_check_mode=True, ) warnings = list() result = dict(changed=False, warnings=warnings) state = module.params["state"] if module.params["vrf"] != "default": for param in GLOBAL_PARAMS: if module.params[param]: module.fail_json( msg='Global params can be modified only under "default" VRF.', vrf=module.params["vrf"], global_param=param, ) args = PARAM_TO_COMMAND_KEYMAP.keys() existing = get_existing(module, args, warnings) if existing.get("asn") and state == "present": if existing.get("asn") != module.params["asn"]: module.fail_json( msg="Another BGP ASN already exists.", proposed_asn=module.params["asn"], existing_asn=existing.get("asn"), ) proposed_args = dict( (k, v) for k, v in module.params.items() if v is not None and k in args ) proposed = {} for key, value in proposed_args.items(): if key not in ["asn", "vrf"]: if str(value).lower() == "default": value = PARAM_TO_DEFAULT_KEYMAP.get(key, "default") if key == "confederation_peers": if value[0] == "default": if existing.get(key): proposed[key] = "default" else: v = set([int(i) for i in value]) ex = set([int(i) for i in existing.get(key)]) if v != ex: proposed[key] = " ".join(str(s) for s in v) else: if existing.get(key) != value: proposed[key] = value candidate = CustomNetworkConfig(indent=3) if state == "present": state_present(module, existing, proposed, candidate) elif existing.get("asn") == module.params["asn"]: state_absent(module, existing, candidate) if candidate: candidate = candidate.items_text() if not module.check_mode: load_config(module, candidate) result["changed"] = True result["commands"] = candidate else: result["commands"] = [] module.exit_json(**result)
def main(): area_default_cost_spec = { "state": { "choices": [PRESENT, ABSENT], "default": PRESENT }, "cost_value": { "type": "int" }, } area_authentication_spec = { "state": { "choices": [PRESENT, ABSENT], "default": PRESENT }, "message_digest": { "type": "bool", "default": False }, } area_filter_list_spec = { "state": { "choices": [PRESENT, ABSENT], "default": PRESENT }, "prefix_list": { "type": "str", "required": True }, "direction": { "choices": ["in", "out"] }, } area_nssa_spec = { "state": { "choices": [PRESENT, ABSENT], "default": PRESENT }, "default_information_originate": { "type": "bool", "default": False }, "default_information_originate_metric_type": { "type": "int", "choices": [1, 2], }, "default_information_originate_metric": { "type": "int" }, "no_redistribution": { "type": "bool", "default": False }, "no_summary": { "type": "bool", "default": False }, "translator_role": { "type": "bool", "default": False }, "translator_role_type": { "choices": ["always", "candidate", "never"] }, } area_range_spec = { "state": { "choices": [PRESENT, ABSENT], "default": PRESENT }, "ip_addr": { "type": "str", "required": True }, "advertise": { "type": "bool", "default": None }, } area_stub_spec = { "state": { "choices": [PRESENT, ABSENT], "default": PRESENT }, "no_summary": { "type": "bool", "default": False }, } area_virtual_link_spec = { "state": { "choices": [PRESENT, ABSENT], "default": PRESENT }, "ip_addr": { "type": "str", "required": True }, "auth_key": { "type": "str" }, "msg_key_id": { "type": "int" }, "msg_key_password": { "type": "str" }, "authentication_type": { "choices": ["message-digest", "null"] }, "authentication": { "type": "bool", "default": False }, "dead_interval": { "type": "bool", "default": False }, "dead_interval_value": { "type": "int" }, "hello_interval": { "type": "bool", "default": False }, "hello_interval_value": { "type": "int" }, "retransmit_interval": { "type": "bool", "default": False }, "retransmit_interval_value": { "type": "int" }, "transmit_delay": { "type": "bool", "default": False }, "transmit_delay_value": { "type": "int" }, } area_spec = { "state": { "choices": [PRESENT, ABSENT], "default": PRESENT }, "area_id": { "type": "str", "required": True }, "default_cost": { "type": "dict", "options": area_default_cost_spec }, "authentication": { "type": "dict", "options": area_authentication_spec }, "filter_list": { "type": "dict", "options": area_filter_list_spec }, "nssa": { "type": "dict", "options": area_nssa_spec }, "range": { "type": "dict", "options": area_range_spec }, "stub": { "type": "dict", "options": area_stub_spec }, "virtual_link": { "type": "dict", "options": area_virtual_link_spec }, } router_spec = { "state": { "choices": [PRESENT, ABSENT], "default": PRESENT }, "process_id": { "type": "int" }, "vrf_instance": { "type": "str" }, } network_area_spec = { "state": { "choices": [PRESENT, ABSENT], "default": PRESENT }, "network_address": { "type": "str", "required": True }, "area_id": { "type": "str", "required": True }, } ospf_router_id_spec = { "state": { "choices": [PRESENT, ABSENT], "default": PRESENT }, "ip_addr": { "type": "str" }, } passive_interface_spec = { "state": { "choices": [PRESENT, ABSENT], "default": PRESENT }, "name": { "type": "str" }, "ip_addr": { "type": "str" }, } redistribute_spec = { "state": { "choices": [PRESENT, ABSENT], "default": PRESENT }, "connected": { "type": "bool", "default": False }, "static": { "type": "bool", "default": False }, "metric": { "type": "int" }, "metric_type": { "choices": ["1", "2"] }, "route_map_name": { "type": "str" }, "tag": { "type": "int" }, } summary_address_spec = { "state": { "choices": [PRESENT, ABSENT], "default": PRESENT }, "ip_addr": { "type": "str", "required": True }, "not_advertise": { "type": "bool", "default": False }, "tag": { "type": "int" }, } argument_spec = { "area": { "type": "dict", "options": area_spec }, "router": { "type": "dict", "options": router_spec, "required": True }, "network_area": { "type": "dict", "options": network_area_spec }, "ospf_router_id": { "type": "dict", "options": ospf_router_id_spec }, "passive_interface": { "type": "dict", "options": passive_interface_spec }, "redistribute": { "type": "dict", "options": redistribute_spec }, "summary_address": { "type": "dict", "options": summary_address_spec }, } argument_spec.update(awplus_argument_spec) module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True) warnings = [] result = {"changed": False, "warnings": warnings} ospf, existing_config = get_existing_config(module) commands = get_commands(module, KEY_TO_COMMAND_MAP, router_ospf_map, ospf, existing_config) result["commands"] = commands if commands: if not module.check_mode: load_config(module, commands) result["changed"] = True module.exit_json(**result)
def main(): """ main entry point for module execution """ hashed_password_spec = dict(value=dict(no_log=True, required=True)) element_spec = dict( name=dict(), configured_password=dict(no_log=True), hashed_password=dict(no_log=True, type="dict", options=hashed_password_spec), privilege=dict(type="int"), state=dict(default="present", choices=["present", "absent"]), ) aggregate_spec = deepcopy(element_spec) aggregate_spec["name"] = dict(required=True) # remove default in aggregate spec, to handle common arguments remove_default_spec(aggregate_spec) argument_spec = dict( aggregate=dict( type="list", elements="dict", options=aggregate_spec, aliases=["users", "collection"], ), purge=dict(type="bool", default=False), ) argument_spec.update(element_spec) argument_spec.update(awplus_argument_spec) mutually_exclusive = [ ("name", "aggregate"), ("hashed_password", "configured_password"), ] module = AnsibleModule( argument_spec=argument_spec, mutually_exclusive=mutually_exclusive, supports_check_mode=True, ) warnings = list() result = {"changed": False, "warnings": warnings} want = map_params_to_obj(module) have = map_config_to_obj(module) commands = map_obj_to_commands(update_objects(want, have), module) if module.params["purge"]: want_users = [x["name"] for x in want] have_users = [x["name"] for x in have] for item in set(have_users).difference(want_users): if item != "admin": commands.append(user_del_cmd(item)) result["commands"] = commands if commands: if not module.check_mode: load_config(module, commands) result["changed"] = True module.exit_json(**result)