I am new to writing Ansible playbooks and have hit a roadblock. I have a list of data in several wrapped form in an api.enter image description here and in each item there is a drop-down list “environments” with several more items enter image description here. and in each of these items there is the data “name” and “publish_date” enter image description here. in the end the construction is like this:
- results
- 0
- 1
- 2
2.environments- 0
- 1
- name: “123”
- publish_date: “4 months ago”
I need to load all names older than a certain date as a list
I tried to do this:
vars:
begin_date: “{{ lookup(‘pipe’, ‘date -d “3 months ago” -I’) }}” #determined the date I needed
tasks:
-
debug:
msg: “{{begin_date}}” -
name: Get all data #display the entire list of API
uri:
url: “127.0.0.1/api”
user: “{{user}}”
password: “{{pass}}”
method: GET
force_basic_auth: yes
status_code: 200
validate_certs: no
register: data
ignore_errors: yes -
name: debug #search and display all data older than 3 months using json_query
debug:
job: “{{ data.json.results | json_query(‘environments[*]’,<3 months)| map(attribute=’name’) | list }}”
register: job -
debug:
msg: “env 3 month before{{job}}”
but when executing the playbook the output is empty
TASK [debug] ****
ok: [mytest] => {
“msg”: “env 3 month before””
please help me understand what I’m doing wrong and where I’m wrong
talion.kel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.