Bonus
Add Template and Policy using policy module

Configure Template and Policy

Step 1 - create a new branch

We will use a new branch to add the template and policy but first make sure you pull the latest change from main branch

  1. Switch to main branch
                
            git checkout main
                
            
                
            Switched to branch 'main'
            Your branch is up to date with 'origin/main'.
                
            
  2. Pull the latest update first
                
            git pull
                
            
                
    remote: Enumerating objects: 1, done.
    remote: Counting objects: 100% (1/1), done.
    remote: Total 1 (delta 0), reused 0 (delta 0), pack-reused 0
    Unpacking objects: 100% (1/1), 257 bytes | 257.00 KiB/s, done.
    From 10.0.208.215:CL-POD02/DEVWKS-3320
       539bcbe..1b8c832  main       -> origin/main
    Updating 539bcbe..1b8c832
    Fast-forward
     prod.env.tfvars                    | 12 ++++++++++++
     stage.env.tfvars                   | 12 ++++++++++++
     task01_interfaces/interface.tfvars | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
     task01_interfaces/main.tf          | 23 +++++++++++++++++++++++
     task01_interfaces/variables.tf     | 39 +++++++++++++++++++++++++++++++++++++++
     task02_overlay/main.tf             | 23 +++++++++++++++++++++++
     task02_overlay/overlay.tfvars      | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     task02_overlay/variables.tf        | 43 +++++++++++++++++++++++++++++++++++++++++++
     8 files changed, 264 insertions(+)
                
            
  3. Create a new local branch called policy:
                
            git checkout -b policy
                
            
                
            Switched to a new branch 'policy'
                
            

Step 2 - add template and policy

  1. Open file main.tf

            
        code -r /home/cisco/CiscoLive/DEVWKS-3320/main.tf
            
        

    Add below content to the end of file and press Ctrl+s to save it.

            
    
        module "policy" {
          source      = "./modules/policy"
          fabric_name = var.fabric_name
          inventory   = var.inventory
          templates   = var.templates
          policies    = var.policies
        }
            
        
  2. Open file variables.tf

            
        code -r /home/cisco/CiscoLive/DEVWKS-3320/variables.tf
            
        

    Add below content to the end of file and press Ctrl+s to save it.

            
    variable "templates" {
      type = list(object({
        name        = string
        description = string
        file        = string
      }))
    }
    
    variable "policies" {
      type = list(object({
        switch_id     = string
        template_name = string
        description   = string
        priority      = number
        props         = map(any)
      }))
    }
            
        
  3. Open file common.tfvars

            
        code -r /home/cisco/CiscoLive/DEVWKS-3320/common.tfvars
            
        

    Add below content to the end of file and press Ctrl+s to save it.

            
    templates = [
      {
        name        = "telemetry"
        description = "static telemetry config"
        file        = "./telemetry.tmpl"
      }
    ]
    
    policies = [
      {
        switch_id     = 101
        template_name = "telemetry"
        description   = "dialout telemetry"
        priority      = 500
        props         = {}
      },
      {
        switch_id     = 102
        template_name = "telemetry"
        description   = "dialout telemetry"
        priority      = 500
        props         = {}
      },
      {
        switch_id     = 201
        template_name = "telemetry"
        description   = "dialout telemetry"
        priority      = 500
        props         = {}
      },
      {
        switch_id     = 101
        template_name = "ntp_server"
        description   = "ntp_server 10.81.254.131"
        priority      = 500
        props = {
          "NTP_SERVER"     = "10.81.254.131"
          "NTP_SERVER_VRF" = "management"
        }
      },
      {
        switch_id     = 102
        template_name = "ntp_server"
        description   = "ntp_server 10.81.254.131"
        priority      = 500
        props = {
          "NTP_SERVER"     = "10.81.254.131"
          "NTP_SERVER_VRF" = "management"
        }
      },
      {
        switch_id     = 201
        template_name = "ntp_server"
        description   = "ntp_server 10.81.254.131"
        priority      = 500
        props = {
          "NTP_SERVER"     = "10.81.254.131"
          "NTP_SERVER_VRF" = "management"
        }
      }
    ]
            
        
  4. Open file telemetry.tmpl

            
        code -r /home/cisco/CiscoLive/DEVWKS-3320/telemetry.tmpl
            
        

    Copy below content to the file and press Ctrl+s to save it.

            
    ##template variables
    ##
    ##template content
    ! example of freeform template
    feature telemetry
    
    telemetry
      destination-profile
        use-vrf management
      destination-group 1
        ip address 1.1.1.1  port 57000 protocol gRPC encoding GPB
      sensor-group 1
        data-source DME
        path sys/ch depth unbounded
      sensor-group 2
        data-source DME
        path sys/intf depth unbounded
      subscription 1
        dst-grp 1
        snsr-grp 1 sample-interval 10000
      subscription 2
        dst-grp 1
        snsr-grp 2 sample-interval 10000
    ##
            
        

Step 3 - Commit code to local stage branch

    
git commit -a -m "policy"
    

    
[policy abccf7b] policy
 4 files changed, 109 insertions(+)
    

Step 4 - Push local branch stage to remote

    
    git push --set-upstream origin policy
    

    
Enumerating objects: 10, done.
Counting objects: 100% (10/10), done.
Delta compression using up to 8 threads
Compressing objects: 100% (6/6), done.
Writing objects: 100% (6/6), 1.19 KiB | 1.19 MiB/s, done.
Total 6 (delta 4), reused 0 (delta 0), pack-reused 0
remote:
remote: To create a merge request for policy, visit:
remote:   http://10.0.208.215/CL-POD02/DEVWKS-3320/-/merge_requests/new?merge_request%5Bsource_branch%5D=policy
remote:
To 10.0.208.215:CL-POD02/DEVWKS-3320.git
 * [new branch]      policy -> policy
branch 'policy' set up to track 'origin/policy'.
    

Step 5 - Create a Pull Request

Now we need to create PR to actual test the config on the staging environment, Open gitlab on a new tab:

  • Gitlab URL: http://10.0.208.215/CL-POD02/DEVWKS-3320

At the Gitlab login screen, login using your username and password:

  • Username: user02
  • Password: cisco.123

  1. Click Merge Requests on side menu
  2. Then click New Merge Requests
  3. Select policy as Source branch
  4. Select main as Target branch
  5. Then click Compare branches and continue
  6. leave all the field as default, then click Create merge request
  7. Click circle in below screen, navigate to pipeline page
  8. Wait till pipeline finished, if any pipeline failed, you can click the step to check the error message

Step 6 - Merge the change

  1. Click Merge requests on side menu
  2. Then click PR we just created: policy
  3. On PR detal page Click Merge
  4. Once code is merged, a new pipeline(CD piplien) is triggered, click circle in blow screen
  5. Wait till pipeline is finished
  • Introduction
  • NDFC and Terraform
  • Envrionment and Topology
  • Task01 Interface Module
  • Task02 Overlay Module
  • Task03 CI/CD Pipeline
  • Bonus: Policy Module
  • Thanks