# Access register array defined in one host group from another host group

**URL:** <https://forum.ansible.com/t/access-register-array-defined-in-one-host-group-from-another-host-group/16036>\
**Category:** Ansible Project\
**Created:** [August 26, 2014, 5:35am UTC](https://forum.ansible.com/t/access-register-array-defined-in-one-host-group-from-another-host-group/16036 "2014-08-26T05:35:43Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Imran\_Khan1](https://avatars.discourse-cdn.com/v4/letter/i/a4c791/32.png) [@Imran\_Khan1](https://forum.ansible.com/u/Imran_Khan1)\
**Post date:** [August 26, 2014, 5:35am UTC](https://forum.ansible.com/t/access-register-array-defined-in-one-host-group-from-another-host-group/16036/1 "2014-08-26T05:35:43Z")

</div>

Hello, is it possible to do the following

- hosts: localhost  
gather\_facts: False

tasks:

---

<div class="post-metadata">

**Author:** ![Henry\_Finucane](https://avatars.discourse-cdn.com/v4/letter/h/94ad74/32.png) [@Henry\_Finucane](https://forum.ansible.com/u/Henry_Finucane)\
**Post date:** [August 26, 2014, 5:37am UTC](https://forum.ansible.com/t/access-register-array-defined-in-one-host-group-from-another-host-group/16036/2 "2014-08-26T05:37:26Z")

</div>

Probably something like

hostvars[groups['webservers']|first].new\_ips

---

<div class="post-metadata">

**Author:** ![Imran\_Khan1](https://avatars.discourse-cdn.com/v4/letter/i/a4c791/32.png) [@Imran\_Khan1](https://forum.ansible.com/u/Imran_Khan1)\
**Post date:** [August 26, 2014, 6:02am UTC](https://forum.ansible.com/t/access-register-array-defined-in-one-host-group-from-another-host-group/16036/3 "2014-08-26T06:02:17Z")

</div>

You mean hostvars[groups[‘localhost’]|first.new\_ips  
Doesn’t work!

---

<div class="post-metadata">

**Author:** ![Imran\_Khan1](https://avatars.discourse-cdn.com/v4/letter/i/a4c791/32.png) [@Imran\_Khan1](https://forum.ansible.com/u/Imran_Khan1)\
**Post date:** [August 26, 2014, 6:14am UTC](https://forum.ansible.com/t/access-register-array-defined-in-one-host-group-from-another-host-group/16036/4 "2014-08-26T06:14:53Z")

</div>

{{hostvars[groups[‘localhost’].new\_ips.results.stdout}}  
Gives the following error: One or more undefined variables: ‘dict object’ has no attribute ‘localhost’

---

<div class="post-metadata">

**Author:** ![Henry\_Finucane](https://avatars.discourse-cdn.com/v4/letter/h/94ad74/32.png) [@Henry\_Finucane](https://forum.ansible.com/u/Henry_Finucane)\
**Post date:** [August 26, 2014, 6:27am UTC](https://forum.ansible.com/t/access-register-array-defined-in-one-host-group-from-another-host-group/16036/5 "2014-08-26T06:27:47Z")

</div>

You know what- I answered your title, not your question. If you don't  
want to have to try and persist things between plays, you might have  
more luck with something like this:

- hosts: myhosts  
&nbsp;&nbsp;&nbsp;tasks:  
&nbsp;&nbsp;&nbsp;- shell: echo things  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;local\_action: true  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;register: new\_ips  
&nbsp;&nbsp;&nbsp;- shell: echo other things {{new\_ips}}

but there's nothing in your example that seems to necessitate anything  
that you're doing.

---

<div class="post-metadata">

**Author:** ![Imran\_Khan1](https://avatars.discourse-cdn.com/v4/letter/i/a4c791/32.png) [@Imran\_Khan1](https://forum.ansible.com/u/Imran_Khan1)\
**Post date:** [August 26, 2014, 6:41am UTC](https://forum.ansible.com/t/access-register-array-defined-in-one-host-group-from-another-host-group/16036/6 "2014-08-26T06:41:32Z")

</div>

haha…okay! I did not want to post my whole playbook as it might get confusing. I really do appreciate your help though. Here is a sizeable chunk of the playbook which might make things easy (or difficult) to understand 🙂

#$ cat khan.yml
