I am able to get the output.json to display but looking only to display the 
record type and priority from the json file then take that output to a 
variable in the playbook. 

On Monday, March 27, 2023 at 2:50:56 PM UTC-5 JJ wrote:

> Hope this helps
>
> server]$ ansible-playbook test-json-output.yml
> [WARNING]: provided hosts list is empty, only localhost is available. Note 
> that the implicit localhost does not match 'all'
>
> PLAY [Ansible connection] 
> ************************************************************************************************************************************************************************************
>
> TASK [Gathering Facts] 
> ***************************************************************************************************************************************************************************************
> ok: [localhost]
>
> PLAY [Read local Mailgun JSON file] 
> **************************************************************************************************************************************************************************
>
> TASK [Gathering Facts] 
> ***************************************************************************************************************************************************************************************
> ok: [localhost]
>
> TASK [Create dictionary] 
> *************************************************************************************************************************************************************************************
> ok: [localhost]
>
> TASK [Print variable JSON data] 
> ******************************************************************************************************************************************************************************
> ok: [localhost] => {
>     "jsondata": {
>         
>        },
>         "receiving_dns_records": [
>             {
>                 "cached": [],
>                 "priority": "10",
>                 "record_type": "MX",
>                 "valid": "unknown",
>                 "value": "mxa.mailgun.org"
>             },
>             
>
> TASK [Output specific JSON data] 
> *****************************************************************************************************************************************************************************
> fatal: [localhost]: FAILED! => {"msg": "Error in jmespath.search in 
> json_query filter plugin:\n'dict object' has no attribute '
>
> On Monday, March 27, 2023 at 12:45:03 PM UTC-5 JJ wrote:
>
>> I am new to Anisble and I have been trying to get Anisble to take the 
>> output of a local json file and read it, store the information and then 
>> output the data. I think I was successful because it does output the data 
>> in the file. What I am having trouble with is getting just a specific piece 
>> of data to display so I know Anisble is parsing the right section of the 
>> json file so I can pass it to a variable in the playbook. I feel I have 
>> tried almost everything but with no success.
>>
>> JSON EXAMPLE
>> }, "receiving_dns_records": [ { "cached": [], "priority": "10", 
>> "record_type": "MX", "valid": "unknown", "value": "mxa.domain.org" }, 
>>
>> Playbook:
>>
>> ---
>> - name: Ansible connection 
>>   hosts: localhost        
>>   connection: local 
>>
>> - name: Read local JSON file
>>   hosts: localhost
>>   vars:
>>     jsondata: "{{ lookup('file', '/home/name/appdir/output.json') | 
>> from_json }}"
>>   
>>   tasks:
>>     - name: Create dictionary 
>>       set_fact: 
>>         jsondata: "{{ jsondata }}"
>>
>>     
>>     - name: Print variable JSON data
>>       debug:
>>         var: jsondata
>>                
>>
>>
>>     - name: Output specific JSON data 
>>       debug: 
>>         msg: "this is where I get lost I have tried JMES Query and Debug 
>> MSG but every example I see fails"
>>
>

-- 
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/a2ace255-11c1-4b59-af5b-b5ec4240d9a4n%40googlegroups.com.

Reply via email to