Thanks Nick,  
That worked great to give me back the value itself.

On Tuesday, September 24, 2019 at 2:10:46 PM UTC-5, Nick Schendel wrote:
>
> I am working on some playbooks right now using the URI module and doing 
> what you describe. If you register the output of the task, you can call the 
> response contents with output.json.keyname.  Where output is the name you 
> used in the register. So as an example:
>
>   - name: get some value via URI call
>     uri:
>         url: https://{{ server_hostname }}/api/somepath
>     register: uri_output
>
> Now in later plays you can use uri_output.json.keyx, or uri_output.somekey 
> for values returned in the response body itself.  Some of the stuff I am 
> doing will return a json aray, and for those I am using 
> uri_output.json.data[0].key to get at what I need.  Now I just need to 
> figure out how to query the returned array to match a particular value.
>
> I was also able to set a specific value to a variable with set_fact:
>
>     - name: set variable for target_vm_id
>     set_fact:
>       target_vm_id: "{{ vminfo.json.data[0].id }}"
>
>
> On Tuesday, September 24, 2019 at 1:25:45 PM UTC-5, Paul Hoffman wrote:
>>
>> I'd like to leverage systems with an API to provide variables to 
>> playbooks running on the controller.
>> Something similar to a dynamic inventory script loading from an external 
>> system.
>>
>> For example with a curl command and can get the exact contents I need.  
>> IE: {"myVariable":"myValue"}  or yaml format:
>> myVariable: myValue
>>
>> I've looked at the uri module and it looks promising.  The values 
>> returned by the GET call are embedded in the 
>> returned contents along with many other API variables.
>>
>> The idea being when I need a value that changes frequently or shouldn't 
>> be included in static playbooks I call the 
>> external system that has the master value and load it.
>> I'd prefer not pulling the data into a variable file first.  That would 
>> avoid file management issues.
>>
>> I'm not too familiar with jinja2 but perhaps there's a way to take the 
>> output from URI and parse out the values.
>> I'm sure there is a way to do this that I haven't come across yet.
>>
>> If anyone has already solved this point me in the right direction.
>> v/r
>>
>>

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/436f2df8-4761-4316-b67c-70bf10bcf445%40googlegroups.com.

Reply via email to