theforeman / foreman-ansible-modules

Ansible modules for interacting with the Foreman API and various plugin APIs such as Katello
GNU General Public License v3.0
147 stars 163 forks source link

wait_for feature for theforeman.foreman.host #961

Open gardar opened 3 years ago

gardar commented 3 years ago
SUMMARY

Please consider adding wait_for feature(s) for the host module, the feature would be used to get the ansible playbook to wait until the host is created/built or modifications to the host are successfully applied.

The vmware_guest_module can be used as a inspiration as it has two such options for waiting:

Using a separate task with wait_for_connection is not always possible since the host could be deployed on a network that's not accessible from where the foreman playbook is being run.

If I could query the build status of the host in a separate task then I guess that would be a acceptable workaround, but I haven't found a way to do that with the current modules.

--

ISSUE TYPE
gardar commented 3 years ago

Found a good workaround, creating a task with a "until" loop that looks up the host by name and checks if the status of the host is installed and that it's got a IP address. I'm verifying that it's got a IP in addition to being installed as the host seems to also get the "Installed" status when it's booted into the foreman discovery image

- name: "Check if VM is built and wait if it's not (max 10 minutes)"                                      
  theforeman.foreman.resource_info:                                                                       
    username: "{{ satellite_server_usr }}"                                                                
    password: "{{ satellite_server_psw }}"                                                                
    server_url: "https://{{ satellite_server_fqdn }}"                                                     
    validate_certs: false                                                                                 
    full_details: true                                                                                    
    search: name = "{{ satellite_host_name }}"                                                            
    resource: hosts                                                                                       
  register: build_post                                                                                    
  until: build_post.resources[0].build_status_label == "Installed" and build_post.resources[0].ip | ipaddr
  retries: 150                                                                                            
  delay: 15                                                                                               
mdellweg commented 3 years ago

I think you can also use the ping (ansible core) module with retries to wait for hosts to be available.

bherrin3 commented 3 years ago

Just curious if this issue is relative to FQDN as well. For example, in RHVM, there are similar ovirt.roles that do this same behavior. However, relative to the functionality of the product, FQDN is typically the killer for the product being ready to action on (for example, satellite installer).

Just wondering if this is outside the scope of this request. Thanks.

gardar commented 3 years ago

@mdellweg as I mentioned in the first post using ping/wait_for_connection is not always applicable as sometimes you won't be accessing the host directly from the same playbook being run, most of the time you probably will but not always. That being said I'm happy with the workaround I found, but it would still be nice to get this implemented within the foreman.host module.

@bherrin3, are you talking about the host being deployed in RHVM when the fqdn of the host appears? Does it appear in Satellite/Foreman? Could you perhaps query for the fqdn in a task similar to https://github.com/theforeman/foreman-ansible-modules/issues/961#issuecomment-694327226 ?