Launch task with date in var

Hello,

My playbook allows to create/disable users in the Active Directory,

In my playbook, I’m going to look for my role which will allow me to generate my variables according to a CSV.
In this CSV, I have a start date and an end date of an employee.

I would like to know if it is possible to process the start date and end date variable in order to launch a task at that moment?

I use AWX in parallel to launch my playbook once a day.

Do you have any ideas?

Thank you!

Translated with www.DeepL.com/Translator (free version)

In this CSV, I have a start date and an end date of an employee.
I would like to know if it is possible to process the start date
and end date variable in order to launch a task at that moment?

For example, given the file

cat users.csv

2022-01-01,2023-01-01,admin
2022-01-01,2022-07-12,alice
2022-07-12,2023-01-01,bob

The playbook below

cat pb.yml

- hosts: localhost
  vars:
    date_format: "%Y-%m-%d"
    today: "{{ date_format|strftime }}"
  tasks:
    - community.general.read_csv:
        path: "{{ playbook_dir }}/users.csv"
        fieldnames: start,end,user
      register: users
    - debug:
        msg: "Launch task for user {{ item.user }} end date."
      loop: "{{ users.list }}"
      when: item.end == today
    - debug:
        msg: "Launch task for user {{ item.user }} start date."
      loop: "{{ users.list }}"
      when: item.start == today

gives (abridged)

  msg: Launch task for user alice end date.
  msg: Launch task for user bob start date.

Instead of the condition, use more efficient *selectattr*. The tasks
below give the same result

    - debug:
        msg: "Launch task for user {{ item.user }} end date."
      loop: "{{ users.list|selectattr('end', '==', today) }}"
    - debug:
        msg: "Launch task for user {{ item.user }} start date."
      loop: "{{ users.list|selectattr('start', '==', today) }}"