[NOTE]: This is not like accessing other hosts' yaml data like described here. This is setting my own variable during execution and want to access it later
I am using ansible-playbook
to perform some task on 2 vm pools.
Assume that I have only one host in vms1
pool.
And I try to get the hostname from that system dynamically and I want to reuse the same variable across the other hosts
block in the same file.
I am getting the error saying,
FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'myHostname' is undefined
My playbook yml file looks somewhat like this,
- hosts: vms1
tasks:
- name: Getting file list
shell: ls /my/path/
register: shellOutput
- set_fact:
fileList: "{{ shellOutput.stdout }}"
- hosts: vms2
tasks:
- name: Get file list
shell: "echo {{ fileList }} >> /tmp/hostFileList.txt"