Hi Ansible Gurus, specially Dick Visser and vlado and all experts,
I have a question regarding Ansible Integration of REST APIs (built in JAVA). Assume I have 100 of Resource End Point( or Service End point) where each Resource can be updated/read/deleted using CURD operation. Also Each resource has almost 10-15 variables (JSON Req/Resp).
Currently i am using URI module for interacting these webservices but my whole JSON data is stored in raw text file. Any time i want to do any CURD opeation , i update that file and call Ansible task to perform respective CURD operation.
Business demand is : have each REST resource parameters also configurable using ansible (rather than storing in Plain text file). What is the best way of doing this because I have many REST resources and each resource has many params.(as req./resp).
Actually problem is : This Data (Rest Response/Req.) is quite big(present in file) and we want to make each key(variable) of this data in Ansible either using jinja template or anything else.
From your query what I understood was, you’ve have REST API that has n param and you want to handle each API and it’s param as single resource. And if that’s correct, then in that case you can write a module using HTTPAPI as connection plugin handle each of APIs and its resource in particular module.
Hi Sumit,
My requirement is like below:
I have multiple REST end points (Resource END points ) and each one of these has multiple params .
Example:
~/base/endpoint1 - has n params
~/base/endpoint2 - has m params
~/base/endpoint3 - has p params
~/base/endpoint4 - has q params
… and so on .
All of these
On each of these resource , one can perform CURD operations.
Notice implementation of this code is in JAVA.
So once i automate using Ansible , I use Ansible URI module and POST all data using a .json file ( which has all cumulative data of all resources i.e endpoint1+endpoint2+…)as below:
name: application provisionning
uri:
url: http://{{ IP | default(ansible_fqdn) }}:8080/myapp/base
body_format: json
method: POST
body: “{{ lookup(‘file’,app_provisioning_filepath) | from_json}}”
user: “{{ restapi_user }}”
password: “{{ restapi_password }}”
force_basic_auth: true
Now my requirment is :
End user wants that each of these parameters whatever u store in (.json file) should be ansible format (e.g .yaml format).
So that whole ansible code looks in .yaml and no .json etc.
Now our REST API can produce/consume only JSON media type as per implementation.
How i can make all these params( which is stored in .json file) into ansible or yaml format.
THanks Sumit ,
So I can convert whole .yaml file( Which contains all REST data) to .json file (which will contain json data).
Can you give snippet of code for yaml file to json file conversion