# Playbook -- How to read a value from another yaml file ?

**URL:** <https://forum.ansible.com/t/playbook-how-to-read-a-value-from-another-yaml-file/16082>\
**Category:** Ansible Project\
**Created:** [August 30, 2014, 6:43am UTC](https://forum.ansible.com/t/playbook-how-to-read-a-value-from-another-yaml-file/16082 "2014-08-30T06:43:19Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Darup\_tek](https://avatars.discourse-cdn.com/v4/letter/d/3d9bf3/32.png) [@Darup\_tek](https://forum.ansible.com/u/Darup_tek)\
**Post date:** [August 30, 2014, 6:43am UTC](https://forum.ansible.com/t/playbook-how-to-read-a-value-from-another-yaml-file/16082/1 "2014-08-30T06:43:19Z")

</div>

I have this playbook which changes the xml file on a remote server.  
This playbook needs to read a value from another yaml file.

For example source yaml file:  
main.yml  
cluster: onecluster

product: someproduct  
…

playbook.yml  
-replace: dest=/a/b/cd.xml regexp=something replace=\<\<\< value of **cluster** from main.yml \>\>\>

The playbook.yml changes the value as per the value from main.yml.  
I cannot not hardcode that in the playbook.yml, all the values should come from central place(main.yml)

Thank you in advance.

---

<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 30, 2014, 7:04pm UTC](https://forum.ansible.com/t/playbook-how-to-read-a-value-from-another-yaml-file/16082/2 "2014-08-30T19:04:50Z")

</div>

I'm not 100% sure if I understand the question, but your inventory can  
associate extra yaml files with all hosts or with groups of hosts. The  
documentation is fairly reasonable:  
[http://docs.ansible.com/intro\_inventory.html](http://docs.ansible.com/intro_inventory.html) (group\_vars are what you  
want, and are discussed at the end)

As an aside, the Ansible convention for global defaults is the "all" group.

---

<div class="post-metadata">

**Author:** ![Darup\_tek](https://avatars.discourse-cdn.com/v4/letter/d/3d9bf3/32.png) [@Darup\_tek](https://forum.ansible.com/u/Darup_tek)\
**Post date:** [August 31, 2014, 6:42am UTC](https://forum.ansible.com/t/playbook-how-to-read-a-value-from-another-yaml-file/16082/3 "2014-08-31T06:42:33Z")

</div>

Thanks, I solved the problem by using extra-vars.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [September 2, 2014, 10:57pm UTC](https://forum.ansible.com/t/playbook-how-to-read-a-value-from-another-yaml-file/16082/4 "2014-09-02T22:57:58Z")

</div>

vars\_files:

- /path/to/foo.yaml

Would be the most idiomatic way to read a YAML file in a playbook.

---

<div class="post-metadata">

**Author:** ![Darup\_tek](https://avatars.discourse-cdn.com/v4/letter/d/3d9bf3/32.png) [@Darup\_tek](https://forum.ansible.com/u/Darup_tek)\
**Post date:** [September 2, 2014, 11:23pm UTC](https://forum.ansible.com/t/playbook-how-to-read-a-value-from-another-yaml-file/16082/5 "2014-09-02T23:23:44Z")

</div>

That makes sense , I can populate the yaml before executing the playbook.  
Thanks for the suggestion.
