On Tue, 12 Jul 2022 00:09:15 -0700 (PDT)
Gabz Modz <
gabz...@gmail.com> 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