Data Center Automation: NX-API & Ansible Basics
CCNP Data Center — DCCOR track EVE-NG — Nexus / ACI lab
مقصدObjectiveObjective
اس lab میں آپ Nexus پر NX-API enable کریں گے، structured JSON output پڑھیں گے، اور agentless Ansible کے تصور کو سمجھیں گے۔Is lab mein aap Nexus par NX-API enable karenge, structured JSON output parhenge, aur agentless Ansible ke tasawwur ko samjhenge.In this lab you will enable NX-API on Nexus, read structured JSON output, and understand the agentless Ansible concept.
آسان مثالSimple AnalogySimple Analogy
NX-API switch کو vending machine بنا دیتا ہے: ہاتھ سے command لکھنے کے بجائے آپ کا program request بھیجتا ہے اور صاف ستھرا JSON جواب ملتا ہے۔ Ansible وہ manager ہے جو ایک ہی order تمام vending machines کو بیک وقت بھیجتا ہے۔NX-API switch ko vending machine bana deta hai: haath se command likhne ke bajaye aap ka program request bhejta hai aur saaf suthra JSON jawab milta hai. Ansible woh manager hai jo ek hi order tamam vending machines ko beek waqt bhejta hai.NX-API turns the switch into a vending machine: instead of typing commands by hand, your program sends a request and gets a neatly packed JSON answer. Ansible is the manager that sends the same order to every vending machine at once.
سیٹ اپLab SetupLab Setup
EVE-NG میں: 1x Nexus 9000v (N9K-1) جس کا mgmt0 آپ کے PC سے reachable ہو۔ NX-API developer sandbox کھولنے کے لیے ایک web browser۔EVE-NG mein: 1x Nexus 9000v (N9K-1) jis ka mgmt0 aap ke PC se reachable ho. NX-API developer sandbox kholne ke liye ek web browser.In EVE-NG: 1x Nexus 9000v (N9K-1) with mgmt0 reachable from your PC. A web browser to open the NX-API developer sandbox.
اقداماتStepsSteps
Step 1
NX-API enable کریں (N9K-1 پر)۔ اس سے switch کا HTTP API on ہو جاتا ہے تاکہ programs اس سے بات کر سکیں۔NX-API enable karein (N9K-1 par). Is se switch ka HTTP API on ho jata hai taake programs is se baat kar sakein.Enable NX-API (on N9K-1). This turns on the switch's HTTP API so programs can talk to it.
configure terminal feature nxapi nxapi http port 80 end show nxapi
Step 2
اپنے browser میں NX-API developer sandbox کھولیں۔ یہ switch کے اندر بنی ہوئی testing page ہے۔Apne browser mein NX-API developer sandbox kholein. Ye switch ke andar bani hui testing page hai.Open the NX-API developer sandbox in your browser. It is a testing page built into the switch.
🖱️ اپنے browser میں http://<switch-mgmt-ip> کھولیںApne browser mein http://<switch-mgmt-ip> kholeinOpen http://<switch-mgmt-ip> in your browser
Step 3
Sandbox میں 'show version | json' چلائیں۔ Output structured JSON میں آتا ہے — ڈھیلی text کے بجائے keys اور values۔Sandbox mein 'show version | json' chalyein. Output structured JSON mein aata hai — dhili text ke bajaye keys aur values.In the sandbox, run 'show version | json'. The output comes back as structured JSON — keys and values instead of loose text.
Step 4
JSON میں 'host_name' اور 'chassis_id' جیسی keys تلاش کریں۔ Script ان keys کو براہِ راست پڑھ سکتا ہے — نازک text parsing کی ضرورت نہیں۔JSON mein 'host_name' aur 'chassis_id' jaisi keys talash karein. Script in keys ko braah-e-raast parh sakta hai — naazuk text parsing ki zaroorat nahi.Find keys like 'host_name' and 'chassis_id' in the JSON. A script can read these keys directly — no fragile text parsing needed.
Step 5
Ansible agentless ہے: آپ اسے اپنی machine پر install کرتے ہیں، اور یہ SSH پر switches تک پہنچتا ہے۔ Nexus switch پر کوئی agent install نہیں ہوتا۔Ansible agentless hai: aap isay apni machine par install karte hain, aur ye SSH par switches tak pahunchta hai. Nexus switch par koi agent install nahi hota.Ansible is agentless: you install it on your own machine, and it reaches switches over SSH. No agent is installed on the Nexus switch itself.
Step 6
آپ ایک playbook لکھتے ہیں — tasks کی فہرست والی سادہ YAML file۔ ایک playbook بیک وقت دس switches کو ایک جیسا configure کر سکتی ہے۔Aap ek playbook likhte hain — tasks ki fehrist wali saada YAML file. Ek playbook beek waqt das switches ko ek jaisa configure kar sakti hai.You write a playbook — a simple YAML file listing tasks. One playbook can configure ten switches at once, identically.
تصدیقVerifyVerify
Sandbox میں 'show interface mgmt0 | json' چلائیں اور JSON keys سے interface کا IP address لکھیں۔Sandbox mein 'show interface mgmt0 | json' chalyein aur JSON keys se interface ka IP address likhein.In the sandbox, run 'show interface mgmt0 | json' and write down the interface's IP address from the JSON keys.
show nxapi
خرابی دور کرناTroubleshootingTroubleshooting
⚠️ Browser NX-API connection refuse کر رہا ہے۔Browser NX-API connection refuse kar raha hai.The browser refuses the NX-API connection.
✅ کیا 'feature nxapi' enable ہے؟ کیا HTTP port open ہے اور management IP reachable ہے (پہلے ping کریں)؟Kya 'feature nxapi' enable hai? Kya HTTP port open hai aur management IP reachable hai (pehle ping karein)?Is 'feature nxapi' enabled? Is the HTTP port open and the management IP reachable (ping it first)?
⚠️ JSON output سمجھنا مشکل لگ رہا ہے۔JSON output samajhna mushkil lag raha hai.The JSON output is confusing to read.
✅ Command کے آخر میں '| json' لگانا مت بھولیں۔ Keys کھولنے کے لیے sandbox کا formatted view استعمال کریں۔Command ke aakhir mein '| json' lagana mat bhoolein. Keys kholne ke liye sandbox ka formatted view istemal karein.Do not forget '| json' at the end of the command. Use the sandbox's formatted view to expand the keys.
انٹرویو سوالاتInterview Q&AInterview Q&A
❓ NX-API کیا ہے؟NX-API kya hai?What is NX-API?
NX-API Nexus پر HTTP/HTTPS API ہے۔ آپ CLI commands بھیجتے ہیں اور output plain text کے بجائے structured JSON یا XML میں ملتا ہے۔NX-API Nexus par HTTP/HTTPS API hai. Aap CLI commands bhejte hain aur output plain text ke bajaye structured JSON ya XML mein milta hai.NX-API is an HTTP/HTTPS API on Nexus. You send CLI commands and get the output back in structured JSON or XML instead of plain text.
❓ Ansible کو agentless کیوں کہتے ہیں؟Ansible ko agentless kyun kehte hain?Why is Ansible called agentless?
Ansible کو agentless اس لیے کہتے ہیں کیونکہ target device پر کچھ install نہیں کرنا پڑتا — یہ control machine سے SSH (یا NX-API) پر کام کرتا ہے۔Ansible ko agentless is liye kehte hain kyunke target device par kuch install nahi karna parta — ye control machine se SSH (ya NX-API) par kaam karta hai.Ansible is called agentless because nothing needs to be installed on the target device — it works over SSH (or NX-API) from the control machine.