Hard to say why that would fail. I copy-n-pasted your file and it worked
for me, although I named it slightly differently.
For completeness, here's my playbook and file:
[utoddl@tango ansible]$ cat include_vars.yml
---
- name: testing include_vars
hosts: localhost
gather_facts: false
tasks:
- name: include the vars file
ansible.builtin.include_vars:
file: ./include_vars_file.yml
- name: show users
debug:
msg: "{{ users }}"
[utoddl@tango ansible]$ cat include_vars_file.yml
---
# file vars/users.yml
timestamp:
sep2023: 1693864800 # date --date=09/05/2023 +%s
users:
a_user:
name: a_user
passwd: $6$FF.DN/vbue.2i9/vla6h8xpZhx4L/dppBbnnCWN8hZ0
uid: 3007
comment: log receiver
expires: '{{timestamp.sep2023}}'
[utoddl@tango ansible]$ ansible-playbook include_vars.yml -vv
ansible-playbook [core 2.12.9]
[...]
PLAYBOOK: include_vars.yml *****************************************************
1 plays in include_vars.yml
PLAY [testing include_vars] ****************************************************
META: ran handlers
TASK [include the vars file] ***************************************************
task path: /home/utoddl/ansible/include_vars.yml:6
ok: [localhost] => {"ansible_facts": {"timestamp": {"sep2023": 1693864800}, "users": {"a_user": {"comment": "log receiver", "expires": "{{timestamp.sep2023}}",
"name": "a_user", "passwd": "$6$FF.DN/vbue.2i9/vla6h8xpZhx4L/dppBbnnCWN8hZ0", "uid": 3007}}}, "ansible_included_var_files": ["/home/utoddl/ansible/./include_vars_file.yml"],
"changed": false}
TASK [show users] **************************************************************
task path: /home/utoddl/ansible/include_vars.yml:9
ok: [localhost] => {
"msg": {
"a_user": {
"comment": "log receiver",
"expires": "1693864800",
"name": "a_user",
"passwd": "$6$FF.DN/vbue.2i9/vla6h8xpZhx4L/dppBbnnCWN8hZ0",
"uid": 3007
}
}
}
META: ran handlers
META: ran handlers
PLAY RECAP *********************************************************************
localhost : ok=2 changed=0 unreachable=0 failed=0
skipped=0 rescued=0 ignored=0
On 10/25/22 10:58 AM, Jacquelin C wrote:
Hello team,
I would like to use variables in a vars file, like this :
##############
---
# file vars/users.yml
timestamp:
sep2023: 1693864800 # date --date=09/05/2023 +%s
users:
a_user:
name: a_user
passwd: $6$FF.DN/vbue.2i9/vla6h8xpZhx4L/dppBbnnCWN8hZ0
uid: 3007
comment: log receiver
expires: '{{timestamp.sep2023}}'
##############
but when load the file with ansible.builtin.include_vars
I get the error : timestamp' is undefined
How can i do that ?
--
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/d8b1759f-8f14-419b-baf9-d33809283298n%40googlegroups.com
<https://groups.google.com/d/msgid/ansible-project/d8b1759f-8f14-419b-baf9-d33809283298n%40googlegroups.com?utm_medium=email&utm_source=footer>.
--
Todd
--
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/4c0c303e-921e-58e7-0304-dc69541258ac%40gmail.com.