# How do you register variables from imported playbooks?

**URL:** <https://forum.ansible.com/t/how-do-you-register-variables-from-imported-playbooks/25915>\
**Category:** Ansible Project\
**Created:** [November 3, 2017, 3:37pm UTC](https://forum.ansible.com/t/how-do-you-register-variables-from-imported-playbooks/25915 "2017-11-03T15:37:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ddrake2012](https://avatars.discourse-cdn.com/v4/letter/d/9fc348/32.png) [@ddrake2012](https://forum.ansible.com/u/ddrake2012)\
**Post date:** [November 3, 2017, 3:37pm UTC](https://forum.ansible.com/t/how-do-you-register-variables-from-imported-playbooks/25915/1 "2017-11-03T15:37:19Z")

</div>

Hello,

I’m new to ansible and am trying to use import\_playbook and register but it is not working. I have a playbook called vpc.yml:

- hosts: localhost  
tasks:
- import\_role:  
name: vpc  
vars:  
aws\_region: “{{aws\_region}}”  
register: public\_subnet

within another playbook:

- import\_playbook: vpc.yml

# register: public\_subnet

- hosts: localhost  
connection: local  
gather\_facts: False  
name: set up EC2 instances  
tasks:
- name: Provision a set of instances  
ec2:  
key\_name: AnsibleTest

# group: test

instance\_type: t2.micro  
image: ami-900ae6e8  
wait: true  
exact\_count: “{{ node\_count }}”  
count\_tag:  
Name: Test  
instance\_tags:  
Name: Test  
region: “{{aws\_region}}”  
vpc\_subnet\_id: public\_subnet

register: ec2

If I run the above I get an error saying the subnet ID public\_subnet is undefined, but if I try to change the import\_playbook to user the register: public\_subnet line commented above I get a syntax error.

I understand I could rather easily just use the VPC role in my top level playbook but I’m trying to learn. From what I understand this should be possible, or at least was possible before 2.4. What am I missing here?

Thanks!  
Dave

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [November 8, 2017, 3:12am UTC](https://forum.ansible.com/t/how-do-you-register-variables-from-imported-playbooks/25915/2 "2017-11-08T03:12:51Z")

</div>

You are getting an error because you are passing a string, the  
'register' keyword is 'host specific' since the host in both plays is  
'localhost' it is directly accessible, you should have:

vpc\_subnet\_id: "{{public\_subnet}}"
