Skip to content

Commit 2ba01b0

Browse files
authored
Making timestamp processing consistent to avoid timestamp format issues (#95)
1 parent 6ece51e commit 2ba01b0

File tree

3 files changed

+28
-13
lines changed

3 files changed

+28
-13
lines changed

inventory-generation/notifications/main.yaml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020
path: "{{ directory }}/iac/inventories/notifications/inventory/group_vars/all"
2121
register: notifications_dir
2222

23+
- name: "Pre-process timestamps"
24+
set_fact:
25+
- archive_date_in_seconds: "{{ (archive_date | default('2000-01-01T') | regex_replace('^(.*)T.*$', '\\1') | to_datetime('%Y-%m-%d')).strftime('%s') }}"
26+
- time_now_in_seconds: "{{ now(utc=true, fmt='%s') }}"
27+
2328
- name: "Copy email templates from main repo to engagement repo - if the target directory does NOT already exist"
2429
block:
2530
- name: "Add directory for group_vars/all"
@@ -56,7 +61,7 @@
5661
- start_date is defined
5762
- engagement_type | default('') == 'Residency' or engagement_type | default('') == 'DO500'
5863
- (hosting_environments is defined) and (hosting_environments | length > 0)
59-
- (archive_date | default('2006-01-02T15:04:05Z') | to_datetime('%Y-%m-%dT%H:%M:%SZ')).strftime('%s') > now(utc=true).strftime('%s')
64+
- archive_date_in_seconds > time_now_in_seconds
6065
- hosting_environments[0].ocp_sub_domain is defined
6166
- ocp_base_url is defined
6267

@@ -68,4 +73,4 @@
6873
- start_date is defined
6974
- engagement_type | default('') == 'Residency' or engagement_type | default('') == 'DO500'
7075
- (hosting_environments is defined) and (hosting_environments | length > 0)
71-
- (archive_date | default('2006-01-02T15:04:05Z') | to_datetime('%Y-%m-%dT%H:%M:%SZ')).strftime('%s') > now(utc=true).strftime('%s')
76+
- archive_date_in_seconds > time_now_in_seconds

inventory-generation/tower_jobs_launch/main.yaml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,20 @@
77
when:
88
- directory is undefined or (directory | trim) == ""
99

10-
- name: Read Engagement Data
10+
- name: 'Read Engagement Data'
1111
include_vars:
1212
file: '{{ directory }}/engagement.json'
1313

14-
- name: Set customer engagement
14+
- name: 'Set customer engagement'
1515
set_fact:
1616
customer_engagement: "{{ customer_name | lower | replace(' ', '_') }}-{{ project_name | lower | replace(' ', '_') }}"
1717

18-
- name: Set facts to bootstrap scheduled notifications into Ansible Tower
18+
- name: 'Pre-process timestamps'
19+
set_fact:
20+
- archive_date_in_seconds: "{{ (archive_date | default('2000-01-01T') | regex_replace('^(.*)T.*$', '\\1') | to_datetime('%Y-%m-%d')).strftime('%s') }}"
21+
- time_now_in_seconds: "{{ now(utc=true, fmt='%s') }}"
22+
23+
- name: 'Set facts to bootstrap scheduled notifications into Ansible Tower'
1924
set_fact:
2025
delete_missing_items: false
2126
ansible_tower:
@@ -85,6 +90,6 @@
8590
- start_date is defined
8691
- (hosting_environments is defined) and (hosting_environments | length > 0)
8792
- engagement_type | default('') == 'Residency' or engagement_type | default('') == 'DO500'
88-
- (archive_date | default('2006-01-02T15:04:05Z') | to_datetime('%Y-%m-%dT%H:%M:%SZ')).strftime('%s') > now(utc=true).strftime('%s')
93+
- archive_date_in_seconds > time_now_in_seconds
8994

9095
- import_playbook: '{{ infra_ansible_directory }}/playbooks/ansible/tower/configure-ansible-tower.yml'

inventory-generation/tower_jobs_schedules/main.yaml

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,21 @@
99
when:
1010
- directory is undefined or (directory | trim) == ""
1111

12-
- name: Read Engagement Data
12+
- name: 'Read Engagement Data'
1313
include_vars:
1414
file: "{{ directory }}/engagement.json"
1515

16-
- name: Combine customer and engagement name
16+
- name: 'Combine customer and engagement name'
1717
set_fact:
1818
customer_engagement: "{{ customer_name | lower | replace(' ', '_') }}-{{ project_name | lower | replace(' ', '_') }}"
1919

20-
- name: Residency Engagement Type inventory
21-
block:
20+
- name: 'Pre-process timestamps'
21+
set_fact:
22+
- archive_date_in_seconds: "{{ (archive_date | default('2000-01-01T') | regex_replace('^(.*)T.*$', '\\1') | to_datetime('%Y-%m-%d')).strftime('%s') }}"
23+
- time_now_in_seconds: "{{ now(utc=true, fmt='%s') }}"
24+
25+
- name: 'Residency Engagement Type inventory'
26+
block:`
2227
- name: "Write inventory to file"
2328
template:
2429
src: "residency-tower-management-host.yaml.j2"
@@ -31,9 +36,9 @@
3136
when:
3237
- start_date is defined
3338
- engagement_type | default('') == 'Residency'
34-
- (archive_date | default('2006-01-02T15:04:05Z') | to_datetime('%Y-%m-%dT%H:%M:%SZ')).strftime('%s') > now(utc=true).strftime('%s')
39+
- archive_date_in_seconds > time_now_in_seconds
3540

36-
- name: DO500 Engagement Type inventory
41+
- name: 'DO500 Engagement Type inventory'
3742
block:
3843
- name: "Write inventory to file"
3944
template:
@@ -47,4 +52,4 @@
4752
when:
4853
- start_date is defined
4954
- engagement_type | default('') == 'DO500'
50-
- (archive_date | default('2006-01-02T15:04:05Z') | to_datetime('%Y-%m-%dT%H:%M:%SZ')).strftime('%s') > now(utc=true).strftime('%s')
55+
- archive_date_in_seconds > time_now_in_seconds

0 commit comments

Comments
 (0)