【问题标题】:ansible problem execut for get vm info in vsphere在 vsphere 中获取 vm 信息的 ansible 问题执行
【发布时间】:2020-10-15 09:40:07
【问题描述】:

我尝试执行这个 ansible yml 文件来获取 vsphere 中的 vm 信息,

我有两个文件:

主机文件:

[Web]
192.168.11.11 #ip of my vsphere server

test.vmware2.yaml 文件:

- name: Gather all registered virtual machines
  community.vmware.vmware_vm_info:
    hostname: '{{ vcenter_hostname }}'
    username: '{{ vcenter_username }}'
    password: '{{ vcenter_password }}'
  delegate_to: localhost
  register: vminfo

我用这个命令执行:

ansible -i /mnt/hosts test.vmware2.yaml

我有这条消息:

ERROR! 'community.vmware.vmware_vm_info' is not a valid attribute for a Play

The error appears to be in '/mnt/test.vmware2.yaml': line 1, column 3, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:


- name: Gather all registered virtual machines
  ^ here

我想知道是什么问题?

感谢您的回复

【问题讨论】:

  • 也许你可以把你使用的ansible版本放在这里? ansible --version
  • 这就是test.vmware2.yaml中的全部内容吗?
  • 我有这个版本的 ansible ansible --version ansible 2.9.6 配置文件 = /etc/ansible/ansible.cfg 配置的模块搜索路径 = ['/home/gthuraisingam/.ansible/plugins/ modules', '/usr/share/ansible/plugins/modules'] ansible python 模块位置 = /usr/lib/python3/dist-packages/ansible 可执行位置 = /usr/bin/ansible python 版本 = 3.8.5(默认,2020 年 7 月 28 日,12:59:40) [GCC 9.3.0]
  • 它就是我在文件 [test.vmware2.yaml] 中的全部内容

标签: python ansible virtual-machine vmware vsphere


【解决方案1】:

我认为你想执行 ansible-playbook:

ansible-playbook -i /mnt/hosts test.vmware2.yaml

那么你的剧本文件应该是这样的:

 - hosts: Web
   gather_facts: false
   become: false
   vars:
      vcenter_hostname: 10.10.10.1
      vcenter_username: user
      vcenter_password: password
   tasks:
     - name: Gather all registered virtual machines
       community.vmware.vmware_vm_info:
         hostname: '{{ vcenter_hostname }}'
         username: '{{ vcenter_username }}'
         password: '{{ vcenter_password }}'
       delegate_to: localhost
       register: vminfo

    - debug:
        msg: "{{ item.guest_name }}, {{ item.ip_address }}"
      with_items:
        - "{{ vminfo.virtual_machines }}"

【讨论】:

  • 我执行了这个,但是我有这个消息:[警告]:无法匹配提供的主机模式,忽略:Web PLAY [Web] *************** ****************************************************** ****************************************************** ****************************************************** ************************ 跳过:没有匹配的主机 PLAY RECAP *************
  • /mnt/hosts 是否包含组 [Web]?您也可以使用localhost 作为主机,因为您将任务委派给localhost
  • 我该如何使用它,我尝试从我的计算机 192.168.10.10 开始执行,我的目标是获取自 vsphere 192.168.11.11 以来的信息
  • 如何ansible-playbook playbook.yml 并将主机从Web 更改为localhost,就像这样- hosts: localhost
  • 我在 fie test.vmware2.yaml 中将 Web 更改为 localhost 但现在我收到此错误消息:TASK [Gather all registered virtual machines] ************* ************************************ 致命:[本地主机]:失败! => {"msg": "该任务包含一个带有未定义变量的选项。错误是:'vcenter_hostname' 未定义\n\n错误似乎在 '/mnt/test.vmware2.yaml':第 5 行,第 8 列,但可能\n位于文件中的其他位置,具体取决于确切的语法问题。\n\n违规行似乎是:\n\n 任务:\n - 名称:收集所有已注册的虚拟机\n ^ 此处\n "}
猜你喜欢
  • 2014-11-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-06-21
  • 1970-01-01
  • 2015-08-11
  • 1970-01-01
  • 2021-11-28
相关资源
最近更新 更多