I am working on the restore a DB in AWS RDS using Ansible “rds” module. It worked and I have the DB endpoint “registered” variable rds_instance. This is run on the localhost.
Then I need to provision some AWS EC2 instances and configure them with the DB endpoint. When I referenced it in the second role’s templates as {{ rds_instance.instance.endpoint }}, it says the variable is undefined.
How can I pass the DB endpoint from the first role to the second one?
Thanks,
Philip
In spite of the examples, it looks to me as if there is no “instance” element in the return value from the rds module. I haven’t used it, I’m just reading the doco. Nor does there seem to be an “endpoint” element.
If you use debug to print out your “rds_instance” variable, immediately after using the rds module, you will be able to see the structure within it and identify the right element to use - if what you need exists at all. Or just use “-v” with ansible-playbook.
It helps in such cases to provide the actual error message that you are seeing - we don’t know exactly what Ansible is telling you is undefined. If it is saying that rds_instance itself is undefined, that is a different problem that if it is telling you that there is no “instance” element in it.
It also helps if you provide the code that ansible-playbook is running. Are you running both roles from within one playbook? If so, your registered variable from the first role should certainly be available to the second role. If you are running the second role via second playbook (i.e., a second invocation of ansible-playbook), variables set in the first will no longer exist when you run the second.
Regards, K.