Coder Social home page Coder Social logo

frr_add-static-route_ansible's Introduction

Ansible Playbook to Add a Static Route on FRR

This Ansible playbook is designed to add a static route to devices running Free Range Routing (FRR). It installs FRR if not already present, configures the static route, and restarts the FRR service to apply the changes.

Directory Structure

Ensure your directory structure looks like this:

ansible/
├── inventory
│   └── hosts
├── playbooks
│   └── add_static_route.yml
└── roles
    └── frr
        ├── handlers
        │   └── main.yml
        ├── tasks
        │   └── main.yml
        └── templates
            └── static_route.j2

Inventory File (inventory/hosts)

Define your target hosts in an inventory file.

[frr_routers]
router1 ansible_host=192.168.1.1 ansible_user=your_user ansible_password=your_password

Playbook (playbooks/add_static_route.yml)

Create a playbook to execute the role.

- name: Add static route to FRR routers
  hosts: frr_routers
  become: yes
  roles:
    - frr
  vars:
    static_route:
      destination: "10.0.0.0/24"
      next_hop: "192.168.1.254"

Role Tasks (roles/frr/tasks/main.yml)

Define the tasks to configure the static route.

- name: Ensure FRR is installed
  package:
    name: frr
    state: present

- name: Template the static route configuration
  template:
    src: static_route.j2
    dest: /etc/frr/staticd.conf
    owner: frr
    group: frr
    mode: 0644
  notify: restart frr

- name: Ensure FRR service is running
  service:
    name: frr
    state: started
    enabled: yes

Template (roles/frr/templates/static_route.j2)

Create a template file to define the static route configuration.

ip route {{ static_route.destination }} {{ static_route.next_hop }}

Handlers (roles/frr/handlers/main.yml)

Define handlers to restart FRR if the configuration changes.

- name: restart frr
  service:
    name: frr
    state: restarted

Variables

You can define variables in a vars directory or directly in the playbook. For simplicity, let's include it in the playbook as shown above.

Running the Playbook

Navigate to your ansible directory and run the playbook with the following command:

ansible-playbook -i inventory/hosts playbooks/add_static_route.yml

This playbook ensures FRR is installed, templates the static route configuration into the staticd.conf file, and restarts the FRR service to apply the changes. You can modify the destination and next_hop variables to suit your requirements.

Customizing the Static Route

To customize the static route, modify the destination and next_hop variables in the playbook:

vars:
  static_route:
    destination: "your_destination_network"
    next_hop: "your_next_hop_ip"

Requirements

Ansible 2.9 or later
Devices running Free Range Routing (FRR)
SSH access to the target devices with appropriate user permissions

Author

This playbook was created by Ehsan Momeni Bashusqeh.

frr_add-static-route_ansible's People

Contributors

emomeni avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.