Tuesday, July 12, 2022

How to make API call on NSX-T with ansible

 We will make execute an ansible playbook to get all the NSX-T segments for us



cat /root/ansible/hosts/hostsNsx.ini
[nsxtdev]
NSX-T.abc.com


cat /root/ansible/playbooks/nsx.yaml
- hosts: nsxtdev
  connection: local
  gather_facts: false
  tasks:
  - name: Get all the NSX-T Segments
    uri:
      url: https://NSX-T/policy/api/v1/infra/segments
      force_basic_auth: yes
      validate_certs: no
      headers:
        Accept: "application/json"
        Content-Type: "application/json"
      user: USERNAME
      password: PASSWORD
      method: GET
      status_code: "200"
      body_format: json


ansible-playbook -i /root/ansible/hosts/hostsNsx.ini /root/ansible/playbooks/nsx.yaml -vvvv


to avoid using  -vvvv and to get the only API call result , you can use the following playbook

 
- hosts: nsxtdev
  connection: local
  gather_facts: false
  tasks:
  - name: Get all the NSX-T Segments
    uri:
      url: https://NSX-T/policy/api/v1/infra/segments
      force_basic_auth: yes
      validate_certs: no
      headers:
        Accept: "application/json"
        Content-Type: "application/json"
      user: USERNAME
      password: PASSWORD
      method: GET
      status_code: "200"
      body_format: json
    register: response
  - debug: var=response.json


ansible-playbook -i /root/ansible/hosts/hostsNsx.ini /root/ansible/playbooks/nsx.yaml

No comments:

Post a Comment

NSX-T (local log in) with VIDM integration

We will explain how to log in with a local account to your NSX-T which integrated with VIDM. We integrated our NSX-T into the VIDM. We had a...