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 lab

Trigger the same playbooks via REST API call to Ansible Semaphore as did on day 3 with web UI directly.

curl -v -c /tmp/semaphore-cookie -XPOST \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-d '{"auth": "YOUR_LOGIN", "password": "YOUR_PASSWORD"}' \
https://s01.apnic56.anuragbhatia.com/api/auth/login

Step 2: Setup user access token

Create new token

curl -v -b /tmp/semaphore-cookie -XPOST \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
https://s01.apnic56.anuragbhatia.com/api/user/tokens

Check existing tokens

curl -v -b /tmp/semaphore-cookie \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
https://s01.apnic56.anuragbhatia.com/api/user/tokens

Step 3: Find out project_id

curl -X 'GET' \
-H 'Authorization: Bearer <Token here from step 1>' \
-H 'accept: text/plain; charset=utf-8' \
'https://s01.apnic56.anuragbhatia.com/api/projects'

Step 4: Find template id under the project

curl -X 'GET' \
-H 'Authorization: Bearer <Token here from step 1>' \
-H 'accept: text/plain; charset=utf-8' \
'https://s01.apnic56.anuragbhatia.com/api/project/1/templates'

Step 5: Trigger task

curl -XPOST -H 'Content-Type: application/json' \
-H 'Accept: application/json' -H 'Authorization: Bearer <Token here from step 1>' \
 -d '{"template_id": 1, "debug": false, "dry_run": false, "playbook": "", "environment": ""}' \
 https://s01.apnic56.anuragbhatia.com/api/project/1/tasks -v