Date Time Conversion

Hi All,

I want to convert the below time to human readable format, i tried some of the jinza formatter but it is failing .
Failed
{{ iso_date|iso8601_to_time|datetimeformat(‘%a, %B %d’) }}
requirement 2023-07-20 16:36:44

So i can convert this to <file_name>_2023_07_20_16_36_44 .txt

“created”: “2023-07-20T16:36:44.396234Z”, “modified”: “2023-07-20T16:37:26.400464Z”,

I would use regex_replace instead -

- debug:
msg: '{{ iso_date |regex_replace("(\d{4})\-(\d{2})\-(\d{2})\ (\d{2}):(\d{2}):(\d{2})", "_____.txt") }}'
vars:
iso_date: "2023-07-20 16:36:44"

typed without testing, sorry, give it a go

  • name: create my file
    ansible.builtin.file:
    path: /tmp/{{ now(fmt=“%Y_%m_%d_%H_%M_%S.txt”) }}
    state: touch
      path: /tmp/"{{ now(fmt="%Y_%m_%d_%H_%M_%S.txt") }}"

should be

      path: /tmp/{{ now(fmt="%Y_%m_%d_%H_%M_%S.txt") }}