Pass output variable of one role as an input to another role

Hi,

I am having the below ansible script.

While executing the script, I am getting error in the role ‘install-packages’. The error is,

“msg”: "The task includes an option with an undefined variable. The error was: {{ ip }}: ‘ip’ is undefined.

It is looking for ‘ip’ variable inside the role ‘install-packages’,

Please provide your feedback…

You are setting the variable on host local not on host new_vms so the variable ip doesn't exist there.
To access the variable you need to use hostvars and specify which host you like the get the ip variable from.

   {{ hostvars['local'].ip }}