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

First commit

parent abfa84ca
No related branches found
No related tags found
1 merge request!7Modifications to iptrunk domain model
Showing
with 593 additions and 90 deletions
# geant-gap-ansible
## Getting started
To make it easy for you to get started with GitLab, here's a list of recommended next steps.
Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
## Add your files
- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:
```
cd existing_repo
git remote add origin https://gitlab.geant.org/goat/geant-gap-ansible.git
git branch -M main
git push -uf origin main
```
## Integrate with your tools
- [ ] [Set up project integrations](https://gitlab.geant.org/goat/geant-gap-ansible/-/settings/integrations)
## Collaborate with your team
- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
- [ ] [Automatically merge when pipeline succeeds](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)
## Test and Deploy
Use the built-in continuous integration in GitLab.
- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html)
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing(SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
***
# Editing this README
When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thank you to [makeareadme.com](https://www.makeareadme.com/) for this template.
## Suggestions for a good README
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
## Name
Choose a self-explaining name for your project.
## Description
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
## Badges
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
## Visuals
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
## Installation
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
## Usage
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
## Support
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
## Roadmap
If you have ideas for releases in the future, it is a good idea to list them in the README.
## Contributing
State if you are open to contributions and what your requirements are for accepting them.
For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
## Authors and acknowledgment
Show your appreciation to those who have contributed to the project.
## License
For open source projects, say how it is licensed.
## Project status
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
Here we store ansible roles and playbooks to be used with Forkflow Orchestrator.
The intention is to transform this in a proper Ansible Collection.
File added
File added
from ansible_merge_vars import ActionModule
[defaults]
nocolor=true
- name: Manage base config playbook
hosts: all
gather_facts: yes
remote_user: admin
vars_files:
- /opt/ansible_inventory/group_vars/junos/device_access.yaml
roles:
- Juniper.junos
- roles/base_config
tasks:
- name: Import routers variables
ansible.builtin.include_vars:
dir: /opt/ansible_inventory/group_vars/routers
---
- hosts: all
user: admin
vars_files:
- /opt/ansible_inventory/group_vars/junos/device_access.yaml
tasks:
- name: collect default set of facts
junipernetworks.junos.junos_facts:
gather_subset: hardware
register: router_facts
- name: show facts
debug:
msg: "{{ router_facts }}"
- name: Manage base config playbook
hosts: staging_routers
roles:
- Juniper.junos
- roles/iptrunks
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 base_config
---
# handlers file for base_config
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: Create a folder for all the things
ansible.builtin.file:
path: "/var/tmp/ansible_run_{{opid}}"
state: directory
mode: '0755'
- name: Merge the variables
include_tasks: merge_variables.yaml
- name: Print the template in "/var/tmp/ansible_run_{{opid}}/{{mytemplates.template_name}}.conf"
template:
src: "{{ mytemplates.template_path }}"
dest: "/var/tmp/ansible_run_{{opid}}/{{mytemplates.template_name}}.conf"
lstrip_blocks: yes
trim_blocks: yes
delegate_to: localhost
- name: Send message to syslog
syslogger:
msg: "[[{{opid}}]] {{mytemplates.template_name}} compiled"
log_pid: true
- name: Send end of operation in syslog
syslogger:
msg: "[[{{opid}}]] deploy base config on {{inventory_hostname}} dry run"
log_pid: true
- name: Deploy base_config on "{{inventory_hostname}}" [CHECK ONLY]
juniper_junos_config:
load: 'replace'
src: "/var/tmp/ansible_run_{{opid}}/{{mytemplates.template_name}}.conf"
format: text
config_mode: "private"
check: yes
commit: no
register: response
when: verb == "deploy" and dryrun == "True"
#- name: Show diff for dry run
# debug:
# msg: "{{ response }}"
# when: verb == "deploy" and dryrun == "True"
- name: Send end of operation in syslog
syslogger:
msg: "[[{{opid}}]] deploy base config on {{inventory_hostname}} for real "
log_pid: true
- name: Deploy base_config on "{{inventory_hostname}}" [AND COMMIT]
juniper_junos_config:
load: 'replace'
src: "/var/tmp/ansible_run_{{opid}}/{{mytemplates.template_name}}.conf"
format: text
config_mode: "private"
comment: "{{ commit_comment }}"
register: response
when: verb == "deploy" and dryrun == "False"
- name: Show diff
debug:
msg: "{{ response }}"
when: verb == "deploy" and dryrun == "False"
- name: Send end of operation in syslog
syslogger:
msg: "[[{{opid}}]] Ending operations "
log_pid: true
---
# tasks file for base_config
- name: Print the usage
debug:
msg:
- "Allowed verbs: 'compile' and 'deploy'. Use: -e 'verb=$verb'."
when: (verb is not defined) or (verb not in verbs)
- meta: end_play
when: (verb is not defined) or (verb not in verbs)
- name: Gather_facts
junipernetworks.junos.junos_facts:
gather_subset: all
- name: Import routers variables
ansible.builtin.include_vars:
dir: /opt/ansible_inventory/group_vars/routers
- set_fact:
opid: "{{ lookup('community.general.random_string', length=18, special=false) }}"
config_is_different: "False"
- name: Print the ID
debug:
msg: "{{opid}}"
- include: compile_base_config.yaml
when: verb in verbs
- include: deploy_base_config.yaml
when: verb == "deploy"
## This playbook is used to merge variables that are splitted in group and host vars.
# Currently, this is valid for:
# system_login_users
# system_login_classes
# snmp_communities
#
# This playbook should be included in any other playbook that makes use of these variables.
#
- name: Merge system login user vars
merge_vars:
suffix_to_merge: users__to_merge
merged_var_name: system_login_users
expected_type: 'list'
- name: Merge system login classes vars
merge_vars:
suffix_to_merge: classes__to_merge
merged_var_name: system_login_classes
expected_type: 'list'
- name: Merge snmp communities vars
merge_vars:
suffix_to_merge: snmp_communities__to_merge
merged_var_name: snmp_communities
expected_type: 'list'
{% include 'class_of_service.j2' %}
{% include 'chassis.j2' %}
{# #}
{% include 'forwarding_options.j2' %}
{# #}
{% include 'firewall.j2' %}
{# #}
{% include 'groups.j2' %}
{# #}
{% include 'interfaces.j2' %}
{# #}
{% include 'policy_options.j2' %}
{# #}
{% include 'policy_statements.j2' %}
{# #}
{% include 'routing_options.j2' %}
{# #}
{% include 'services.j2' %}
{# #}
{% include 'snmp.j2' %}
{# #}
{% include 'protocols/protocols_global.j2' %}
{% include 'system/system_global.j2' %}
{% include 'routing_instances.j2' %}
replace: chassis {
dump-on-panic;
{% if ansible_net_has_2RE == true %}
redundancy {
routing-engine 0 master;
routing-engine 1 backup;
failover {
on-loss-of-keepalives;
on-disk-failure;
}
{% if chassis_graceful_switchover_inactive is sameas true%}
inactive: graceful-switchover;
{% else %}
graceful-switchover;
{% endif %}
}
{% endif %}
routing-engine {
disk {
smart-check;
}
}
aggregated-devices {
ethernet {
device-count {{ chassis_aggredated_ethernet_count }};
}
}
{% if ansible_net_has_2RE == true %}
{% if chassis_fabric_rm is defined %}
fabric {
redundancy-mode {
{{ chassis_fabric_rm }};
}
}
{% endif %}
{% endif %}
{% if chassis_fpcs is defined %}
{% for fpc in chassis_fpcs %}
fpc {{ fpc.fpc_id }} {
{% if ( fpc.power is defined ) and ( fpc.power == "off" ) %}
power off;
{% else %}
{% for pic in fpc.pics %}
pic {{ pic.pic_id }} {
{% if pic.pic_mode is defined %}
pic-mode {{ pic.pic_mode }};
{% endif %}
{% if pic.tunnel_services is defined %}
tunnel-services {
bandwidth {{ pic.tunnel_services }};
}
{% endif %}
{% if pic.inline_services is defined %}
inline-services {
bandwidth {{ pic.inline_services }};
}
{% endif %}
{% if pic.ports is defined %}
{% for port in pic.ports %}
port {{ port.id }} {
speed {{ port.speed }};
}
{% endfor %}
{% endif %}
}
{% endfor %}
sampling-instance ipfx;
inline-services flex-flow-sizing ;
{% endif %}
}
{% endfor %}
{% else %}
{% for net_module in ansible_net_modules %}
{% if 'FPC' in net_module.name %}
{% set fpc_name_as_list = net_module.name.split(" ") %}
fpc {{ fpc_name_as_list[1] }} {
{% if fpc_name_as_list[1] is sameas "0" %}
pic 0 {
tunnel-services {
bandwidth 10g;
}
inline-services {
bandwidth 10g;
}
}
{% endif %}
sampling-instance ipfx;
inline-services flex-flow-sizing ;
}
{% endif %}
{% endfor %}
{% endif %}
{% if chassis_enhanced_ip is sameas true %}
network-services enhanced-ip;
{% endif %}
}
replace: class-of-service {
{% if cos_classifiers is defined %}
classifiers {
{% for classifier in cos_classifiers %}
{{ classifier.type }} {{ classifier.name }} {
import {{ classifier.import }};
{% for forwarding_class in classifier.forwarding_classes %}
forwarding-class {{ forwarding_class.name}} {
loss-priority {{ forwarding_class.loss_priority }} code-points [{% for code_point in forwarding_class.code_points %} {{ code_point }} {% endfor %} ];
}
{% endfor %}
}
{% endfor %}
}
{% else %}
{{ raise('ERROR: YOU HAVE NO CLASSIFIERS DEFINED')}}
{%endif %}
{% if cos_drop_profiles is defined %}
drop-profiles {
{% for drop_profile in cos_drop_profiles %}
{{ drop_profile.name }} {
interpolate {
fill-level [{% for fill_level in drop_profile.fill_levels %} {{ fill_level }} {% endfor %} ];
drop-probability [{% for drop_probability in drop_profile.drop_probabilities %} {{ drop_probability }} {% endfor %} ];
}
}
{% endfor %}
}
{% else %}
{{ raise('ERROR: YOU HAVE NO DROP-PROFILES DEFINED')}}
{%endif %}
{% if cos_forwarding_classes is defined %}
forwarding-classes {
{% for fc in cos_forwarding_classes %}
class {{ fc.name }} queue-num {{ fc.queue_num }} priority {{ fc.priority }};
{% endfor %}
}
{% endif %}
{% if cos_interfaces is defined %}
interfaces {
{% for interface in cos_interfaces %}
{{ interface.regex }} {
{% if interface.scheduler_map is defined %}
scheduler-map {{ interface.scheduler_map}};
{% endif %}
unit * {
classifiers {
{% for classifier in interface.classifiers %}
{{ classifier.type }} {{ classifier.name }} ;
{% endfor %}
}
{% if interface.rewrite_rules is defined %}
rewrite-rules {
{% for rr in interface.rewrite_rules %}
{{ rr.type }} {{ rr.name }} protocol {{ rr.protocol}};
{% endfor %}
}
{% endif %}
}
}
{% endfor %}
}
{% else %}
{{ raise('ERROR: YOU HAVE NO INTERFACES DEFINED')}}
{% endif %}
{% if cos_rewrite_rules is defined %}
{% for rewrite_rule in cos_rewrite_rules %}
rewrite-rules {
{{ rewrite_rule.type }} {{ rewrite_rule.name }} {
import {{ rewrite_rule.import }}
{% if rewrite_rule.forwarding_classes is defined %}
{% for fc in rewrite_rule.forwarding_classes %}
forwarding-class {{ fc.name }} {
{% if fc.loss_priorities is defined %}
{% for lp in fc.loss_priorities %}
loss-priority {{ lp.type }} code-point {{ lp.code_point }};
{% endfor %}
{% endif %}
}
{% endfor %}
{% endif %}
}
}
{% endfor %}
{% endif %}
{% if cos_scheduler_maps is defined %}
scheduler-maps {
{% for scheduler_map in cos_scheduler_maps %}
{{ scheduler_map.name }} {
{% for mapping in scheduler_map.mappings %}
forwarding-class {{ mapping.class }} scheduler {{ mapping.scheduler }} ;
{% endfor %}
}
{% endfor %}
}
{% else %}
{{ raise('ERROR: YOU HAVE NO SCHEDULER-MAP DEFINED')}}
{% endif %}
{% if cos_schedulers is defined %}
schedulers {
{% for scheduler in cos_schedulers %}
{{ scheduler.name }} {
{% if scheduler.transmit_rate.unit == "remainder" %}
transmit-rate {
remainder;
}
{% elif scheduler.transmit_rate.unit == "percent" %}
transmit-rate percent {{ scheduler.transmit_rate.value }};
{% elif scheduler.transmit_rate.unit == "rate" %}
transmit-rate {{ scheduler.transmit_rate.value }};
{% else %}
{{ raise('ERROR: SCHEDULER TRANSMIT-RATE scheduler.transmit_rate.value NOT VALID')}}
{% endif %}
{% if ((scheduler.buffer_size.unit == "remainder") or (scheduler.buffer_size.unit == "shared")) %}
buffer-size {
{{ scheduler.buffer_size.unit }};
}
{% elif ((scheduler.buffer_size.unit == "percent") or (scheduler.buffer_size.unit == "temporal")) %}
buffer-size {{ scheduler.buffer_size.unit }} {{ scheduler.buffer_size.value }};
{% else %}
{{ raise('ERROR: SCHEDULER TRANSMIT-RATE scheduler.buffer_size.value NOT VALID')}}
{% endif %}
priority {{ scheduler.priority }};
{% if scheduler.drop_profile_map is defined %}
drop-profile-map loss-priority {{ scheduler.drop_profile_map.loss_priority }} protocol {{ scheduler.drop_profile_map.protocol }} drop-profile {{ scheduler.drop_profile_map.drop_profile }};
{% endif %}
}
{% endfor %}
}
{% else %}
{{ raise('ERROR: YOU HAVE NO SCHEDULER DEFINED')}}
{% endif %}
}
{##}
{#We should validate, but raise does not work :-( #}
{% set supported_from = [ 'destination-address','destination-port','icmp-type','port','prefix-list','protocol','source-address','source-prefix-list','tcp-established' ] %}
{% set supported_then = [ 'accept','policer','discard','reject' ] %}
{##}
firewall {
{% for family, filters in firewall.items() %}
{% if family != "policer" %}
family {{ family }} {
{% for filter, filter_data in filters.items() %}
replace: filter {{ filter }} {
{% if filter_data.options is defined %}
{{ filter_data.options }};
{% endif %}
{% for term in filter_data.terms %}
term {{ term.name }} {
{% if term.from is defined %}
from {
{% for from, from_data in term.from.items() %}
{# Stuff that goes in line: like ports, protocols and similar#}
{% if "tcp-established" in from %}
tcp-established;
{% elif ("port" in from) or ("protocol" in from) or ("icmp-type" in from) or ("next-header" in from) or ("hop-limit" in from)%}
{% if (from_data is iterable) and (from_data is not string) %}
{{ from }} [ {% for from_data_element in from_data %}{{ from_data_element }} {% endfor %} ];
{% else %}
{{ from }} {{ from_data }};
{% endif %}
{# Stuff that goes in a list: like addresses, prefix lists etc... #}
{% else %}
{{ from }} {
{% for from_data_element in from_data %}
{{ from_data_element }};
{% endfor %}
}
{% endif %}
{% endfor %}
}
{% endif %}
then {
{% if (term.then is iterable) and (term.then is not string) %}
{% for then_action in term.then %}
{% if then_action is not string %}
{% for action, destination in then_action.items() %}
{{ action }} {{ destination}};
{% endfor %}
{% else %}
{{ then_action }};
{% endif %}
{% endfor %}
{% else %}
{{ term.then }};
{% endif %}
}
}
{% endfor %}
}
{% endfor %}
}
{% else %}
{% for filter, filter_data in filters.items() %}
replace: policer {{ filter }} {
{% if filter_data.options is defined %}
{{ filter_data.options }};
{% endif %}
if-exceeding {
bandwidth-limit {{ filter_data.bandwidth_limit }};
burst-size-limit {{ filter_data.burst_size_limit }};
}
then discard;
}
{% endfor %}
{% endif %}
{% endfor %}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment