- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如果 json 键名称中包含破折号,Ansible playbook 将无法工作,如果没有破折号,则可以正常工作。
我尝试使用 from_json 和 json_query,但遇到了同样的问题
这是我必须解析的输出:
ok: [2.2.2.2] => {
"bgp": {
"response": {
"@status": "success",
"result": {
"entry": [
{
"@peer": "V4",
"@vr": "VR",
"ORF-entry-received": "0",
"aggregate-confed-as": "yes",
"config": {
"remove-private-as": "yes"
},
"connect-retry-interval": "15",
"established-counts": "0",
"holdtime": "0",
"holdtime-config": "90",
"idle-hold": "15",
"keepalive": "0",
"keepalive-config": "30",
"last-error": null,
"last-update-age": "634",
"local-address": "3.3.3.3",
"msg-total-in": "0",
"msg-total-out": "0",
"msg-update-in": "0",
"msg-update-out": "0",
"multi-hop-ttl": "1",
"nexthop-peer": "no",
"nexthop-self": "no",
"nexthop-thirdparty": "yes",
"open-delay": "0",
"passive": "no",
"password-set": "no",
"peer-address": "2.2.2.2",
"peer-capability": null,
"peer-group": "PEER_A",
"peer-router-id": "0.0.0.0",
"peering-type": "Unspecified",
"prefix-counter": null,
"prefix-limit": "5000",
"reflector-client": "not-client",
"remote-as": "65000",
"same-confederation": "no",
"status": "Connect",
"status-duration": "0",
"status-flap-counts": "49"
}
]
}
}
}
}
这是我当前的代码(当我添加“对等地址”时出现问题):
- debug:
msg:
peer-address: "{{ item.peer-address }}"
status: "{{ item.status }}"
loop: "{{ (result_3.stdout|from_json).response.result.entry }}"
这是我收到的错误:
{"msg": "The task includes an option with an undefined variable. The error was: 'dict object' has no attribute 'peer'\n\nThe error appears to have been in '/etc/ansible/Playbook-v2.yml': line 49, column 6, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n - debug:\n ^ here\n"}
我只想获取我正在解析的两个键和值:
"peer-address": "2.2.2.2"
"status": "Connect"
最佳答案
这是你的问题:
peer-address: "{{ item.peer-address }}"
名称 peer-address
不是有效的标识符(在 Jinja 语法中,与大多数语言一样,变量名称不能包含 -
)。您可以使用替代语法来引用键:
peer-address: "{{ item['peer-address'] }}"
关于ansible - 如果 json 键名称中包含破折号,则带有 json 循环的 Ansible playbook 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55574776/
我正在尝试使用 Javascript Regex 验证以下格式基本上破折号之前的第一组数字只能是 3 个数字字符。而破折号后面的字符只能是两个或三个数字字符。不允许使用其他字符或空格。 我看过几篇关于
我试图用 gsub 替换我认为是标准的破折号。我正在测试的代码是: gsub("-", "ABC", "reported – estimate") 但是,这没有任何作用。我将破折号复制并粘贴到 htt
我有一个带有可删除行和列的破折号 DataTable 对象。我想根据可见行更新图形。我不确定如何创建回调以及要传递哪些参数。在浏览器中删除行时,存储在表对象中的数据实际上可能不会更改。 from da
我正在尝试为超过一周前的日期着色。但当我这样做时,它会为所有日期着色。 首先我在破折号代码之前尝试过它,它工作得很好 df = pd.DataFrame(list(collection_jobs.fi
我正在尝试匹配 python 中的以下行,但是该行不起作用。 示例文本为: usr/local/java/latest/bin/java-Djava.util.logging.config.file=
我目前正在使用以下 JavaScript 代码: concatedSubstring.replace(/\//g, '-').replace(/[A-Za-z]/g, function(c){
我在 postgreSQL 中使用 regex_replace 并试图去除字符串中不是字母或数字的任何字符。但是,使用此正则表达式: select * from regexp_replace('bli
我正在尝试选择类名中有破折号的对象 - 例如 $("div.nav-next"); 它不起作用 - 似乎破折号是问题所在 - 有什么想法吗?谢谢 最佳答案 试试这个。去掉“div”部分。 $('.na
如何将连字符打印到这样的输出中,例如 344-34-4333。如果这个 ID 是从一个没有连字符的文件中读取的,我怎样才能让它打印 xxx-xx-xxxx 3 to 2 to 4 ? 最佳答案 std
数字小部件可以在同一个仪表板上多次使用吗? 例如我想显示每个团队成员的当前分数,每个团队成员一个带有向上/向下箭头的小部件,将当前分数与最后一个分数进行比较,如果分数上升,则小部件背景为绿色,如果分数
如何在 Linux 中使用命令行将目录名中的空格替换为 -(破折号)? 注意:有数百个目录,每个目录都有子目录。 我尝试了以下命令,但它返回一条消息'call: rename from to file
当我使用 android 虚线时,它在小屏幕上工作正常,但在 Samsung S3 设备和更高版本中不工作。 截图 和 drawable/dashline.xml XML
我正在使用 GNU bash 运行 Windows,版本 4.3.46(2)-release (x86_64-pc-msys) 可重现的例子 我有一个很大的制表符分隔的文本文件,其中有很多行和列。这只
因此,我正在构建一个读取传感器数据并使用 plotly 绘制获取的数据的项目。使用 interval = 1000 效果很好,但 interval = 500 会导致图形变得歇斯底里。 这是我的图表变
我有以下正则表达式,但我希望文本框允许使用破折号 ^[0-9a-zA-Z \/_?:.,\s]+$ 有人知道我该怎么做吗? 最佳答案 破折号必须是字符类中的第一个/最后一个字符,才能按字面使用: ^[
我经常在 PHP MVC 应用程序中看到 Apache RewriteRule,如下所示: RewriteRule ^.*$ - [NC,L] Apache docs for the RewriteR
我在 zsh 脚本中遇到基本名称问题。想象一下 $directory 包含一个带有前导破折号的文件名,在我的例子中它是“-Fast-”。然后脚本执行 folder=$(basename
我需要制作一条在变量后面有破折号的路线。我想要的很容易用代码解释(这是我尝试过的,但它不起作用) Route::any('tournament/{sportName}/{regionName}/{to
我在 zsh 脚本中遇到基本名称问题。想象一下 $directory 包含一个带有前导破折号的文件名,在我的例子中它是“-Fast-”。然后脚本执行 folder=$(basename
简单的说: echo "xxxxx Tyyy zzzzz" | egrep "\byyy\b" (不匹配哪个是正确的) echo "xxxxx T-yyy zzzzz" | egrep "\byyy\
我是一名优秀的程序员,十分优秀!