APNIC 56 Network Automation tutorial
Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Back to homepage

Semaphore REST API with variables

Goal here is to trigger Semaphore REST API lab using variables.

Step 1 - Update your Ansible playbook to include variables

Sample Ansible Playbook

  - hosts: router
    gather_facts: no
    
    tasks: 
      - name: Setup system hostname   
        vyos.vyos.vyos_system:
          host_name: "{{ inventory_hostname }}"

      - name: Setup system timezone    
        vyos.vyos.vyos_config:
          lines: 
            - "set system time-zone {{ timezone }}"
            
      - name: Add IPs to loopback
        vyos.vyos.vyos_l3_interfaces:
          config:
          - name: "{{ interface }}"
            ipv4:
            - address: "{{ ip }}/{{ mask }}"
          state: merged                      

Step 2 - Push the updated playbook on the Gitlab


Step 3 - Trigger Semaphore task

curl -XPOST -H 'Content-Type: application/json' \
-H 'Accept: application/json' -H 'Authorization: Bearer <Token here>' \
-d '{"template_id": 1, "debug": false, "dry_run": false, "playbook": "", "environment": "{\"timezone\":\"Asia/Kolkata\",\"ip\":\"10.10.100.1\",\"mask\":\"30\",\"interface\":\"lo\"}"}' \
https://s01.apnic56.anuragbhatia.com/api/project/1/tasks -v

Same command with spaces for easy reading - DO NOT RUN IT directly

curl -XPOST -H 'Content-Type: application/json' \
-H 'Accept: application/json' -H 'Authorization: Bearer <Token here>' \
-d '{"template_id": 1, "debug": false, "dry_run": false, "playbook": "", 


"environment": "{\"timezone\":\"Asia/Kolkata\",\"ip\":\"10.10.100.1\",\"mask\":\"30\",\"interface\":\"lo\"}"}' \


https://s01.apnic56.anuragbhatia.com/api/project/1/tasks -v