# how to share variables between hosts

**URL:** <https://forum.ansible.com/t/how-to-share-variables-between-hosts/33602>\
**Category:** Ansible Project\
**Created:** [August 13, 2020, 11:49am UTC](https://forum.ansible.com/t/how-to-share-variables-between-hosts/33602 "2020-08-13T11:49:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gabriel\_Sousa](https://avatars.discourse-cdn.com/v4/letter/g/aeb1de/32.png) [@Gabriel\_Sousa](https://forum.ansible.com/u/Gabriel_Sousa)\
**Post date:** [August 13, 2020, 11:49am UTC](https://forum.ansible.com/t/how-to-share-variables-between-hosts/33602/1 "2020-08-13T11:49:54Z")

</div>

i have this:

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [August 13, 2020, 12:05pm UTC](https://forum.ansible.com/t/how-to-share-variables-between-hosts/33602/2 "2020-08-13T12:05:12Z")

</div>

> i have this:
> 
> ---  
> - hosts: all  
> vars:  
> - site: "{{ ansible\_hostname | regex\_replace('^(.{2}).\*' ,'\\1' ) }}"  
> - datavg: DATAVG  
> - datavgpvs: /dev/sdb  
> - lv\_int:  
> - { lv: app, size: "{{appS}}", vg: "{{datavg}}", fs: xfs, mount: "/app" }
> 
> - hosts:  
> - a  
> become: yes  
> become\_method: sudo  
> vars:  
> - appS: 30G
> 
> tasks:  
> - name: Setup datavg LVs  
> lvol: lv={{item.lv}} state=present vg={{datavg}} size={{item.size}}  
> with\_items: "{{ hostvars[all].lv\_inst }}"
> 
> but i have error in hostvars "' 'all' is undefined"

It's unclear why you don't loop over lv\_int:

with\_items: "{{ lv\_int }}"

Otherwise use group variables to share variables between hosts.

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke
