On Tue, 12 Jul 2022 00:09:15 -0700 (PDT)
Gabz Modz <[email protected]> wrote:

> 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

shell> 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

shell> 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.

-- 
Vladimir Botka

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/20220712112909.0f48200d%40gmail.com.

Attachment: pgppEc7EGKFzP.pgp
Description: OpenPGP digital signature

Reply via email to