- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试读取其中包含标签 !vault
的 YAML 文件。我收到错误:
could not determine a constructor for the tag '!vault'
看了几个博客,我明白我需要指定一些构造函数来解决这个问题,但我不清楚如何去做。
import yaml
from yaml.loader import SafeLoader
with open('test.yml' ) as stream:
try:
inventory_info = yaml.safe_load(stream)
except yaml.YAMLError as exc:
print(exc)
User = inventory_info['all']['children']['linux']['vars']['user']
key = inventory_info['all']['children']['linux']['vars']['key_file']
我正在使用的 YAML 文件:
all:
children:
rhel:
hosts: 172.18.144.98
centos:
hosts: 172.18.144.98
linux:
children:
rhel:
centos:
vars:
user: "o9ansibleuser"
key_file: "test.pem"
ansible_password: !vault |
$ANSIBLE_VAULT;2.1;AES256
3234567899353936376166353
最佳答案
要么使用from_yaml
实用函数:
from ansible.parsing.utils.yaml import from_yaml
# inventory_info = yaml.safe_load(stream) # Change this
inventory_info = from_yaml(stream) # to this
或者将构造函数添加到yaml.SafeLoader
:
from ansible.parsing.yaml.objects import AnsibleVaultEncryptedUnicode
def construct_vault_encrypted_unicode(loader, node):
value = loader.construct_scalar(node)
return AnsibleVaultEncryptedUnicode(value)
yaml.SafeLoader.add_constructor(u'!vault', construct_vault_encrypted_unicode)
inventory_info = yaml.safe_load(stream)
关于python - PyYAML 错误 : Could not determine a constructor for the tag '!vault' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69817464/
我想在我的 pip 项目中使用 PyYaml,但在将其用作依赖项时遇到了麻烦。主要问题是 pip 中的 PyYaml 不是跨平台安装。 如何使用 pip 安装 pyyaml 以使其正常工作。请注意,在
这个问题在这里已经有了答案: Pip install from pypi works, but from testpypi fails (cannot find requirements) (2 个回
我想用 PyYaml 解释以下 YAML 字符串: - !Table header: - !Column - !Paragrap
yaml.load将数字加载为 Python 浮点数。我找不到一种直接的方法来覆盖它。 比较 json.load , 允许 parse_float=Decimal如果你想将浮点数解析为 decimal
我认为加载 .yml file 时出现内存泄漏使用库 PyYAML。 我已按照以下步骤操作: import yaml d = yaml.load(open(filename, 'r')) 进程使用的内
我需要使用 pyyaml 将 dict 导出到 yaml,不带“-” export_dash_dict = {} export_dash_dict["dashboards"] = []
在下面的代码中,我创建了 net_plan_dict 变量字典并将其转换为 YAML 格式文件。在字典中,我有一个名为 addresses 的字段,它是一个包含三个元素的数组。创建 YAML 文件后,
我构建 libyaml 并将其安装到本地区域: yaml-0.1.5 $ ./configure --prefix=/usr/local/sqlminus yaml-0.1.5 $ make inst
这个问题已经有答案了: New PyYAML version breaks on most custom python objects - RepresenterError (1 个回答) 已关闭 5
我正在尝试理解关于 https://pyyaml.org/wiki/PyYAML 的声明那: PyYAML features - a complete YAML 1.1 parser. In part
看起来好像 PyYAML 将字符串 10:01 解释为以秒为单位的持续时间: import yaml >>> yaml.load("time: 10:01") {'time': 601} 官方文档没有
尝试获取 YAML 文档以解析为我可以操作的 python 字典对象。我安装了 pip install pyyaml。 import yaml yamlstring = "some: var \n a
所以我有一个 yaml 文件,里面有很多琐碎的问题和一个答案列表。但是,每当我尝试加载此文件并使用 pyyaml 将内容转储到 python 中时,它都会向后转储它们。我不确定这是我的 yaml 文件
当用很长的键转储字典时,我得到这样的结果: ? ns=4;s=|var|CODESYS Control for Raspberry Pi SL.Application.GVL.Data.DateTim
我想将一些配置参数从 YAML 直接映射到 Python 参数名称。只是想知道是否有一种方法无需编写额外代码(之后修改键)让 YAML 解析器用下划线“_”替换键中的破折号“-”。 some-para
这个问题在这里已经有了答案: Parsing YAML, return with line number (4 个答案) 关闭 1 年前。 有什么方法可以配置 PyYAML 以便我可以获得与给定节点
我有以下 Python 2.6 程序和 YAML 定义(使用 PyYAML ): import yaml x = yaml.load( """ product:
我有以下 YAML 文件: --- my_vars: my_env: "dev" my_count: 3 当我用 PyYAML 读取它并再次转储它时,我得到以下输出: --- my_vars:
我正在开发一个使用 Unity3D 游戏引擎的项目。对于某些管道要求,最好能够使用 Python 从外部工具更新某些文件。 Unity 的 meta 和 anim 文件在 YAML 中,所以我认为使用
我有一个 python 项目,我想在其中使用 YAML (pyYaml 3.11),特别是因为它“漂亮”并且用户可以在必要时轻松地在文本编辑器中进行编辑。不过,我的问题是,如果我将 YAML 引入 p
我是一名优秀的程序员,十分优秀!