Hands-On: Save FRR Configuration

Let's learn how to use Ansible to retrieve and store configuration details for FRR routers.

We'll cover the following

This lesson uses the same topology as the Hands-On: Display FRR facts lesson. Instead of displaying the facts for the FRR routers on the console, this time we will be storing their configuration details in a simple text file.

FRR on Ansible

The playbooks in this lesson use the frr.frr ansible module to query information from FRR routers.

We are using SSH to connect to the routers.

The save_config.yml file is a playbook that saves the current configuration for all routers into a config directory. The playbook creates this directory itself. A separate .txt file, named after the router’s hostname, is created for each router in the inventory as well.

For instance, if a router’s hostname is, a file config/ will be created.

The playbook uses the super-simple Templates/Config.j2 template to save the configuration to text files.

Other ansible values that one may query are listed in the frr.frr.frr_facts documentation. Some examples include:

  • ansible_net_version: The FRR version on the device
  • ansible_net_mem_stats: Memory statistics for the device
  • ansible_net_hostname: The hostname of the device

Running the playbook

In the example below, we have six devices on our network: PC1, PC2, and PC3 grouped under PCs, and router1, router2, router3 grouped under routers.

Let’s take a look at how we can gather information about our FRR devices using ansible.

Running the widget at the end of this lesson will automatically run the command:

ansible-playbook save_config.yml

This will run the save_config.yml playbook for all devices in the routers group.

To limit the output to just a single device, we can add the --limit flag and provide the IPv4 address of the device we want to single out.

We can get the IPv4 addresses of our devices by using:

cat /etc/ansible/hosts

An example of running the playbook with the --limit flag is as follows:

ansible-playbook save_config.yml --limit

This will limit the task to the device with the provided IP.

If we want to modify and re-run the playbooks, we can use a console-based text editor (Vim, nano) in the terminal window. Then, re-issue the ansible-playbook command. If you modify the playbooks in the widget’s graphical editor, press “Run” to update the underlying container with your updated file(s).

Try it out in the widget below:

Get hands-on with 1200+ tech skills courses.