Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ansible: The task includes an option with an undefined variable. The error was: 'variable' is undefined

Tags:

ansible

I am writing ansible playbook, and set the below variable :

default_tz: 'ZONE="America/Los_Angeles"'

I am trying to add the above variable to a file, by using the below code On the same playbook:

- name: configure time zone
  lineinfile:
   line: "{{ default_tz }}"
   dest: "/etc/sysconfig/clock"

I am getting the below error while running the playbook:

"The task includes an option with an undefined variable. The error was: 'default_tz' is undefined\
like image 648
askpython Avatar asked Oct 27 '25 23:10

askpython


1 Answers

You should declare variable in the scope of variables. Like this:

vars: default_tz: 'ZONE="America/Los_Angeles"'

https://docs.ansible.com/ansible/latest/user_guide/playbooks_variables.html#defining-variables-in-a-playbook

like image 84
yehudkob Avatar answered Oct 29 '25 14:10

yehudkob



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!