Skip to content
Snippets Groups Projects
Commit b9ec900b authored by Simone Spinelli's avatar Simone Spinelli
Browse files

Remove get_facts from iptrunk role + variuos little things

parent b9654255
Branches
Tags
1 merge request!7Modifications to iptrunk domain model
Showing
with 198 additions and 22 deletions
- name: Manage iptrunks playbook
hosts: all
remote_user: admin
gather_facts: no
vars_files:
- /opt/ansible_inventory/group_vars/junos/device_access.yaml
roles:
......
......@@ -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)
......
......@@ -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)
......
......@@ -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) }}"
......
{% 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 %}
......@@ -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}}"
......
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).
---
# defaults file for iptrunks_checks
---
# handlers file for iptrunks_checks
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.
- 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 }}"
- 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"
---
# 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"
localhost
---
- hosts: localhost
remote_user: root
roles:
- iptrunks_checks
---
# 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}}"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment