Hi Rahul, If you just want to convert .json data to .yaml data then you can use the `to_yaml` filter, ref: https://docs.ansible.com/ansible/latest/user_guide/playbooks_filters.html#filters-for-formatting-data
*Regards,* Sumit Jaiswal Github/IRC: *justjais* On Tue, Nov 12, 2019 at 6:37 PM Rahul Kumar <[email protected]> wrote: > 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. > > On Tue, 12 Nov 2019 at 18:12, Sumit Jaiswal <[email protected]> wrote: > >> Hi Rahul, >> >> 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. >> >> Please refer: >> https://docs.ansible.com/ansible/latest/plugins/httpapi.html and >> https://docs.ansible.com/ansible/latest/plugins/connection/httpapi.html, >> this will guide you through the use of HTTPAPI plugin and platforms which >> have already implemented their REST APIs using the plugin. >> >> >> *Regards,* >> Sumit Jaiswal >> Github/IRC: *justjais* >> >> On 12-Nov-2019, at 4:11 PM, Rahul Kumar <[email protected]> wrote: >> >> Hi dick and all, >> Any suggestion on this ?? >> >> @ Dick >> NO ,the uri module does not accept an ansible native format (i.e. YAML >> list) for the body parameters: >> >> On Tue, 5 Nov 2019 at 15:56, Rahul Kumar <[email protected]> wrote: >> >>> Hi Dick , >>> Any suggestion on above query? >>> >>> Rahul >>> >>> On Mon, 16 Sep 2019 at 17:58, Rahul Kumar <[email protected]> >>> wrote: >>> >>>> Thanks Dick! Below is the task: >>>> >>>> - name: application provisionning >>>> uri: >>>> url: http://{{ IP | default(ansible_fqdn) }}:8080/my-config/rest >>>> body_format: json >>>> method: PUT >>>> body: "{{ lookup('file',app_provisioning_filepath) | from_json}}" >>>> user: "{{ restapi_user }}" >>>> password: "{{ restapi_password }}" >>>> force_basic_auth: true >>>> >>>> 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. >>>> >>>> Rahul >>>> >>>> On Mon, 16 Sep 2019 at 15:24, Dick Visser <[email protected]> >>>> wrote: >>>> >>>>> Hi >>>>> >>>>> What do your tasks look like? >>>>> In any case, the uri module accept an ansible native format (i.e. YAML >>>>> list) for the body parameters: >>>>> https://docs.ansible.com/ansible/latest/modules/uri_module.html. >>>>> So just use that instead of an external JSON file. >>>>> >>>>> >>>>> BTW, keywords like "urgent" tend to not work very well in community >>>>> driven support fora. >>>>> >>>>> >>>>> Dick >>>>> >>>>> On Mon, 16 Sep 2019 at 09:30, Rahul Kumar <[email protected]> >>>>> wrote: >>>>> > >>>>> > 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). >>>>> > >>>>> > >>>>> > Waiting for urgent response and best solution. >>>>> > >>>>> > Thanks and Regards >>>>> > Rahul >>>>> > >>>>> > -- >>>>> > You received this message because you are subscribed to the Google >>>>> Groups "Ansible Project" group. >>>>> > To unsubscribe from this group and stop receiving emails from it, >>>>> send an email to [email protected]. >>>>> > To view this discussion on the web visit >>>>> https://groups.google.com/d/msgid/ansible-project/CAGH8rEyBfToefFAT0KxMxEiLt_e%2BsujNnQ0snBUFbqPAZPn62w%40mail.gmail.com >>>>> . >>>>> >>>>> >>>>> >>>>> -- >>>>> Dick Visser >>>>> Trust & Identity Service Operations Manager >>>>> GÉANT >>>>> >>>>> -- >>>>> You received this message because you are subscribed to the Google >>>>> Groups "Ansible Project" group. >>>>> To unsubscribe from this group and stop receiving emails from it, send >>>>> an email to [email protected]. >>>>> To view this discussion on the web visit >>>>> https://groups.google.com/d/msgid/ansible-project/CAL8fbwNvpH4Aj%2B4nh08V1icEmk0Zg42GCKabzzFiwcXKyEij-g%40mail.gmail.com >>>>> . >>>>> >>>> >> -- >> You received this message because you are subscribed to the Google Groups >> "Ansible Project" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected]. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/ansible-project/CAGH8rEwDUPbTMhp9ff2WAFzGhJTEj0xbPY7Ccqs0%2Bh4aOUSRZg%40mail.gmail.com >> <https://groups.google.com/d/msgid/ansible-project/CAGH8rEwDUPbTMhp9ff2WAFzGhJTEj0xbPY7Ccqs0%2Bh4aOUSRZg%40mail.gmail.com?utm_medium=email&utm_source=footer> >> . >> >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Ansible Project" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected]. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/ansible-project/26E772D0-AEFD-4257-BA39-14446F4AAED9%40redhat.com >> <https://groups.google.com/d/msgid/ansible-project/26E772D0-AEFD-4257-BA39-14446F4AAED9%40redhat.com?utm_medium=email&utm_source=footer> >> . >> > -- > You received this message because you are subscribed to the Google Groups > "Ansible Project" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/ansible-project/CAGH8rEzKefjq9xg%3DqXfdO-yANefkWxMu2yRQ-FpZjHG%3DZBLnwQ%40mail.gmail.com > <https://groups.google.com/d/msgid/ansible-project/CAGH8rEzKefjq9xg%3DqXfdO-yANefkWxMu2yRQ-FpZjHG%3DZBLnwQ%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAOUugfnxt8rQ0si-if%2BV87se7prFm3JK4ySEc9xZGriWzZukDw%40mail.gmail.com.
