jumpserver api

使用 jumpserver 時,需要用到的 api 指令


curl 版本 add

curl  -s -H 'Authorization: Token xxx' -H "Content-Type:application/json"  -d '{"id": "9f7a3cd5-b3be-4a4f-a7f6-0cbcb8529e71","ip": "192.168.186.66","hostname": "Hadoop_186_66","port": 22,"platform": "Linux","is_active": true,"public_ip": null,"created_by": null,"comment": "","admin_user": "xxx", "nodes": ["26b3113f-9e2c-44a0-aec5-3b852d594571"]}'  'http://jump-2.mlytics.net:3000/api/v1/assets/assets/ '

ansible 版本 add

- name: "register jumpservers list"
  uri:
     url: http://jump-2.mlytics.net:3000/api/v1/assets/assets/
     method: POST
     headers:
        Authorization: "Token xxx"
     body_format: form-urlencoded
     body: 
     - [ id, xxx ]
     - [ ip, "{{ ansible_ssh_host }}" ]
     - [ hostname, "{{ inventory_hostname }}" ]
     - [ port, 20022 ]
     - [ platform, linux ]
     - [ is_active, true ]
     - [ public_ip, null ]
     - [ create_by, null ]
     - [ comment, null ]
     - [ admin_user, xxx ]
     - [ nodes, xxx]
     status_code: "201"
     validate_certs: no
  delegate_to: localhost
  when: env == "prod"

curl 版本 delete

curl   -X DELETE -H 'Authorization: Token xxx' -H "Content-Type:application/json"  'http://jump-2.mlytics.net:3000/api/v1/assets/assets/?hostname=Hadoop_186_66'

ansible 版本 delete

- name: "Delete jumpservers list hosts"
  uri:
     url: "http://jump-2.mlytics.net:3000/api/v1/assets/assets/?hostname={{ inventory_hostname }}"
     method: DELETE
     headers:
        Authorization: "Token xxxx"
     follow_redirects: safe
     return_content: false
     status_code: "204"
     validate_certs: no
  delegate_to: localhost