Provisioning discovered hosts: hostgroup settings not applied

Looks like content view and lifecycle interface does not carry over when you press Submit (that is essentially edit host and update). I need to reproduce this, not sure what is wrong.

1 Like

If you need anything, please let me know. We could also set up a session where we poke around in my server (on Fridays I have the time to do this :slight_smile: as I’m not tied up in client work then).

If you want to have a frank advice, change your workflow to avoid Customize host. That is really something I would love to kill with passion, discovery rules will work reliably, creating host from hostgroup without customization will work. This tho, it is full of bugs, woes and regressions.

Will try to reproduce but no promises. :frowning:

1 Like

I think killing customize host sounds like a good plan. In my experience, the only thing you reasonably need to be able to do are:

  1. Set hostname (though there are plenty options to do that later as well)
  2. Set the hostgroup (which contains activation keys etc)

The rest I could legitimately miss :slight_smile:

The only reason I was diving into Customize host was to set a hostname, if that’s something that’s on the small pop-up, I’d probably never dive in the Customize menus. But due to the bugs you mention, I need to correct a whole lot of other things…

I will test my workflow with just assigning a host group and setting the hostname later (I actually never tested changing the hostname of a system that is already registered, so an interesting aspect would be to see if Foreman is updated with the new hostname :slight_smile: )

I agree that hostname would need to be there, then we could remove it. Let’s wait until Edit Host form is redesigned and then we can either remove it or perhaps integrate it in a better way.

1 Like

My new VM workstation came in yesterday and I have re-deployed the whole enchilada again, but I found something odd.

  • I use Ansible to configure Host Groups with all required details
  • When boot a blank VM it’s discovered, but I can’t install it.
    • Manually clicking ‘provision’ and setting a host group prompts for a missing installation source.
    • Discovery rules provide the following error:
2022-01-13T11:26:38 [I|app|12ae8218] Detected IPv4 subnet: Beheer with taxonomy ["HTM"]/["DC-A"]
2022-01-13T11:26:38 [I|app|12ae8218] Assigned location: DC-A
2022-01-13T11:26:38 [I|app|12ae8218] Assigned organization: HTM
2022-01-13T11:26:38 [I|app|12ae8218] Match found for host macaab6aa1c2acb (5) rule FreeIPA (2)
2022-01-13T11:26:38 [W|app|12ae8218] Could not find a provider for macaab6aa1c2acb. Providers returned {"Katello::ManagedContentMediumProvider"=>["Kickstart repository was not set for host 'macaab6aa1c2acb'", "Content source was not set for host 'macaab6aa1c2acb'"], "MediumProviders::Default"=>["Operating system was not set for host 'macaab6aa1c2acb'", " medium was not set for host 'macaab6aa1c2acb'", "Invalid medium '' for ''", "Invalid architecture '' for ''"]}

This strikes me as odd, as the Ansible module calls contain all the required parameters and when I inspect the created Host Group it does show the contents as I intented them to be.

So just for the sake of it, I opened a Host Group, didn’t change a thing, clicked save and voila, it works.

But I don’t understand why

Any idea, what is Ansible doing differently then my browser?

P.S. Discovery rules are really interesting, thanks for the tip!

Do you use nested hostgroups? That is also a rabbit hole, try with a flat one :slight_smile:

Also check org/loc there can be issues with that too.

To wrap it up:

  • Avoid host customizations in discovery
  • Avoid nested hostgroups
  • Rename hosts before provisioning (can be done via CLI or mass UI action)

Sorry, no, plain Host Groups :confused:

I did do some tests with renaming machines, even if you’re too late with renaming it (so it already started installing before you made the change), it’s still very trivial to update it afterwards :slight_smile: DNS will update immediately (if you have it set up that way :wink: )

When you create a new (fake) host with that hostgroup, does it work that way?

Discovery provisioning is nothing but editing an existing host, converting it from discovered to managed type and saving it with new parameters.

I tried reproducing it, but ever since I manually saved that one Host Group I can no longer reproduce the error.

Or I have been doing something wrong.

However, as you mentioned, ‘Customize Host’ is still not working, but that’s fine, as I have adapted my workflow to set the hostname immediatly after creating the host.

:tada: yay, it’s still broken (that’s not good, but that means I can reproduce it :slight_smile: )

I made a lot of different host groups (for the different types of machines in my lab setup). And then I applied the ‘open and save it’ workaround, presto.

The full log is here: 2022-01-20T00:26:37 [I|app|b4a15647] Completed 200 OK in 4ms (Views: 0.1ms | Act - Pastebin.com
The clicks I did:

  1. Open the host in Discovered hosts
  2. Click Provision, assign Host Group (Host group ID 5 = Rocky8-Kubernetes-Beheer)
  3. Get prompted for the media
  4. Go to the Host group, open it, save it (no changes made)
  5. Repeat from 1
  6. Success
1 Like

Oh gosh, rebuilding the edit host form is on this year’s agenda. We will solve this for once and forever. I do not want to dive into this code, discovery overrides ton of stuff and its been PAIN to maintain this. Unless you crack it.

1 Like

@lzap it took me some time, but I found a clue!

This is a hostgroup after it has been newly created by Ansible

Id:                    4
Name:                  RedHat8-Base-Infra
Title:                 RedHat8-Base-Infra
Description:           
  Managed by Ansible, your changes will be lost
Network:               
    Subnet ipv4: Infra
    Domain:      rh.lab
Operating system:      
    Architecture:     x86_64
    Operating System: RedHat 8
    Partition Table:  Kickstart default first disk only
    PXE Loader:       None
Puppetclasses:         

Parameters:            
    autopart_options => --nohome
    kt_activation_keys => RedHat8-Base-Infra
    remote_execution_create_user => true
    remote_execution_effective_user_method => sudo
    remote_execution_ssh_keys => ['a bunch of ssh keys']
    remote_execution_ssh_user => ansible
Locations:             
    DC1
Organizations:         
    Lab-Inc
OpenSCAP Proxy:        
Content View:          
    Id:   15
    Name: COV RedHat8-Base
Lifecycle Environment: 
    Id:   2
    Name: Infra
Content Source:        
    Id:   1
    Name: sat.rh.lab
Kickstart Repository:  
    Id:

And this is after the workaround I wrote in my previous post

Id:                    4
Name:                  RedHat8-Base-Infra
Title:                 RedHat8-Base-Infra
Description:           
  Managed by Ansible, your changes will be lost
Network:               
    Subnet ipv4: Infra
    Domain:      rh.lab
Operating system:      
    Architecture:     x86_64
    Operating System: RedHat 8
    Partition Table:  Kickstart default first disk only
    PXE Loader:       None
Puppetclasses:         

Parameters:            
    autopart_options => --nohome
    kt_activation_keys => RedHat8-Base-Infra
    remote_execution_create_user => true
    remote_execution_effective_user_method => sudo
    remote_execution_ssh_keys => ['a bunch of ssh keys']
    remote_execution_ssh_user => ansible
Locations:             
    DC1
Organizations:         
    Lab-Inc
OpenSCAP Proxy:        
Content View:          
    Id:   15
    Name: COV RedHat8-Base
Lifecycle Environment: 
    Id:   2
    Name: Infra
Content Source:        
    Id:   1
    Name: sat.rh.lab
Kickstart Repository:  
    Id: 144

So for some reason the Kickstart Repository ID isn’t properly saved, but the weird thing is, when I open the hostgroup in the WebUI it is visible :thinking:

Does this help in finding out what causes this? :blush:

Something in the UI what Katello overrides does not play well with what Discovery overrides. Sounds so bad I know.

@lzap o/

Well… I have a confession to make, my ansible role made a boo-boo when configuring the hostgroups.

So even while the forms may a bit plagued (not all issues described earlier are fixed), this was a problem of my own doing. When looking at my code again I noticed that I didn’t add the kickstart_repository argument (I did add medium…). :man_facepalming:

Which totally explains the behaviour and why the workaround actually works. Opening the form to edit a hostgroup tries to autocomplete some field (including the kickstart repo) when the Content View has been properly defined (which it is). And then saving the hostgroup saves whatever kickstart repo has been found by the auto-resolve logic of the form.

It still doesn’t fix the ‘Customize host’ workflow, but in our current situation that’s perfectly fine, the workaround you suggested by just setting the name later is solid.

Especially as we’re also going to focus more on using discovery rules combined with Ansible (see https://github.com/theforeman/foreman-ansible-modules/pull/1431 for a WIP module that can make them) which eliminates the need to customize a host altogether.

So sorry for creating the wild goose chase with regards to the Ansible modules, but thank you a lot for all the input you’ve given! :partying_face: :rocket:

1 Like

Just chiming in as I’m dealing with the same issue of things not appearing, but, not using Ansible, but am using nested host groups. I guess I can try without them.

I will add that I can’t use the automated discovery because I need to manually set the hostname before kickstarting (we have things in our install process that register with AD using hostname during build) so we can’t change it afterwards. But, having a simple way to set hostname/group without doing the whole customization thing would be great.

You can still use automated discovery in that case, let me share the playbook I use to create a new machine:

If you want, you can replace most of the variables with static values if you don’t have an extensive Ansible setup. Or script these actions in a different way (you could also accomplish this using hammer on the commandline)

---
# This is an example playbook/workflow on how to add new VMs to the virtual infrastructure
#
# 0. Ensure we can talk to Proxmox
# 1. Create a new KVM on Proxmox and grab MAC address
# 2. Create a new Discovery Rule in Foreman
# 3. Boot the VM
# 4. Get coffee
# 5. Playbook will clean up Discovery Rule for you
#
# NOTE: Due to how Proxmox works, the hostname on the hypervisor is not FQDN, the one
# in Satellite is. It's recommended to use the Foreman inventory module instead of
# Proxmox in environments where Foreman is present
#
- name: 'Deploy new machine'
  hosts: 'config.rh.lab'
  gather_facts: false
  vars_prompt:
    - name: 'input_hostname'
      prompt: 'What is the hostname of the new machine?'
      default: 'servera.example.com'
      private: false
    - name: 'input_memory'
      prompt: 'How much RAM in GB?'
      default: 2
      private: false
    - name: 'input_hostgroup'
      prompt: 'Which hostgroup will the machine be in?'
      default: 'RedHat8-Base-Infra'
      private: false
  tasks:
    - name: 'Ensure Proxmoxer Python module'
      ansible.builtin.pip:
        name: 'proxmoxer'
        state: 'present'

    - name: 'Create new VM on Proxmox'
      community.general.proxmox_kvm:
        api_user: "{{ proxmox_user }}"
        api_password: "{{ proxmox_password }}"
        api_host: "{{ proxmox_host }}"
        validate_certs: "{{ proxmox_validate_certs }}"
        name: "{{ input_hostname }}"
        node: "{{ proxmox_node }}"
        boot: 'ndc'  # network, dvd, disk
        bootdisk: 'virtio0'
        bios: 'ovmf'
        efidisk0:
          storage: "{{ proxmox_storage }}"
          efitype: '4m'
          format: 'raw'
          pre_enrolled_keys: false
        cores: 2
        memory: "{{ input_memory * 1024 }}"
        net:
          net0: 'virtio,bridge=vmbr0'
        scsihw: 'virtio-scsi-pci'
        virtio:
          virtio0: "{{ proxmox_storage }}:40"
        ide:
          ide0: 'none,media=cdrom'
        state: 'present'
      register: 'vm_created'

    - name: 'Ensure Discovery Rule on Satellite'
      theforeman.foreman.discovery_rule:
        username: "{{ hostvars[rhsm_foreman_server]['foreman_admin_user'] }}"
        password: "{{ hostvars[rhsm_foreman_server]['foreman_admin_password'] }}"
        server_url: "{{ hostvars[rhsm_foreman_server]['foreman_url'] }}"
        validate_certs: "{{ hostvars[rhsm_foreman_server]['foreman_validate_certs'] }}"
        name: "ansible-autoinstall-{{ input_hostname }}"
        search: "mac = {{ vm_created['mac']['net0'] | lower }}"
        hostgroup: "{{ input_hostgroup }}"
        hostname: "{{ input_hostname }}"
        organizations:
            - "{{ hostvars[rhsm_foreman_server]['foreman_organization'] }}"
        locations: "{{ hostvars[rhsm_foreman_server]['foreman_locations'] }}"

    - name: 'Wait for VM settle'
      ansible.builtin.pause:
        seconds: 10

    - name: 'Start VM on Proxmox'
      community.general.proxmox_kvm:
        api_user: "{{ proxmox_user }}"
        api_password: "{{ proxmox_password }}"
        api_host: "{{ proxmox_host }}"
        validate_certs: "{{ proxmox_validate_certs }}"
        name: "{{ input_hostname }}"
        state: 'started'

    - name: 'Wait for VM installer to start'
      ansible.builtin.pause:
        minutes: 5

    - name: 'Remove Discovery Rule from Satellite'
      theforeman.foreman.discovery_rule:
        username: "{{ hostvars[rhsm_foreman_server]['foreman_admin_user'] }}"
        password: "{{ hostvars[rhsm_foreman_server]['foreman_admin_password'] }}"
        server_url: "{{ hostvars[rhsm_foreman_server]['foreman_url'] }}"
        validate_certs: "{{ hostvars[rhsm_foreman_server]['foreman_validate_certs'] }}"
        name: "ansible-autoinstall-{{ input_hostname }}"
        state: 'absent'

We don’t use Ansible at all, we’re all puppet based, and I can’t do it in puppet either as the software in question that needs the hostname to be set is required by our puppet configs.

Right, but the point I wanted to make was, you can still use discovery rules to create a rule that matches a VMs MAC address and assigns it the hostname you need. You could probably also whip up something with Puppet to do either the required hammer calls or via the REST API.

Or call Ansible from Puppet, the possibilities are endless :grin: