chore(ansible): compare time

This commit is contained in:
Michele Cereda
2024-12-10 02:41:54 +01:00
parent 9665eb611f
commit ebb6282833

View File

@@ -835,6 +835,10 @@
state: touch state: touch
mode: '0755' mode: '0755'
with_dict: "{{ users_info }}" with_dict: "{{ users_info }}"
- name: Compare time
# https://docs.ansible.com/ansible/latest/collections/ansible/builtin/to_datetime_filter.html
# https://docs.python.org/3/library/datetime.html#strftime-and-strptime-behavior
block: []
- name: AWS-specific operations - name: AWS-specific operations
tags: never tags: never
@@ -898,6 +902,31 @@
resource: i-xyzxyz01 resource: i-xyzxyz01
tags: tags:
MyNewTag: value MyNewTag: value
- name: Test the remaining time for role assumption is > 5m
# https://docs.ansible.com/ansible/latest/collections/ansible/builtin/to_datetime_filter.html
# https://docs.python.org/3/library/datetime.html#strftime-and-strptime-behavior
ansible.builtin.debug:
msg: >-
{{
dict([
[
'assumed_role.sts_creds.expiration',
assumed_role.sts_creds.expiration | to_datetime('%Y-%m-%dT%H:%M:%S+00:00')
],
[ 'now()', now() ],
[
'assumed_role.sts_creds.expiration - now()',
assumed_role.sts_creds.expiration | to_datetime('%Y-%m-%dT%H:%M:%S+00:00') - now()
],
[
'condition',
(
assumed_role.sts_creds.expiration
| to_datetime('%Y-%m-%dT%H:%M:%S+00:00') - now()
).total_seconds() > 300
],
])
}}
- name: Update the play's inventory with a newly started instance - name: Update the play's inventory with a newly started instance
tags: tags:
- update_inventory - update_inventory