# List in File command ?

**URL:** <https://forum.ansible.com/t/list-in-file-command/11641>\
**Category:** Ansible Project\
**Created:** [July 3, 2012, 9:32am UTC](https://forum.ansible.com/t/list-in-file-command/11641 "2012-07-03T09:32:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ansibleguest](https://avatars.discourse-cdn.com/v4/letter/a/b4bc9f/32.png) [@ansibleguest](https://forum.ansible.com/u/ansibleguest)\
**Post date:** [July 3, 2012, 9:32am UTC](https://forum.ansible.com/t/list-in-file-command/11641/1 "2012-07-03T09:32:00Z")

</div>

To use a list in the file command is not possible ?  
I tried this:

&nbsp;&nbsp;vars:  
&nbsp;&nbsp;&nbsp;&nbsp;user: root  
&nbsp;&nbsp;&nbsp;&nbsp;group: root  
&nbsp;&nbsp;&nbsp;&nbsp;basedir: /opt/basedir  
&nbsp;&nbsp;&nbsp;&nbsp;createdirectories: ["$basedir/test1","$basedir/test2"]

&nbsp;&nbsp;&nbsp;#createdirectories: [{$basedir/test1}, {$basedir/test2}]  
&nbsp;&nbsp;&nbsp;#createdirectories: [$basedir/test1, $basedir/test2]

&nbsp;&nbsp;tasks:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- action: file path=$item state=directory owner=$user group=  
$group  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;with\_items:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- $createdirectories

Expansion seams correct:  
"createdirectories": ["$basedir/test1", "$basedir/test2"],

and got an error like this:

fatal: [10.101.1.102] =\> failed to parse: Traceback (most recent call  
last):  
line 138, in \<module\>  
(k, v) = x.split("=")

---

<div class="post-metadata">

**Author:** ![CWS](https://avatars.discourse-cdn.com/v4/letter/c/e495f1/32.png) [@CWS](https://forum.ansible.com/u/CWS)\
**Post date:** [July 3, 2012, 10:03am UTC](https://forum.ansible.com/t/list-in-file-command/11641/2 "2012-07-03T10:03:47Z")

</div>

Use with\_items, [http://ansible.github.com/playbooks2.html#loop-shorthand](http://ansible.github.com/playbooks2.html#loop-shorthand)

---

<div class="post-metadata">

**Author:** ![ansibleguest](https://avatars.discourse-cdn.com/v4/letter/a/b4bc9f/32.png) [@ansibleguest](https://forum.ansible.com/u/ansibleguest)\
**Post date:** [July 3, 2012, 11:33am UTC](https://forum.ansible.com/t/list-in-file-command/11641/3 "2012-07-03T11:33:55Z")

</div>

Thank you, yes that works of course and that is how it is today.

But i would like to put all these into a variable which comes from an  
external .yml-file.  
This will make the playbook more generic and reusable when the  
uncommon config is stored externally...

---

<div class="post-metadata">

**Author:** ![Daniel\_Hokka\_Zakriss](https://avatars.discourse-cdn.com/v4/letter/d/f05b48/32.png) [@Daniel\_Hokka\_Zakriss](https://forum.ansible.com/u/Daniel_Hokka_Zakriss)\
**Post date:** [July 3, 2012, 12:30pm UTC](https://forum.ansible.com/t/list-in-file-command/11641/4 "2012-07-03T12:30:20Z")

</div>

ansibleguest wrote:

> Thank you, yes that works of course and that is how it is today.
> 
> But i would like to put all these into a variable which comes from an  
> external .yml-file.  
> This will make the playbook more generic and reusable when the  
> uncommon config is stored externally...

with\_items and vars\_files are not friends right now. It's something I've  
been looking at fixing, but I don't think it'll make 0.5.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [July 3, 2012, 12:48pm UTC](https://forum.ansible.com/t/list-in-file-command/11641/5 "2012-07-03T12:48:47Z")

</div>

Yeah, it seems possible to evaluate vars\_files earlier, for vars\_files that do not contain host specific variables.

For vars\_files that DO contain variables though, with\_items can't be friends because task expansion has to happen  
before variable expansion -- every host in a playbook gets the same number of tasks (which also keeps counts from  
getting confusing)

It may be possible to move the looping over with\_items to be an entirely runner thing, in which case that abstraction no  
longer makes multiple tasks, but is ONE task, with an array of returns or something.
