SROS Config Generation with Ansible

When I’m building new Alcatel routers, I have a pretty simple process that makes building and deploying new 7705’s pretty simple. It’s all thanks to Ansible and Ansible-playbook. A sample Ansible playbook is available here: https://github.com/nlgotz/sros-ansible

The overall steps are as follows:

  1. Collect all information on the device, IP addresses, and far-end devices.
  2. Add all that information to the ansible-playbook folder
  3. Run ansible-playbook
  4. Copy the generated config files to the CF cards for the SAR.
  5. Power up the SAR.
  6. Watch the boot up cycle to make sure everything worked properly.

The Process

Information Collection

I start by collecting the device information that is needed for building the SAR. This includes things like the host name, location, what cards are in the box, IP addresses, router interface names, etc.

I’m not going to go into too much detail here, as everyone’s company does it differently.

Add the Information to the Ansible Playbook

This is a two step process. First you need to add the device name to the hosts file. It’s as simple as this:

cat hosts
[sros]
SROS01

Really simple, huh? Well, that’s the easy one, the next one is a bit more complicated. The host vars file has all the important information that Ansible will use to build the config file.

The file name should be named (in this case) SROS01.yml. It should be the hostname that you used in the hosts file followed by .yml.

Below is a sample yml file (This is taken from my GitHub repository):

cat host_vars/SROS01.yml
---
management:
    hostname: SROS01
    location: "Site A"
    systemIP: 10.1.1.1

mda:
    - id: 1
      mda_type: a8-1gb-v3-sfp
      ethernet: true
    - id: 3
      mda_type: a6-em
    - id: 6
      mda_type:  a12-sdi

ports:
    - id: 1/1/1
      type: ethernet
      description: "to SROS02"
      mode: network
      encap: "null"
    - id: 1/1/3
      type: ethernet
      description: "to Switch 1"
      mode: access
      encap: dot1q
    - id: 1/6/1
      type: rs232
      description: "to Cpipe"

router_interface:
    - id: "to-SROS02-01"
      address: 10.0.0.0/31
      port: 1/1/1


ospf:
    - id: 0.0.0.1
      interfaces:
        - id: "system"
        - id: "to-SROS02-01"
          type: "point-to-point"

services:
    - id: 11001
      description: "Data and Voice VPRN"
      type: vprn
      customer: 200
      interfaces:
        - id: "21001"
          description: "Management VPLS"
          address: 10.2.5.1/24
          vpls: "M1"
          saps:
            - id: 1/1/3:1
        - id: "21002"
          description: "Data VPLS"
          address: 10.2.6.1/24
          vpls: "D2"
          saps:
            - id: 1/1/3:2
          dhcp: true
    - id: 21000
      type: m-vpls
      customer: 200
      saps:
        - id: 1/1/3:0

timing:
    - id: 1
      port: 1/1/1

This basically all of the config needed to get a basic SAR configuration setup.

In order for it to work for you, you will need to modify it to meet your standards. The meat of the config file is in roles/ansible_router/templates/config.j2 and roles/ansible_bof/templates/bof.j2. This will create both the config file (named .cfg) and bof.cfg.

Run Ansible Playbook

Now, assuming you have modified the config.j2 and bof.j2 to meet your needs, it should be as simple as running the following command and you will have your configs:

ansible-playbook -i hosts sros.yml

Now, assuming you have all of the variables filled in, you should see the following:

...
PLAY RECAP *********************************************************************
SROS01                     : ok=5    changed=3    unreachable=0    failed=0   

This means that everything worked. And you should now have a nice new build folder:

build/
	SROS01/
		bof.cfg
		SROS01.cfg

If you look at the config files that are generated, you will see that they have all the variables correctly filled in.

Copy the files to the CF Card

Once the config files are generated by Ansible, you can copy the config files over to the CF cards (assuming you use the A and B CSMs).

Power up the SAR and monitor the boot cycle

Once the CF cards are installed in the CSM, boot up the SAR and watch the SAR boot up. Doing this allows you to watch when it loads the config file and make sure that everything loads properly.

Modifying the template files

Every company has their own standards for router configs. The way I initially built the router config jinja2 template was I took an existing SAR config and started replacing the things that change with variables. I have kept it pretty simple. It will build the base router and add some simple services like VPRN, r-VPLS, and m-VPLS. I leave the more complicated and individual things (VLL services) for after router is in and working. It’s sometimes easier to just push things with 5620 SAM.

Conclusion

These steps are the way that I build SAR configs. Depending on your environment, you may have to modify some parts to work better. But in the config.j2 file, there are a lot of examples showing how to do various tasks.

comments powered by Disqus