PXEboot is not working

Problem:
PXEBoot with kickstart default is not loading when I try to run it through ansible
Expected outcome:
Booting should work with kickstart default

Other relevant data:
We are trying to create a host using ansible playbook

---
- hosts: myhost
  tasks:
    - name: "Create a VM on specific ovirt network"
      theforeman.foreman.host:
        username: "admin"
        password: "mypass"
        server_url: "myhost.com"
        name: "test1.local.com"
        organization: "myorg"
        location: "myloc"
        lifecycle_environment: "Development"
        content_source: "myhost.com"
        content_view: "AlmaLinux8.4"
        managed: true
        build: true
        compute_profile: "3-Large"
        compute_resource: "Linux"
        compute_attributes:
          cpus: "2"
          memory_mb: "2048"
        interfaces_attributes:
        - type: "interface"
          primary: true
          provision: true
          compute_attributes:
#            name: "eth0"
            identifier: "eth0"
            ip: "192.169.1.56"
            network: "PVT"
            interface: "VirtualVmxnet3"
            subnet: "Subnet"
        operatingsystem: "AlmaLinux8.4"
        provision_method: "build"
        medium: "AlmaLinux8.4Development"
        architecture: "x86_64"
        state: present
        ptable: "Kickstart default"
        root_pass: "mypass"

When we try to execute this playbook, script executes with no error, host gets created but we are not seeing the PXEBoot config file in /var/lib/tftpboot/pxelinux.cfg/ and also We are getting this while booting

But everything works fine when we do the same with hammer command with same configuration. Can you check if I’m messing up with the playbook or am I missing something? Any help would be appreciated.

@evgeni @iballou @Marek_Hulan Any thoughts on this?

You’re not setting a hostgroup or a subnet, so I don’t think Foreman knows which TFTP proxy to configure.

@evgeni I have added subnet: “Subnet” under interfaces_attributes

Huh, then not sure. Would need to see the API output of both hosts (created by hammer and Ansible) to have a better guess.

Ansible is not giving any error. It is working as expected.

Well, no, as the host is not being deployed properly.

Can you get us the contents of https://myhost.com/api/hosts/test1.local.com and https://myhost.com/api/hosts/hammertest1.local.com (a machine you created via hammer)?

Both should be JSON representations of the hosts. Feel free to mail them to evgeni redhat com if you think there might be any sensitive data in there.

I have sent you an email

@evgeni Also, I am not sure of this part. Is the correct way of defining in ansible?

        interfaces_attributes:
        - type: "interface"
          primary: true
          provision: true
          compute_attributes:
#            name: "eth0"
            identifier: "eth0"
            ip: "192.169.1.56"
            network: "PVT"
            interface: "VirtualVmxnet3"
            subnet: "Subnet"

So looking at the diff of what you sent me, I see the following interesting differences (the -- is always testmachine1 and the ++ is sidtest):

  1. the machine deployed by hammer does have a hostgroup set, while the ansible one does not:
-    "hostgroup_id": 1,
-    "hostgroup_name": "Provision from abc.code1.example.com",
-    "hostgroup_title": "Provision from abc.code1.example.com",
+    "hostgroup_id": null,
+    "hostgroup_name": null,
+    "hostgroup_title": null,
  1. the hammer machine is assigned to a subnet, while the ansible one is not:
     "interfaces": [
         {
             …
-            "subnet_id": 1,
-            "subnet_name": "ABC-Subnet",
+            "subnet_id": null,
+            "subnet_name": null,
-    "ip": "192.168.1.55",
+    "ip": null,
-    "subnet_id": 1,
-    "subnet_name": "ABC-Subnet",
+    "subnet_id": null,
+    "subnet_name": null,

Now to the “obvious” question why, as you do set the subnet in the interfaces_attributes

Exactly. I have set all those in my playbook and I have no idea why it is not fetching @evgeni

Ah! You need to set subnet not inside the compute attributes of the interface, so:

        interfaces_attributes:
        - type: "interface"
          primary: true
          provision: true
          subnet: "Subnet"
          compute_attributes:
#            name: "eth0"
            identifier: "eth0"
            ip: "192.169.1.56"
            network: "PVT"
            interface: "VirtualVmxnet3"

After making the changes in subnet part, I ran the script and now playbook is giving me an error

 FAILED! => {"changed": false, "error": {"errors": {"interfaces.ip": ["can't be blank"]}, "full_messages": ["Ip can't be blank"], "id": null}, "msg": "Error while performing create on hosts: 422 Client Error: Unprocessable Entity for url:

Hah. Reading all of your YAML helps.

Try

        interfaces_attributes:
        - type: "interface"
          primary: true
          provision: true
          identifier: "eth0"
          ip: "192.169.1.56"
          subnet: "Subnet"
          compute_attributes:
            network: "PVT"
            interface: "VirtualVmxnet3"

Still the same error: FAILED! => {“changed”: false, “error”: {“errors”: {“interfaces.ip”: [“does not match selected subnet”]}, “full_messages”: [“Ip does not match selected subnet”], “id”: null}, “msg”: "Error while performing create on hosts: 422 Client Error: Unprocessable Entity for url:

This is hardly the same error. Please read the error and act accordingly :slight_smile:

Providing the same IP through hammer was working.

I doubt that.

192.169.1.56 or 192.168.1.56?

Oh shoooooooot!

FAILED! => {"changed": false, "error": {"errors": {"base": ["Create DHCP Settings for test1.local.com task failed with the following error: ERF12-6899 [ProxyAPI::ProxyException]: Unable to set DHCP entry ([RestClient::Conflict]: 409 Conflict) for proxy https://myhost.com/dhcp"]}, "full_messages": ["Create DHCP Settings for sidtest.code1.emi.philips.com task failed with the following error: ERF12-6899 [ProxyAPI::ProxyException]: Unable to set DHCP entry ([RestClient::Conflict]: 409 Conflict) for proxy https://myhost.com:9090/dhcp"], "id": null}, "msg": "Error while performing create on hosts: 422 Client Error: Unprocessable Entity for url: https://myhost.com/api/hosts"}