Is there a way to get job running Start/Finish time from tower .

42 views
Skip to first unread message

javed khan Siddque

unread,
Jul 24, 2023, 10:21:07 AM7/24/23
to Ansible Project

Hi All

Is there a way to get job running Start/Finish time from tower .


Message has been deleted

javed khan Siddque

unread,
Jul 24, 2023, 10:23:20 AM7/24/23
to Ansible Project
MicrosoftTeams-image (5).png

javed khan Siddque

unread,
Jul 26, 2023, 8:07:02 AM7/26/23
to Ansible Project
- name: "[TIME-FETCH] Daily Health Check"
  hosts: localhost
  gather_facts: true
  tasks:
    - name: "Debug Current Job ID -> tower_job_id"
      ansible.builtin.debug:
        msg: "{{ tower_job_id }}"


    - name: "Provide Token Details Before Fetching Job Details[Required Variable]"
      ansible.builtin.set_fact:
        token: "SHQ0ywkHOnQy2kvE0O28VGo"


    - name: "Fetch Current Job Details To Get Job Start Time"
      ansible.builtin.uri:
        url: "https://{{ tower_host }}/api/v2/jobs/{{ tower_job_id }}"
        method: GET
        validate_certs: false
        return_content: true
        status_code:
          - 201
          - 200
        headers:
          Authorization: "Bearer {{ token }}"
          Content-Type: "application/json"
      register: job_details


    - name: "Fetch Start Time(request_date) From job_details in ISO-806 Format"
      ansible.builtin.set_fact:
        fetched_date: "{{ job_details.json.started }}"  # 2023-07-20T16:36:44.396234Z


    - name: "Reformat Start Time(fetched_date) To Proper Date Format"
      ansible.builtin.set_stats:
        data:
          job_started_date_kp_to_kyndryl: "{{ fetched_date.split('.')[0].split('T')[0].split('-') | join('_') + '_' + fetched_date.split('.')[0].split('T')[1].split(':') | join('_') }}"
        # 2023_07_20_16_36_44
Reply all
Reply to author
Forward
0 new messages