managing devices for lxc containers

11 views
Skip to first unread message

Spike

unread,
Mar 13, 2017, 2:41:11 PM3/13/17
to Ansible Project
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}}"
    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

Brian Coca

unread,
Mar 13, 2017, 7:11:39 PM3/13/17
to Ansible Project
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:
- name: c1
devices:
eth0:
name: eth0
type: nic
data:
path: /data
type: disk

-------
Brian Coca
Reply all
Reply to author
Forward
0 new messages