我正在尝试读取包含该标签的 YAML 文件!vault。我收到错误:
无法确定标签“!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']
Run Code Online (Sandbox Code Playgroud)
我正在使用的 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
Run Code Online (Sandbox Code Playgroud) 我有两个数组,我如何获得只出现在第二个数组中而在第一个数组中不可用的元素列表?
数组1=(“A”“B”“C”“D”) 数组2=(“B”“E”“G”)
我需要输出,Array3=("E" "G")因为 Array1 中不存在 E 和 G。我使用了@ephemient @SiegeX 答案,但这并没有返回我需要的东西。
function arraydiff() {
awk 'BEGIN{RS=ORS=" "}
{NR==FNR?a[$0]++:a[$0]--}
END{for(k in a)if(a[k])print k}' <(echo -n "${!1}") <(echo -n "${!2}")
}
Array1=( "A" "B" "C" "D" )
Array2=( "B" "E" "G" )
Array3=($(arraydiff Array1[@] Array2[@]))
Run Code Online (Sandbox Code Playgroud)