首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何使用ansible inventory plugin vmware_vm_inventory解决网络问题?

如何使用ansible inventory plugin vmware_vm_inventory解决网络问题?
EN

Stack Overflow用户
提问于 2021-09-18 15:18:57
回答 1查看 102关注 0票数 1

我使用ansible inventory插件vmware_vm_inventory (参见https://docs.ansible.com/ansible/latest/scenario_guides/vmware_scenarios/vmware_inventory_hostnames.html)。我也想为第一个连接的网络分组。那么什么才是正确的Propertyname呢?

我的vm.vmware.yml

代码语言:javascript
运行
复制
plugin: vmware_vm_inventory
strict: False
hostname: 10.10.10.1
username: user
password: password
validate_certs: False
with_tags: False
hostnames:
  - config.name
properties:
- 'config.name'
- 'config.guestId'
- 'guest.ipAddress'
- 'guest.net'
- 'summary.runtime.powerState'

如果我运行以下命令:

代码语言:javascript
运行
复制
ansible-inventory --host TESTVM001

我得到了:

代码语言:javascript
运行
复制
{
    "ansible_host": "10.20.20.20",
    "config": {
        "guestId": "ubuntu64Guest",
        "name": "TESTVM001"
    },
    "config.guestId": "ubuntu64Guest",
    "config.name": "TESTVM001",
    "guest": {
        "ipAddress": "10.20.20.20",
        "net": [
            {
                "connected": true,
                "deviceConfigId": 4000,
                "dnsConfig": null,
                "ipAddress": [
                    "10.20.20.20",
                    "fe80::333:33ff:aaaa:903f"
                ],
                "ipConfig": {
                    "autoConfigurationEnabled": null,
                    "dhcp": null,
                    "ipAddress": [
                        {
                            "ipAddress": "10.20.20.20",
                            "lifetime": null,
                            "origin": null,
                            "prefixLength": 16,
                            "state": "preferred"
                        },
                        {
                            "ipAddress": "fe80::333:33ff:aaaa:903f",
                            "lifetime": null,
                            "origin": null,
                            "prefixLength": 64,
                            "state": "unknown"
                        }
                    ]
                },
                "macAddress": "00:50:00:ab:cd:ef",
                "netBIOSConfig": null,
                "network": "MYNETWORK"
            }
        ]
    },
    "guest.ipAddress": "10.20.20.20",
    "guest.net": [
        {
            "connected": true,
            "deviceConfigId": 4000,
            "dnsConfig": null,
            "ipAddress": [
                "10.20.20.20",
                "fe80::333:33ff:aaaa:903f"
            ],
            "ipConfig": {
                "autoConfigurationEnabled": null,
                "dhcp": null,
                "ipAddress": [
                    {
                        "ipAddress": "10.20.20.20",
                        "lifetime": null,
                        "origin": null,
                        "prefixLength": 16,
                        "state": "preferred"
                    },
                    {
                        "ipAddress": "fe80::333:33ff:aaaa:903f",
                        "lifetime": null,
                        "origin": null,
                        "prefixLength": 64,
                        "state": "unknown"
                    }
                ]
            },
            "macAddress": "00:50:00:ab:cd:ef",
            "netBIOSConfig": null,
            "network": "MYNETWORK"
        }
    ],
    "runtime": {
        "connectionState": "connected"
    },
    "runtime.connectionState": "connected",
    "summary": {
        "runtime": {
            "powerState": "poweredOn"
        }
    },
    "summary.runtime.powerState": "poweredOn"
}

如何将文件vm.vmware.yml中的- 'guest.net'行更改为仅获取网络名称。

我尝试过的:

- 'guest.net.0.network' - 'guest.net[0].network'

结果是ansible-inventory的帮助输出。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-09-19 14:27:51

我已经找到了。这个提示来自于https://github.com/ansible-collections/community.vmware/issues/902

代码语言:javascript
运行
复制
plugin: vmware_vm_inventory
strict: False
hostname: 10.10.10.1
username: user
password: password
validate_certs: False
with_tags: False
hostnames:
  - config.name
properties:
- 'config.name'
- 'config.guestId'
- 'guest.ipAddress'
- 'guest.net'
- 'summary.runtime.powerState'
compose:
  ansible_host: 'guest.ipAddress'
  ansible_networkname: 'guest.net[0].network'
keyed_groups:
  - key: ansible_networkname
    prefix: "net0"
    seperator: "-"

compose键可以理解jinja2。在https://docs.ansible.com/ansible/latest/collections/community/vmware/vmware_vm_inventory_inventory.html中描述

所以我从ansible-inventory --graph得到的是:

代码语言:javascript
运行
复制
@all:
  |--@ubuntu64Guest:
  |  |--vm1
  |  |--vm2
  |--@net0_NET01:
  |  |--vm1
  |--@net0_NET02:
  |  |--vm2
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69235944

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档