# Extends variables in yaml

**URL:** <https://forum.ansible.com/t/extends-variables-in-yaml/16987>\
**Category:** Ansible Project\
**Created:** [December 8, 2014, 5:46pm UTC](https://forum.ansible.com/t/extends-variables-in-yaml/16987 "2014-12-08T17:46:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Micael\_Malta](https://avatars.discourse-cdn.com/v4/letter/m/a88e57/32.png) [@Micael\_Malta](https://forum.ansible.com/u/Micael_Malta)\
**Post date:** [December 8, 2014, 5:46pm UTC](https://forum.ansible.com/t/extends-variables-in-yaml/16987/1 "2014-12-08T17:46:56Z")

</div>

I have a question: How to extends variables:

In group\_vars/all, i have a variable config and i want in host\_vars/my\_server to extend it

How to do that?

---

<div class="post-metadata">

**Author:** ![Toshio\_Kuratomi](https://avatars.discourse-cdn.com/v4/letter/t/41988e/32.png) [@Toshio\_Kuratomi](https://forum.ansible.com/u/Toshio_Kuratomi)\
**Post date:** [December 10, 2014, 3:46pm UTC](https://forum.ansible.com/t/extends-variables-in-yaml/16987/2 "2014-12-10T15:46:57Z")

</div>

Could you give an example of what you want to achieve?I think that would make your question clearer.

Thanks,  
Toshio

---

<div class="post-metadata">

**Author:** ![Mirko\_Friedenhagen](https://avatars.discourse-cdn.com/v4/letter/m/838e76/32.png) [@Mirko\_Friedenhagen](https://forum.ansible.com/u/Mirko_Friedenhagen)\
**Post date:** [December 10, 2014, 5:41pm UTC](https://forum.ansible.com/t/extends-variables-in-yaml/16987/3 "2014-12-10T17:41:03Z")

</div>

What about:

Extending a list? In Python-Syntax  
group\_vars/all.yml: packages = ["a", "b"]  
host\_vars/host1.yml: packages.extend(["c", "d"])

Endresult for packages for host1: ["a", ""b", "c", "d"]

Is this possible in yaml?

Regards Mirko

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [December 10, 2014, 6:06pm UTC](https://forum.ansible.com/t/extends-variables-in-yaml/16987/4 "2014-12-10T18:06:12Z")

</div>

ansible is not a programming language, variables are really pretty  
static, they can be overwritten but not really modified.

If you want to create a new list that has the contents of 2 other  
lists, look at the set theory filters:

with\_items: packages|union(extra\_packages)

that should give you what you want.
