Hi,
I am trying to fetch the json data from ami info in the existing yml using 
ansible.Now i am getting errors regarding json query format in number 
expression.
I need help with proper json query under set fact so that the indentation 
is maintained.Please suggest how this can be achieved.
I am using below code for this :- 
---
- name: List AMI info
  hosts: localhost
  gather_facts: yes
  tasks:
    - name: Gather AMI Info
      amazon.aws.ec2_ami_info:
        owners: self
        region: us-east-1
        filters:
          state: available
      register: result

    - name: Set fact date from last {{ec2_input_day}} days
      run_once: yes
      set_fact:
        ec2_f_date: "{{ lookup('pipe','date \"+%Y-%m-%d\" -d 
\"{{ec2_input_day}} day ago\"') }}"
    - debug:
        var: ec2_f_date

    - name: Set fact date from {{ec2_input_day}} days using amis filters
      run_once: yes
      set_fact:
        ec2_f_amis: "{{ result | json_query(\"item[?creation_date<= \" + 
ec2_f_date + \"]\") }}"
    - debug:
        var: ec2_f_amis
     
PLease feel to run this script.Use this command => 

ansible-playbook <any_file>.yml -e ec2_input_day="'<any number>" 

The output i am getting now is this :-
fatal: [localhost]: FAILED! => {"msg": "JMESPathError in json_query filter 
plugin:\ninvalid token: Parse error at column 22, token \"2022\" (NUMBER), 
for expression:\n\"item[?creation_date<= 2022-06-10]\"\n                   
    ^"}.

Thank you.

 

-- 



_Disclaimer: _© 2022 VVDN Technologies Pvt. Ltd. This e-mail contains 
PRIVILEGED AND CONFIDENTIAL INFORMATION intended solely for the use of the 
addressee(s). If you are not the intended recipient, please notify the 
sender by e-mail and delete the original message. Further, you are not to 
copy, disclose, or distribute this e-mail or its contents to any other 
person and any such actions are unlawful._
_
_
_
__

-- 
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/aafeafa7-c036-48de-ab31-6fd88460afcen%40googlegroups.com.

Reply via email to