how can use vim-cmd command in esxi with ansible

291 Views Asked by At

I have no vCenter, just esxi hosts

and I don't use any ansible inventory, I prefer add_host style like below

- 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

ans my tasks/main file below

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

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

and results

[Errno 2] No such file or directory

can you help me ?? :d

1

There are 1 best solutions below

0
On

I made a basic mistake

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

and now works

thank you everybody