简体   繁体   English

Ansible API playbook查询中关于Pagination的问题

[英]Question about Pagination in Ansible API playbook query

I need to query the REST API Jobs endpoint in Ansible Tower in my playbook.我需要在我的剧本中查询 Ansible Tower 中的 REST API Jobs 端点。

I am using the following to retrieve the data我正在使用以下内容来检索数据

- name: Pull Jobs Data
  uri:
    url: https://ansible.xxxx.com/api/v2/jobs/?format=json&page=1&page_size=200
    headers:
      Content-Type: application/json
      Authorization: "Bearer {{ lookup('env', 'TOWER_PASSWORD') }}"
  register: jobs_data

- name: Get last half hour of data
  debug:
    var: "{{item}}"
  when:
  - item['started'] > current_epoch_half_hour_back
  loop: "{{ jobs_data['json']['results'] }}"

I am only interested in looking at the last half hour of jobs data.我只对查看最近半小时的就业数据感兴趣。

We keep around 2 weeks, which is around 15,000 pages of jobs data and when I use the above page=1 and page_size=200 it seems to starts on page 1 which is the oldest data and only seems to look at the first 200 pages thus missing the latest data entirely.我们保留了大约 2 周,大约有 15,000 页的工作数据,当我使用上面的page=1page_size=200时,它似乎从第 1 页开始,这是最旧的数据,因此似乎只查看前 200 页完全缺少最新数据。 RedHat says you can change the limit by modifying the following file /etc/tower/conf.d/<some file>.py but recommends that you not exceed 200. RedHat 表示可以通过修改以下文件/etc/tower/conf.d/<some file>.py来更改限制,但建议您不要超过 200。

Does anyone know how to get the query to start at the last page (newest data) instead of page 1 (oldest data)?有谁知道如何让查询从最后一页(最新数据)而不是第 1 页(最旧数据)开始?

Don't want to hard code a page= values since I wouldn't know that exact value of the last page.不想对page= values 进行硬编码,因为我不知道最后一页的确切值。

According the documentation about Ansible Tower REST API - Jobs you can just perform a Sorting via ?order_by= and which could be the id , started or other fields documented there.根据有关Ansible Tower REST API - Jobs的文档,您可以通过?order_by=执行排序,这可能是idstarted或那里记录的其他字段。 By doing this you could decrease the result set to a size where is no need for pagination anymore.通过这样做,您可以将结果集减小到不再需要分页的大小。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM