# managing devices for lxc containers

**URL:** <https://forum.ansible.com/t/managing-devices-for-lxc-containers/23955>\
**Category:** Ansible Project\
**Created:** [March 13, 2017, 6:40pm UTC](https://forum.ansible.com/t/managing-devices-for-lxc-containers/23955 "2017-03-13T18:40:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Spike1](https://avatars.discourse-cdn.com/v4/letter/s/b5a626/32.png) [@Spike1](https://forum.ansible.com/u/Spike1)\
**Post date:** [March 13, 2017, 6:40pm UTC](https://forum.ansible.com/t/managing-devices-for-lxc-containers/23955/1 "2017-03-13T18:40:46Z")

</div>

Hi,

is there a way to add more than one device to a container from a variable?

I’d like to have something like this defined:

lxc\_containers:

- name: c1  
devices:
- name: eth0  
type: nic  
…
- name: data  
type: disk  
…

and then have a task like:

- name: create containers  
lxd\_container:  
name: “{{[item.name](http://item.name)}}”  
state: started  
…  
devices: “{{item.devices}}”  
…  
with\_items: “{{lxd\_containers}”"

right now this seems impossible as you have to spell out in the task each device. Am I misunderstanding the module? is there a way around it?

thanks,

Spike

---

<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:** [March 13, 2017, 11:11pm UTC](https://forum.ansible.com/t/managing-devices-for-lxc-containers/23955/2 "2017-03-13T23:11:33Z")

</div>

That looks like it should work, {{item.devices}} should be expanded  
before the module reads it, and that is already a list,

Though, looking at the code definition of the module, it seems wrong  
and it takes a dictionary, not a list. Seem to need a 'dictionary of  
device type with a list of devices'. Looks like the following should  
work:

lxc\_containers:  
&nbsp;&nbsp;- name: c1  
&nbsp;&nbsp;&nbsp;&nbsp;devices:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;eth0:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;name: eth0  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;type: nic  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;data:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;path: /data  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;type: disk
