ansible-collections / community.vmware

Ansible Collection for VMware
GNU General Public License v3.0
348 stars 339 forks source link

Refresh dynamic inventory #459

Closed FF186 closed 4 years ago

FF186 commented 4 years ago
SUMMARY

In my homelab I try to power on a VM which is turned off (hw_power_status == poweredOff) and do tasks on this machine. However, after the VM is powered on using the vmware_guest module, and the use of wait_for and - meta: refresh_inventory to get the newest information, the play fails and gives me UNREACHABLE.

I am not saying there's a problem with the dynamic inventory, but I'd like to get some feedback on my logic.

Thanks.

ISSUE TYPE
COMPONENT NAME

Module: vmware_guest Inventory: community.vmware.vmware_vm_inventory

ANSIBLE VERSION
ansible 2.9.9
CONFIGURATION
OS / ENVIRONMENT
STEPS TO REPRODUCE
- hosts: my_vm
  tasks:
- name: Power on VM
  vmware_guest:
    validate_certs: false
    hostname: "{{ vcenter_hostname }}"
    username: "{{ vcenter_username }}"
    password: "{{ vcenter_password }}"
    name: "my_vm"
    state: "poweredon"
  delegate_to: localhost

- name: Wait for system to become reachable
  wait_for:
    port: 22
    timeout: 300
    delay: 30
  delegate_to: localhost

- meta: refresh_inventory
- name: Gather facts 
  setup:
     ....
use `"{{ host_variable }}"`
    other tasks...
EXPECTED RESULTS
ACTUAL RESULTS

fatal: [my_vm]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh
: ssh: Could not resolve hostname my_vm: Temporary failure in name resolution", "skip_reason": "
Host my_vm is unreachable", "unreachable": true}
mariolenz commented 4 years ago

Since this doesn't look like a bug or a feature request, I'll close it. Please don't open issues in this project for general usage questions... but I'll give you some hints.

Failed to connect to the host via ssh : ssh: Could not resolve hostname my_vm: Temporary failure in name resolution

1) The wait_for (which is, by the way, not part of this collection) module can't resolve my_vm. Do you have a DNS record for my_vm? 2) You just create a VM, you don't install an OS; even if you have a correct DNS record, you get a running VM but without an OS you will never get an sshd to connect to.

FF186 commented 4 years ago

Hi @mariolenz , I understand your comment 100%, but when I run tests using the Dynamic Inventory it fails. I've tried this with the use of dynamic inventory, resulting in unreachable, and I've tried this adding the host in a static inventory.

Could this be something?..

mariolenz commented 4 years ago

Can you ssh my_vm successfully? From what you've told me, I'm pretty sure you can't... which means we're not talking about a problem with one of our modules.

Don't get me wrong, I'm not saying you don't have a valid question. But we're somewhat focused on fixing bugs and implementing new features, not about general usage issues.

Serverfault is a good place to ask questions about general usage issues, imho.

FF186 commented 4 years ago

I can ssh into it, I can run playbooks, but what I cannot do: Is to turn a server which is in state poweredOFF using the community.vmware.vmware_vm_inventory. If I only use the dynamic inventory the play fails, but if I but the machine and it's ip in a static inventory it works. I've even tried to use refresh_inventory without any success.

When I run the same playbook when the server is in state poweredON it works...

Sure, I get your point. Thanks @mariolenz.

FF186 commented 4 years ago

One last question @mariolenz, if you don't mind helping a useless kid.

I want to be able to refer to my VM, using the vm_name in host_vars/ definition, but I want the inventory_hostname or fqdn to be vm_name + my_domain