diff --git a/iptrunks.yaml b/iptrunks.yaml index 39a70944e939165dd6776b105b0b228d6ccf40c8..3ed18ab29ff6531a6a4c584abd4d41a47ed2a079 100644 --- a/iptrunks.yaml +++ b/iptrunks.yaml @@ -1,6 +1,7 @@ - name: Manage iptrunks playbook hosts: all remote_user: admin + gather_facts: no vars_files: - /opt/ansible_inventory/group_vars/junos/device_access.yaml roles: diff --git a/roles/iptrunks/tasks/iptrunks_deploy_object.yaml b/roles/iptrunks/tasks/iptrunks_deploy_object.yaml index 6d4a5f6f3497a12c434671dea3b8dc81f559172c..e74eea20522b5d93369c839db8f306baddfa7014 100644 --- a/roles/iptrunks/tasks/iptrunks_deploy_object.yaml +++ b/roles/iptrunks/tasks/iptrunks_deploy_object.yaml @@ -22,6 +22,7 @@ format: text config_mode: "private" commit: yes + comment: "{{commit_comment}}" register: response when: verb == "deploy" and not (dry_run | ansible.builtin.bool) diff --git a/roles/iptrunks/tasks/iptrunks_remove_trunk.yaml b/roles/iptrunks/tasks/iptrunks_remove_trunk.yaml index 348bb7f8411857f740a454a60ca9f551de28ec62..bc11df5249d5c70d768062a6a465fe6590bfeb1e 100644 --- a/roles/iptrunks/tasks/iptrunks_remove_trunk.yaml +++ b/roles/iptrunks/tasks/iptrunks_remove_trunk.yaml @@ -22,6 +22,7 @@ format: set config_mode: "private" commit: yes + comment: "{{commit_comment}}" register: response when: verb == "remove" and not (dry_run | ansible.builtin.bool) diff --git a/roles/iptrunks/tasks/main.yml b/roles/iptrunks/tasks/main.yml index acefc5b634f53a7a91c2db58819a84abc93f337a..74ea9258965c6ed94cf4bb8bc093f936b00ac094 100644 --- a/roles/iptrunks/tasks/main.yml +++ b/roles/iptrunks/tasks/main.yml @@ -5,17 +5,16 @@ msg: - "Both 'verb' and 'config_object' are required." - "Allowed verbs: 'compile', 'deploy'. Use: -e 'verb=$verb'" - - "Allowed objects: 'trunk_interface', 'isis', 'isis_interface', 'ldp_interface', 'lldp_interface'. Use: -e 'config_object=$config_object'" - - "'$trunk_id' must be defined for this role to work." + - "Allowed objects: 'all', 'trunk_interface', 'isis', 'isis_interface', 'ldp_interface', 'lldp_interface'. Use: -e 'config_object=$config_object'" when: ((verb is not defined) or (config_object is not defined)) or (verb not in verbs) or (config_object not in config_objects) #when: ((verb is not defined) or (config_object is not defined) or (trunk_id is not defined)) or (verb not in verbs) or (config_object not in config_objects) - meta: end_play when: ((verb is not defined) or (config_object is not defined)) or (verb not in verbs) or (config_object not in config_objects) -- name: Gather_facts - junipernetworks.junos.junos_facts: - gather_subset: all + #- name: Gather_facts + # junipernetworks.junos.junos_facts: + # gather_subset: all - set_fact: opid: "{{ lookup('community.general.random_string', length=18, special=false) }}" diff --git a/roles/iptrunks/templates/trunk_deprovision.j2 b/roles/iptrunks/templates/trunk_deprovision.j2 index 4d17cb89c33401b4be6bfd694b17fdd3523ea27c..732a4897e5a795507a504557ae215a016428ac55 100644 --- a/roles/iptrunks/templates/trunk_deprovision.j2 +++ b/roles/iptrunks/templates/trunk_deprovision.j2 @@ -1,5 +1,4 @@ {% for trunk in trunks %} - {% if trunk.id == trunk_id %} {% if inventory_hostname == trunk.config.nodeA.name %} {% set local= trunk.config.nodeA %} {% endif %} @@ -7,13 +6,12 @@ {% set local= trunk.config.nodeB %} {% endif %} {% if local is defined %} - delete protocols isis interface {{ local.ae_name }} - delete protocols ldp interface {{ local.ae_name }} - delete interfaces {{ local.ae_name }} +delete protocols isis interface {{ local.ae_name }} +delete protocols ldp interface {{ local.ae_name }}.0 +delete interfaces {{ local.ae_name }} {% for iface in local.members %} - delete interfaces {{ iface }} - delete protocols lldp interface {{ iface }} +delete interfaces {{ iface }} +delete protocols lldp interface {{ iface }} {% endfor %} {% endif %} - {% endif %} {% endfor %} diff --git a/roles/iptrunks/vars/main.yml b/roles/iptrunks/vars/main.yml index 6ec015884e8f23fa2ff4500348839b29c3260aa9..df840cd7f7dc2863960d27627f1a8c858a500103 100644 --- a/roles/iptrunks/vars/main.yml +++ b/roles/iptrunks/vars/main.yml @@ -8,6 +8,7 @@ verbs: - "deploy" - "remove" config_objects: + - "all" - "trunk_interface" - "isis" - "isis_interface" @@ -15,17 +16,17 @@ config_objects: - "lldp_interface" - "trunk_deprovision" -wfo_trunk: "{{wfo_trunk_json|from_json}}" +wfo_trunk: "{{wfo_trunk_json}}" +config_object: "{{object}}" -side_a_ipv4_address: "{{ wfo_trunk.iptrunk.iptrunk_ipv4_network| ipaddr('net') | ipaddr('address')}}/31}}" -side_a_ipv6_address: "{{ wfo_trunk.iptrunk.iptrunk_ipv4_network| ipaddr('net') | ipaddr('1') | ipaddr('address')}}/126}}" -side_b_ipv4_address: "{{ wfo_trunk.iptrunk.iptrunk_ipv6_network| ipaddr('net') | ipaddr('1') | ipaddr('address')}}/31}}" -side_b_ipv6_address: "{{ wfo_trunk.iptrunk.iptrunk_ipv6_network| ipaddr('net') | ipaddr('2') | ipaddr('address')}}/126}}" +side_a_ipv4_address: "{{ wfo_trunk.iptrunk.iptrunk_ipv4_network| ipaddr('net') | ipaddr('address')}}/31" +side_a_ipv6_address: "{{ wfo_trunk.iptrunk.iptrunk_ipv6_network| ipaddr('net') | ipaddr('1') | ipaddr('address')}}/126" +side_b_ipv4_address: "{{ wfo_trunk.iptrunk.iptrunk_ipv4_network| ipaddr('net') | ipaddr('1') | ipaddr('address')}}/31" +side_b_ipv6_address: "{{ wfo_trunk.iptrunk.iptrunk_ipv6_network| ipaddr('net') | ipaddr('2') | ipaddr('address')}}/126" trunks: - id: "{{wfo_trunk.iptrunk.geant_s_sid}}" - name: AMS2-LON-IPTRUNK-100G config: common: description: "{{wfo_trunk.iptrunk.iptrunk_description}}" @@ -37,8 +38,6 @@ trunks: name: "{{wfo_trunk.iptrunk.iptrunk_sideA_node.device_fqdn}}" loopback: "{{wfo_trunk.iptrunk.iptrunk_sideA_node.device_lo_ipv4_address}}" ae_name: "{{wfo_trunk.iptrunk.iptrunk_sideA_ae_iface}}" - #ipv4_address: 62.40.98.164/31 - #ipv6_address: 2001:798:cc::5/126 ipv4_address: "{{side_a_ipv4_address}}" ipv6_address: "{{side_a_ipv6_address}}" members: "{{wfo_trunk.iptrunk.iptrunk_sideA_ae_members}}" @@ -48,8 +47,6 @@ trunks: name: "{{wfo_trunk.iptrunk.iptrunk_sideB_node.device_fqdn}}" loopback: "{{wfo_trunk.iptrunk.iptrunk_sideB_node.device_lo_ipv4_address}}" ae_name: "{{wfo_trunk.iptrunk.iptrunk_sideB_ae_iface}}" - #ipv4_address: 62.40.98.165/31 - #ipv6_address: 2001:798:cc::6/126 ipv4_address: "{{side_b_ipv4_address}}" ipv6_address: "{{side_b_ipv6_address}}" members: "{{wfo_trunk.iptrunk.iptrunk_sideB_ae_members}}" diff --git a/roles/iptrunks_checks/README.md b/roles/iptrunks_checks/README.md new file mode 100644 index 0000000000000000000000000000000000000000..225dd44b9fc5b3abff7e9c68ff9e91d505cdd5f0 --- /dev/null +++ b/roles/iptrunks_checks/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/roles/iptrunks_checks/defaults/main.yml b/roles/iptrunks_checks/defaults/main.yml new file mode 100644 index 0000000000000000000000000000000000000000..1c88a7ad07e7ef602985f29582d98921fd7c5b9c --- /dev/null +++ b/roles/iptrunks_checks/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for iptrunks_checks diff --git a/roles/iptrunks_checks/handlers/main.yml b/roles/iptrunks_checks/handlers/main.yml new file mode 100644 index 0000000000000000000000000000000000000000..6106d35f860c8c60ad0ae9e40dcd590eee08907f --- /dev/null +++ b/roles/iptrunks_checks/handlers/main.yml @@ -0,0 +1,2 @@ +--- +# handlers file for iptrunks_checks diff --git a/roles/iptrunks_checks/meta/main.yml b/roles/iptrunks_checks/meta/main.yml new file mode 100644 index 0000000000000000000000000000000000000000..c572acc9f8b466bea50f2799b0ca1956418b862c --- /dev/null +++ b/roles/iptrunks_checks/meta/main.yml @@ -0,0 +1,52 @@ +galaxy_info: + author: your name + description: your role description + company: your company (optional) + + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + + # Choose a valid license ID from https://spdx.org - some suggested licenses: + # - BSD-3-Clause (default) + # - MIT + # - GPL-2.0-or-later + # - GPL-3.0-only + # - Apache-2.0 + # - CC-BY-4.0 + license: license (GPL-2.0-or-later, MIT, etc) + + min_ansible_version: 2.1 + + # If this a Container Enabled role, provide the minimum Ansible Container version. + # min_ansible_container_version: + + # + # Provide a list of supported platforms, and for each platform a list of versions. + # If you don't wish to enumerate all versions for a particular platform, use 'all'. + # To view available platforms and versions (or releases), visit: + # https://galaxy.ansible.com/api/v1/platforms/ + # + # platforms: + # - name: Fedora + # versions: + # - all + # - 25 + # - name: SomePlatform + # versions: + # - all + # - 1.0 + # - 7 + # - 99.99 + + galaxy_tags: [] + # List tags for your role here, one per line. A tag is a keyword that describes + # and categorizes the role. Users find roles by searching for tags. Be sure to + # remove the '[]' above, if you add tags to this list. + # + # NOTE: A tag is limited to a single word comprised of alphanumeric characters. + # Maximum 20 tags per role. + +dependencies: [] + # List your role dependencies here, one per line. Be sure to remove the '[]' above, + # if you add dependencies to this list. diff --git a/roles/iptrunks_checks/tasks/check_isis.yaml b/roles/iptrunks_checks/tasks/check_isis.yaml new file mode 100644 index 0000000000000000000000000000000000000000..541ea3c4cb0cd63424da6a835b5099296c881312 --- /dev/null +++ b/roles/iptrunks_checks/tasks/check_isis.yaml @@ -0,0 +1,12 @@ +- name: Get status of ISIS + juniper_junos_command: + commands: + - show isis adjacency + - show isis interface "{{trunks[0].config.nodeA.ae_name}}".0 + register: response +- name: Show status of ISIS djacencies + debug: + msg: "{{ response.results[0].stdout_lines }}" +- name: Show status of ISIS interfaces + debug: + msg: "{{ response.results[1].stdout_lines }}" diff --git a/roles/iptrunks_checks/tasks/check_ping.yaml b/roles/iptrunks_checks/tasks/check_ping.yaml new file mode 100644 index 0000000000000000000000000000000000000000..8fdf9e8c56fc3eb6863fcad3ef6229de8f3f9603 --- /dev/null +++ b/roles/iptrunks_checks/tasks/check_ping.yaml @@ -0,0 +1,14 @@ +- name: Ping "{{trunks[0].config.nodeB.name}} on {{trunks[0].config.nodeB.ipv4_address.split('/')[0]}}" + juniper_junos_ping: + dest: "{{trunks[0].config.nodeB.ipv4_address.split('/')[0]}}" + count: 1000 + size: 9000 + rapid: yes + register: response +- name: Print the packet_loss percentage from the response. + debug: + var: response +- name: If packet loss is not zero, than this check fails + fail: + msg: "{{ response.changed }}" + when: response.packet_loss != "0" diff --git a/roles/iptrunks_checks/tasks/main.yml b/roles/iptrunks_checks/tasks/main.yml new file mode 100644 index 0000000000000000000000000000000000000000..a3d4c654d09d7a5e564b065be3b779676d384408 --- /dev/null +++ b/roles/iptrunks_checks/tasks/main.yml @@ -0,0 +1,21 @@ +--- +# tasks file for iptrunks +- name: Print the usage + debug: + msg: + - "Allowed checks: 'ping', 'isis'" + when: (check is not defined) or (check is in checks) + +- meta: end_play + when: (check is not defined) or (check is in checks) + +- name: Gather_facts + junipernetworks.junos.junos_facts: + gather_subset: all + + +- include_tasks: check_isis.yaml + when: check == "isis" + +- include_tasks: check_ping.yaml + when: check == "ping" diff --git a/roles/iptrunks_checks/tests/inventory b/roles/iptrunks_checks/tests/inventory new file mode 100644 index 0000000000000000000000000000000000000000..878877b0776c44f55fc4e458f70840f31da5bb01 --- /dev/null +++ b/roles/iptrunks_checks/tests/inventory @@ -0,0 +1,2 @@ +localhost + diff --git a/roles/iptrunks_checks/tests/test.yml b/roles/iptrunks_checks/tests/test.yml new file mode 100644 index 0000000000000000000000000000000000000000..3c586d57b25dcde1d910f578b20c988bae48461d --- /dev/null +++ b/roles/iptrunks_checks/tests/test.yml @@ -0,0 +1,5 @@ +--- +- hosts: localhost + remote_user: root + roles: + - iptrunks_checks diff --git a/roles/iptrunks_checks/vars/main.yml b/roles/iptrunks_checks/vars/main.yml new file mode 100644 index 0000000000000000000000000000000000000000..4a852c70d68ca27f77f257e3e65c37b667112135 --- /dev/null +++ b/roles/iptrunks_checks/vars/main.yml @@ -0,0 +1,31 @@ +--- +# vars file for iptrunks_checks + +trunks: + - id: "{{wfo_trunk.iptrunk.geant_s_sid}}" + name: AMS2-LON-IPTRUNK-100G + config: + common: + description: "{{wfo_trunk.iptrunk.iptrunk_description}}" + speed: "{{wfo_trunk.iptrunk.iptrunk_speed}}" + is_leased_line: false + isis_metric: '9000' + minimum_links: 1 + nodeA: + name: "{{wfo_trunk.iptrunk.iptrunk_sideA_node.device_fqdn}}" + loopback: "{{wfo_trunk.iptrunk.iptrunk_sideA_node.device_lo_ipv4_address}}" + ae_name: "{{wfo_trunk.iptrunk.iptrunk_sideA_ae_iface}}" + ipv4_address: "{{side_a_ipv4_address}}" + ipv6_address: "{{side_a_ipv6_address}}" + members: "{{wfo_trunk.iptrunk.iptrunk_sideA_ae_members}}" + members_descriptions: "{{wfo_trunk.iptrunk.iptrunk_sideA_ae_members_description}}" + port_sid: "{{wfo_trunk.iptrunk.iptrunk_sideA_ae_geant_a_sid}}" + nodeB: + name: "{{wfo_trunk.iptrunk.iptrunk_sideB_node.device_fqdn}}" + loopback: "{{wfo_trunk.iptrunk.iptrunk_sideB_node.device_lo_ipv4_address}}" + ae_name: "{{wfo_trunk.iptrunk.iptrunk_sideB_ae_iface}}" + ipv4_address: "{{side_b_ipv4_address}}" + ipv6_address: "{{side_b_ipv6_address}}" + members: "{{wfo_trunk.iptrunk.iptrunk_sideB_ae_members}}" + members_descriptions: "{{wfo_trunk.iptrunk.iptrunk_sideB_ae_members_description}}" + port_sid: "{{wfo_trunk.iptrunk.iptrunk_sideB_ae_geant_a_sid}}"