【发布时间】:2022-09-29 10:35:56
【问题描述】:
我有以下在职的Salt状态文件:1)下载图像2)从该图像创建一个容器,3)之后添加一个nic。
这些状态使用以下设置工作:
- 盐SSH:版本 3004
- Python:3.9.7
- LXC(快照):版本 5.0.0
- PyLXD:2.3.0 版
- Linux的:aarch64
---
# Create Penguin Container
#---
get_focal:
lxd_image.present:
- name: \'focal\'
- source:
type: simplestreams
server: https://cloud-images.ubuntu.com/releases
name: \'20.04\'
create_penguin:
lxd_container.present:
- name: penguin
- profiles: [\'default\']
- source: \'focal\'
- running: true
- devices:
### I want to create NIC here. ###
add_nic_card:
cmd.run:
- name: |
lxc config device add penguin eth0 nic nictype=bridged parent=br0
我需要结合状态#2 和#3,以便 nic 与容器同时创建。根据official documentation,这应该是可能的。但是,我无法正确使用语法,错误代码也无济于事。
我尝试了以下多种变体:
变化 1
create_penguin:
lxd_container.present:
- name: penguin
- profiles: [\'default\']
- source: \'focal\'
- running: true
- devices:
eth0: {
type: \"nic\",
nictype: \"bridged\",
parent: \"br0\" }
变体 2
create_penguin:
lxd_container.present:
- name: penguin
- profiles:
- default
- source: \'focal\'
- running: true
- devices:
eth0:
type: nic
nictype: bridged
parent: br0
变体 2 产生以下错误:
----------
ID: create_penguin
Function: lxd_container.present
Name: penguin
Result: False
Comment: An exception occurred in this state: Traceback (most recent call last):
File \"/var/tmp/.ubuntu_a31665_salt/pyall/salt/state.py\", line 2179, in call
ret = self.states[cdata[\"full\"]](
File \"/var/tmp/.ubuntu_a31665_salt/pyall/salt/loader/lazy.py\", line 149, in __call__
return self.loader.run(run_func, *args, **kwargs)
File \"/var/tmp/.ubuntu_a31665_salt/pyall/salt/loader/lazy.py\", line 1201, in run
return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
File \"/var/tmp/.ubuntu_a31665_salt/pyall/salt/loader/lazy.py\", line 1216, in _run_as
return _func_or_method(*args, **kwargs)
File \"/var/tmp/.ubuntu_a31665_salt/pyall/salt/loader/lazy.py\", line 1249, in wrapper
return f(*args, **kwargs)
File \"/var/tmp/.ubuntu_a31665_salt/pyall/salt/states/lxd_container.py\", line 235, in present
__salt__[\"lxd.container_create\"](
File \"/var/tmp/.ubuntu_a31665_salt/pyall/salt/loader/lazy.py\", line 149, in __call__
return self.loader.run(run_func, *args, **kwargs)
File \"/var/tmp/.ubuntu_a31665_salt/pyall/salt/loader/lazy.py\", line 1201, in run
return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
File \"/var/tmp/.ubuntu_a31665_salt/pyall/salt/loader/lazy.py\", line 1216, in _run_as
return _func_or_method(*args, **kwargs)
File \"/var/tmp/.ubuntu_a31665_salt/pyall/salt/modules/lxd.py\", line 691, in container_create
container_device_add(name, dn, **dargs)
File \"/var/tmp/.ubuntu_a31665_salt/pyall/salt/modules/lxd.py\", line 1431, in container_device_add
return _set_property_dict_item(container, \"devices\", device_name, kwargs)
File \"/var/tmp/.ubuntu_a31665_salt/pyall/salt/modules/lxd.py\", line 3544, in _set_property_dict_item
raise SaltInvocationError(\"path must be given as parameter\")
salt.exceptions.SaltInvocationError: path must be given as parameter
Started: 09:43:31.807609
Duration: 5147.141 ms
Changes:
----------
标签: salt-stack lxc lxd