# refactor help needed

**URL:** <https://forum.ansible.com/t/refactor-help-needed/14126>\
**Category:** Ansible Project\
**Created:** [December 11, 2013, 4:07pm UTC](https://forum.ansible.com/t/refactor-help-needed/14126 "2013-12-11T16:07:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_Baydoun](https://avatars.discourse-cdn.com/v4/letter/m/aeb1de/32.png) [@Michael\_Baydoun](https://forum.ansible.com/u/Michael_Baydoun)\
**Post date:** [December 11, 2013, 4:07pm UTC](https://forum.ansible.com/t/refactor-help-needed/14126/1 "2013-12-11T16:07:24Z")

</div>

Can the following be refactored so the following array only appears once in the code?

- [‘/home/youruser/a’, ‘/home/youruser/b’, ‘/home/youruser/c’, ‘/home/youruser/d’]

---

<div class="post-metadata">

**Author:** ![David\_Karban](https://avatars.discourse-cdn.com/v4/letter/d/90db22/32.png) [@David\_Karban](https://forum.ansible.com/u/David_Karban)\
**Post date:** [December 11, 2013, 4:53pm UTC](https://forum.ansible.com/t/refactor-help-needed/14126/2 "2013-12-11T16:53:44Z")

</div>

Hi,

either define variable on the beggining of the play like here:  
[http://www.ansibleworks.com/docs/playbooks\_variables.html#variables-defined-in-a-playbook](http://www.ansibleworks.com/docs/playbooks_variables.html#variables-defined-in-a-playbook)

or, better use group vars, or host vars:  
[http://www.ansibleworks.com/docs/playbooks\_best\_practices.html#group-and-host-variables](http://www.ansibleworks.com/docs/playbooks_best_practices.html#group-and-host-variables)

David

---

<div class="post-metadata">

**Author:** ![Michael\_Baydoun](https://avatars.discourse-cdn.com/v4/letter/m/aeb1de/32.png) [@Michael\_Baydoun](https://forum.ansible.com/u/Michael_Baydoun)\
**Post date:** [December 11, 2013, 5:38pm UTC](https://forum.ansible.com/t/refactor-help-needed/14126/3 "2013-12-11T17:38:42Z")

</div>

I previous tried to define the array at the begining of the playbook in the vars section, but it only accepts key/value pairs, not an array. Maybe my syntax was incorrect. Is there an example of an array being defined in the vars section somewhere?

---

<div class="post-metadata">

**Author:** ![willthames](https://avatars.discourse-cdn.com/v4/letter/w/8dc957/32.png) [@willthames](https://forum.ansible.com/u/willthames)\
**Post date:** [December 19, 2013, 12:08am UTC](https://forum.ansible.com/t/refactor-help-needed/14126/4 "2013-12-19T00:08:58Z")

</div>

There are (at least) two ways to do it that both seem to work as expected:

[will@tangerine test]$ cat var\_array.yml
