Skip to content
Snippets Groups Projects
Verified Commit 91dd60fd authored by Simone Spinelli's avatar Simone Spinelli Committed by Karel van Klink
Browse files

Add base config and IP trunks

Iptrunks conversion from subscription

Adjust base config role and change all dryrun to dry_run

Remove get_facts from iptrunk role + variuos little things

Add iptrunk_checks playbook and resolv some Ansible warnings

Base config always targets console

Ansible host is still a problem

Add a placehlder for installing Ansible

Use ansible_host to target hosts that do not have resolution/reachability

Manage ansible_host inside playbooks when node is offline

make ansible-lint happy

Manage ansible_host when device is offline

Make ansible-lint happy

Modifications to devices and sites: terminal server moved to Site

Add linting

Update management of terminal server also in iptrunks

Base config push working in WFO

Trunks rework: temp/untested changes to enable WFO rework

Refactoring device -> router

Fix indentation and selection of ansible_network_os

More indentation problems

Fix errors with refactoring and task inclusion

Fixed IPtrunk for Juniper - including netconf knob

fix IPTrunk deployment, and add descriptions to nokia interfaces

add .gitignore

Adjusti iptrunk role vars to match new domain model

Add base_config and iptrunks
parent abfa84ca
No related branches found
No related tags found
No related merge requests found
Showing
with 348 additions and 90 deletions
skip_list:
- 'name[template]' # Jinja templates should only be at the end of ‘name’.
- 'yaml[line-length]' # Line too long (162 > 160 characters)
- 'no-free-form' # Avoid using free-form when calling module actions. (ansible.builtin.set_fact)
- 'role-name[path]' # Avoid using paths when importing roles.
__pycache__/
# here we should put everything related with installing Ansible:
- pip dependencies
- ansible dependencies
- config files
### TODO
# geant-gap-ansible # geant-gap-ansible
Here we store ansible roles and playbooks to be used with Forkflow Orchestrator.
The intention is to transform this in a proper Ansible Collection.
## 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.
File added
from ansible_merge_vars import ActionModule
[defaults]
host_key_checking=false
display_skipped_hosts = false
#stdout_callback = actionable
- name: Manage base config playbook
hosts: all
gather_facts: false
remote_user: admin
roles:
- Juniper.junos
- roles/base_config
---
- 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 }}"
all:
hosts:
rt2.hlv01.nl.geant.net:
rt2.pi01.it.geant.net:
- name: Manage iptrunks playbook
hosts: all
remote_user: admin
gather_facts: false
roles:
- Juniper.junos
- roles/iptrunks
- name: Manage iptrunks checks playbook
hosts: all
remote_user: admin
vars_files:
- /opt/ansible_inventory/group_vars/junos/router_access.yaml
roles:
- Juniper.junos
- roles/iptrunks_checks
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: Simone Spinelli for GOAT
description: Geant Orchestration and Automation Team
company: geant
# 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 BSD-3-Clause
min_ansible_version: '2.10'
# 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:
- network
# 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: []
# - role: "Juniper.junos"
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
# if you add dependencies to this list.
- name: Merge the variables
ansible.builtin.include_tasks: merge_variables.yaml
- name: Fix ISO_system_id for Nokia (step1)
ansible.builtin.set_fact:
lo_iso_address_as_a_list: "{{ wfo_router.router.router_lo_iso_address.split('.') }}"
- name: Fix ISO_system_id for Nokia (step2)
ansible.builtin.set_fact:
iso_system_id: "{{ lo_iso_address_as_a_list[3:6] | join('.') }}"
- name: Set ansible host to localhost to compile config when router is offline
ansible.builtin.set_fact:
ansible_host: "localhost"
ansible_connection: local
when:
( wfo_router.router.router_access_via_ts | ansible.builtin.bool ) is true
- name: Create a folder for all the things
ansible.builtin.file:
path: "/var/tmp/ansible_run_{{ opid }}"
state: directory
mode: '0755'
delegate_to: localhost
- name: Print the template in "/var/tmp/ansible_run_{{ opid }}/base_config.conf"
ansible.builtin.template:
src: "routers/{{ wfo_router.router.router_vendor }}/base_config.j2"
dest: "/var/tmp/ansible_run_{{ opid }}/base_config.conf"
lstrip_blocks: true
trim_blocks: true
mode: '0755'
delegate_to: localhost
- name: Set back ansible_host to target terminal server
ansible.builtin.set_fact:
ansible_host: "{{ wfo_router.router.router_site.site_ts_address }}"
ansible_connection: netconf
when:
( wfo_router.router.router_access_via_ts | ansible.builtin.bool ) is true
- name: Deploy base_config on "{{ inventory_hostname }}" [CHECK ONLY][Juniper]
juniper_junos_config:
load: 'replace'
src: "/var/tmp/ansible_run_{{ opid }}/{{ mytemplates.template_name }}.conf"
format: text
config_mode: "private"
check: true
commit: false
register: response
when: >
verb == "deploy" and
( dry_run | ansible.builtin.bool ) is true and
wfo_router.router.router_vendor == "juniper"
- name: Show diff for dry run
ansible.builtin.debug:
msg: "{{ response }}"
when: >
verb == "deploy" and
( dry_run | ansible.builtin.bool ) is true and
wfo_router.router.router_vendor == "juniper"
- name: Deploy base_config on "{{ inventory_hostname }}" [AND COMMIT][Juniper]
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
( dry_run | ansible.builtin.bool ) is false and
wfo_router.router.router_vendor == "juniper"
- name: Show diff
ansible.builtin.debug:
msg: "{{ response }}"
when: >
verb == "deploy" and
( dry_run | ansible.builtin.bool ) is false and
wfo_router.router.router_vendor == "juniper"
- name: Deploy base_config on "{{ inventory_hostname }}" [CHECK ONLY][NOKIA]
ansible.netcommon.netconf_config:
format: xml
default_operation: merge
content: "{{ lookup('ansible.builtin.template', 'routers/{{ wfo_router.router.router_vendor }}/base_config.j2') }}"
commit: true
diff: true
check_mode: true
when: >
verb == "deploy" and
( dry_run | ansible.builtin.bool ) is true and
wfo_router.router.router_vendor == "nokia"
- name: Deploy base_config on "{{ inventory_hostname }}" [AND COMMIT][NOKIA]
ansible.netcommon.netconf_config:
format: xml
default_operation: merge
content: "{{ lookup('ansible.builtin.template', 'routers/{{ wfo_router.router.router_vendor }}/base_config.j2') }}"
commit: true
diff: true
check_mode: false
when: >
verb == "deploy" and
( dry_run | ansible.builtin.bool ) is false and
wfo_router.router.router_vendor == "nokia"
---
# tasks file for base_config
- name: Print the usage
ansible.builtin.debug:
msg:
- "Allowed verbs: 'compile' and 'deploy'. Use: -e 'verb=$verb'."
when: (verb is not defined) or (verb not in verbs)
- name: Set ansible_host to terminal server when router is offline
ansible.legacy.set_fact:
ansible_host: "{{ wfo_router.router.router_site.site_ts_address }}"
ansible_port: "{{ wfo_router.router.router_ts_port }}"
when:
( wfo_router.router.router_access_via_ts | ansible.builtin.bool ) is true
- name: Set variable to connect to nokia
ansible.legacy.set_fact:
ansible_network_os: nokia.sros.md
ansible_connection: netconf
when:
wfo_router.router.router_vendor == "nokia"
- name: Set variables for connecting to Junos
ansible.legacy.set_fact:
ansible_network_os: junos
ansible_connection: netconf
when:
wfo_router.router.router_vendor == "juniper"
- name: Fail if arguments are missing
ansible.legacy.meta: end_play
when: (verb is not defined) or (verb not in verbs)
- name: Get the facts from Juniper router
junipernetworks.junos.junos_facts:
gather_subset: all
when:
wfo_router.router.router_vendor == "juniper"
- name: Import routers variables
ansible.builtin.include_vars:
dir: /opt/ansible_inventory/group_vars/routers
- name: Generate an ID for this run
ansible.legacy.set_fact:
opid: "{{ lookup('community.general.random_string', length=18, special=false) }}"
config_is_different: "False"
- name: Print the ID
ansible.builtin.debug:
msg: "{{ opid }}"
- name: Include always compiling phase
ansible.builtin.include_tasks: compile_base_config.yaml
when: verb in verbs
- name: Include deploy if selected
ansible.builtin.include_tasks: 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'
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment