我知道这里已经被问过1000次了,但是我读了很多类似的问题,但仍然没有找到正确的方法。我需要从看起来像这样的一行中提取一个数字:
{"version":"4.9.123M","info":{"version":[2034.2],"description":""},"status":"OK"}
Run Code Online (Sandbox Code Playgroud)
预期产量:
2034.2
Run Code Online (Sandbox Code Playgroud)
该版本号并不总是相同的,但该行的其余部分应该相同。
我曾尝试使用sed,但我对此并不陌生,但失败了:
sed -e 's/version":[\(.*\),"description/\1/'
Run Code Online (Sandbox Code Playgroud)
输出:
sed: -e expression #1, char 35: unterminated `s' command
Run Code Online (Sandbox Code Playgroud)
我认为问题在于该行中包含太多特殊字符,并且我编写的命令不是很好。
我正在尝试为 Ansible 设置动态清单以与 Azure 一起使用,但我收到一些消息,因为 Ansible 无法解析我的 yaml 文件。
到目前为止我做了什么:
创建了 Azure 服务主体并将凭据添加到 /home/user/.azure/credentials (我知道他们建议将它们放在 /home/.azure/credentials 中,我尝试过这样做,但我的 Ansible 似乎在 /home 中查找它们/用户目录。
我将 python 插件(原始的、未经编辑的插件)及其 yaml 配置文件放置在 /etc/ansible/inventory_plugins 中。配置文件如下所示:
plugin: azure_rm
include_vm_resource_groups:
- vm_1197_rg
auth_source: auto
Run Code Online (Sandbox Code Playgroud)
- 使用以下命令测试功能:ansible all -m ping -i ./myazure_rm.yml
输出:
ansible 2.8.1 配置文件 = /etc/ansible/ansible.cfg 配置模块搜索路径 = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules'] ansible python模块位置 = /usr/lib/python2.7/site-packages/ansible 可执行文件位置 = /bin/ansible python 版本 = 2.7.5 (默认,2019 年 4 月 9 日,14:30:50) [GCC 4.8.5 20150623 ( Red Hat 4.8.5-36)] 使用 /etc/ansible/ansible.cfg 作为配置文件 由于清单源不存在或当前用户无法读取而跳过 azure_rm …