0

我没有 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

4

1 回答 1

1

我犯了一个基本错误

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

现在可以工作了

谢谢大家

于 2021-04-20T06:10:16.437 回答