I have a playbook where I am deploying an instance in aws with the ec2 module. To be more flexible, I ask through a prompt for the hostname. I found in the ec2 examples a code snippet that allows you to run a second play with a newly created instance for further customization.
Now I want to set the host name through the hostname module, but I canβt access the variable in the second play.
Here's what my playbook looks like:
--- - hosts: localhost ... vars_prompt: - name: var_hostname prompt: "Please enter the hostname" private: no tasks: - name: Spin up instance local_action: module: ec2 ... register: ec2 - name: Add new instance to host group add_host: hostname={{ item.public_ip }} groupname=launched with_items: ec2.instances - hosts: launched ... tasks: - name: Set hostname hostname: name="{{ var_hostname }}"
fatal: [launch] => One or more variables undefined: "var_hostname" - undefined
Is there a way to transfer a variable from one play to another?
Have I found Strong best practice for transferring vars to playbooks embedded in it? but, unfortunately, she did not have a solution that I can use.
source share