I am new to ansible and got undefined variable error when try to run below playbook. The task includes an option with an undefined variable. The error was: 'variable' is undefined
---
- name: get time date
hosts: localhost
tasks:
- name: get from system
shell: "date +%Y-%m-%d"
register: dstamp
- name: print date
hosts: IOS
tasks:
- name: print
debug:
msg: "{{dstamp.stdout[0:10]}}"
If I change the host from localhost to IOS, it works. I think it is because variable is bond with each host, since I changed the hosts, I got the error. My question is if it is possible to leave the hosts as localhost and IOS, and still can pass the variable. The scenario is like if the server(localhost) is in Europe and network device(IOS) in US, I would like to keep the date consistent with Europe time.
Thank you in advance.