Templating + now()

➜  cat defaults.yml
current: "{{ now('True','%F_%H%M%S') }}"

➜  cat datetime.yml
# make a variable with the current date
- hosts: localhost
  vars_files:
  - ./defaults.yml
  tasks:
  - name: echo
    ansible.builtin.debug:
      var: current

➜  ansible-adhoc ansible-playbook ./datetime.yml
....
TASK [echo]
*************************************************************************************************************
ok: [localhost] => {
    "current": "2023-03-23_110205"
}



On Thu, Mar 23, 2023 at 5:59 AM dulhaver via Ansible Project <
[email protected]> wrote:

> I am trying to define a variable in defaults.yml with some kind of
> dynamic. Conrete creating a directory with the current timestamp at the end
> of the name.
>
>    data_dir: /file/to/dir_$(date +%F_%H%M%S)
>
> gives me exactly the directory name 'dir_$(date +%F_%H%M%S)' and not
> dir_2023_03_23_115122.
>
> How can I achieve such?
>
> --
> 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/403472752.247990.1679565525283%40office.mailbox.org
> .
>

-- 
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/CA%2BrdrUHUasMQ6D_FxuvwbAcMefrZizpZRVbeHzikbcXryxLJKA%40mail.gmail.com.

Reply via email to