如何在带有ansible的esxi中使用vim-cmd命令

问题描述

我没有 vCenter,只有 esxi 主机

而且我不使用任何 ansible 库存,我更喜欢 add_host 风格 如下图

- name: Set inventory from parameter
  gather_facts: no
  hosts: localhost
  tasks:
  - name: Set with add_host
    add_host:
      hostname: "{{ item.dest_name }}"
      ansible_host: "{{ item.dest_addr }}"
      ansible_user: "{{ item.dest_conn_user }}"
      ansible_password: "{{ item.dest_conn_pwd }}"
      ansible_dest_protocol: "{{ item.dest_protocol| default('') }}"
      ansible_port: "{{ item.dest_port | default('22') }}"
      ansible_host_key_checking: no
      custom_dest_name: "{{ item.dest_name }}"
      group: remote_org
    with_items: "{{ dests }}"

- name: Module test with set parameter
  gather_facts: no
  hosts: remote_org
  become: yes
  remote_user: root
  roles:
   - ../roles/4.get_vm_mac

下面是我的任务/主文件

---
  - block:
    - name: Get Target VMid
      command: /bin/vim-cmd vmsvc/getallvms
      delegate_to: localhost

    rescue:
    - name: 'When failure'
      debug:
        msg: "Try again"

和结果

[Errno 2] No such file or directory

你能帮我吗?? :d

解决方法

我犯了一个基本错误

  - block:
    - name: Get Target VMid
      command: /bin/vim-cmd vmsvc/getallvms
      #delegate_to: localhost <- delete this line

现在工作

谢谢大家