How to output data into file in iPXE Provisioning Template

Problem:
I am attempting to output data to a file in the iPXE Provisioning template, but nothing seems to work. Here are a few of the things I have tried:

Echo data into the file:
echo "hello world" > /path/to/file
Expected output:
“hello world” is outputted into path/to/file
Actual output:
iPXE screen prints "hello world" > /path/to/file

Ruby File.write() function (yes, safemode is off):
File.open(/path/to/file, 'w') { |file| file.write("hello world") }
Expected output
“hello world” is outputted into path/to/file
Actual output:
iPXE screen displays error that the function is not found

Foreman and Proxy versions:
Foreman 3.5.1.17‑1

Foreman and Proxy plugin versions:

    ansible-collection-redhat-satellite-3.9.0-2.el8sat.noarch
    ansible-collection-redhat-satellite_operations-1.3.0-2.el8sat.noarch
    ansiblerole-foreman_scap_client-0.2.0-2.el8sat.noarch
    candlepin-4.2.13-1.el8sat.noarch
    candlepin-selinux-4.2.13-1.el8sat.noarch
    foreman-3.5.1.17-1.el8sat.noarch
    foreman-bootloaders-redhat-202102220000-1.el8sat.noarch
    foreman-bootloaders-redhat-tftpboot-202102220000-1.el8sat.noarch
    foreman-cli-3.5.1.17-1.el8sat.noarch
    foreman-debug-3.5.1.17-1.el8sat.noarch
    foreman-dynflow-sidekiq-3.5.1.17-1.el8sat.noarch
    foreman-ec2-3.5.1.17-1.el8sat.noarch
    foreman-installer-3.5.2.1-1.el8sat.noarch
    foreman-installer-katello-3.5.2.1-1.el8sat.noarch
    foreman-libvirt-3.5.1.17-1.el8sat.noarch
    foreman-obsolete-packages-1.1-1.el8sat.noarch
    foreman-openstack-3.5.1.17-1.el8sat.noarch
    foreman-ovirt-3.5.1.17-1.el8sat.noarch
    foreman-postgresql-3.5.1.17-1.el8sat.noarch
    foreman-proxy-3.5.1-1.el8sat.noarch
    foreman-selinux-3.5.1-1.el8sat.noarch
    foreman-service-3.5.1.17-1.el8sat.noarch
    foreman-vmware-3.5.1.17-1.el8sat.noarch
    katello-4.7.0-1.el8sat.noarch
    katello-certs-tools-2.9.0-1.el8sat.noarch
    katello-client-bootstrap-1.7.9-1.el8sat.noarch
    katello-common-4.7.0-1.el8sat.noarch
    katello-debug-4.7.0-1.el8sat.noarch
    katello-selinux-4.0.2-2.el8sat.noarch
    pulpcore-selinux-1.3.2-1.el8pc.x86_64
    puppet-foreman_scap_client-0.4.0-1.el8sat.noarch
    python39-pulp-ansible-0.15.0-1.el8pc.noarch
    python39-pulp-certguard-1.5.5-1.el8pc.noarch
    python39-pulp-cli-0.14.0-4.el8pc.noarch
    python39-pulp-container-2.14.3-1.el8pc.noarch
    python39-pulp-file-1.11.1-1.el8pc.noarch
    python39-pulp-rpm-3.18.14-1.el8pc.noarch
    python39-pulpcore-3.21.6-1.el8pc.noarch
    qpid-proton-c-0.33.0-4.el8.x86_64
    rubygem-foreman-tasks-7.2.1-1.el8sat.noarch
    rubygem-foreman_ansible-10.4.0-1.el8sat.noarch
    rubygem-foreman_azure_rm-2.2.7-1.el8sat.noarch
    rubygem-foreman_bootdisk-21.0.3-1.1.el8sat.noarch
    rubygem-foreman_discovery-22.0.2-1.1.el8sat.noarch
    rubygem-foreman_google-1.0.3-1.el8sat.noarch
    rubygem-foreman_hooks-0.3.17-3.1.el8sat.noarch
    rubygem-foreman_leapp-0.1.13-1.el8sat.noarch
    rubygem-foreman_maintain-1.2.8-1.el8sat.noarch
    rubygem-foreman_openscap-5.2.3-1.el8sat.noarch
    rubygem-foreman_puppet-5.0.0-1.el8sat.noarch
    rubygem-foreman_remote_execution-8.3.0-1.el8sat.noarch
    rubygem-foreman_rh_cloud-7.0.45-1.el8sat.noarch
    rubygem-foreman_templates-9.3.0-2.1.el8sat.noarch
    rubygem-foreman_theme_satellite-11.0.0.5-1.el8sat.noarch
    rubygem-foreman_virt_who_configure-0.5.13-1.el8sat.noarch
    rubygem-foreman_webhooks-3.0.5-1.1.el8sat.noarch
    rubygem-hammer_cli-3.5.1-1.el8sat.noarch
    rubygem-hammer_cli_foreman-3.5.1-1.el8sat.noarch
    rubygem-hammer_cli_foreman_admin-1.1.0-1.el8sat.noarch
    rubygem-hammer_cli_foreman_ansible-0.4.0-2.el8sat.noarch
    rubygem-hammer_cli_foreman_azure_rm-0.2.2-1.el8sat.noarch
    rubygem-hammer_cli_foreman_bootdisk-0.3.0-3.el8sat.noarch
    rubygem-hammer_cli_foreman_discovery-1.1.0-1.el8sat.noarch
    rubygem-hammer_cli_foreman_google-1.0.0-1.el8sat.noarch
    rubygem-hammer_cli_foreman_openscap-0.1.13-2.el8sat.noarch
    rubygem-hammer_cli_foreman_puppet-0.0.6-1.el8sat.noarch
    rubygem-hammer_cli_foreman_remote_execution-0.2.2-1.el8sat.noarch
    rubygem-hammer_cli_foreman_tasks-0.0.18-1.el8sat.noarch
    rubygem-hammer_cli_foreman_templates-0.2.0-3.el8sat.noarch
    rubygem-hammer_cli_foreman_virt_who_configure-0.0.9-2.el8sat.noarch
    rubygem-hammer_cli_foreman_webhooks-0.0.4-1.el8sat.noarch
    rubygem-hammer_cli_katello-1.7.3-1.el8sat.noarch
    rubygem-katello-4.7.0.25-1.el8sat.noarch
    rubygem-pulp_ansible_client-0.15.0-1.el8sat.noarch
    rubygem-pulp_certguard_client-1.5.5-1.el8sat.noarch
    rubygem-pulp_container_client-2.14.2-1.el8sat.noarch
    rubygem-pulp_deb_client-2.20.0-1.el8sat.noarch
    rubygem-pulp_file_client-1.11.2-1.el8sat.noarch
    rubygem-pulp_ostree_client-2.0.0-0.1.a1.el8sat.noarch
    rubygem-pulp_python_client-3.7.3-1.el8sat.noarch
    rubygem-pulp_rpm_client-3.18.7-1.el8sat.noarch
    rubygem-pulpcore_client-3.21.2-1.el8sat.noarch
    rubygem-qpid_proton-0.33.0-5.el8sat.x86_64
    rubygem-smart_proxy_pulp-3.2.0-3.el8sat.noarch
    satellite-6.13.1-1.el8sat.noarch
    satellite-cli-6.13.1-1.el8sat.noarch
    satellite-common-6.13.1-1.el8sat.noarch
    satellite-installer-6.13.0.7-1.el8sat.noarch
    satellite-maintain-0.0.1-1.el8sat.noarch

Other relevant data:
What I am REALLY trying to do is output the generation of a snippet to a file.
I am using Red Hat Satellite, but it is based on Foreman so I thought to ask here.

What are you actually trying to achieve with this? Writing a file inside the iPXE boot environment does not sound like a usual use-case, and I am not even sure the iPXE environment has any tools for that (at least the iPXE documentation does not list any).

I am trying to cloud-init boot Ubuntu 20.04. However, my issue that I’m facing is that either Foreman doesn’t pass through the cloud-init/userdata files or Ubuntu isn’t honoring them. I’m leaning towards Foreman some how isn’t passing them because I can manually boot a no-cloud cloud-init just fine by pointing the url for cloud-init in iPXE to static user-data on my Foreman-proxy (my end goal is to pass through Foreman host parameters). It’s only getting weird when I try to pass these files through Foreman. I found that I can turn my Foreman user-data template into a snippet and I’m able to render it properly in iPXE, so I thought a work around could be to some how do something with the cloud init user-data in iPXE itself by either passing the rendered text into a variable than perhaps passing thag variable into one of the iPXE cloud init parameter, or by somehow outputing the text to a file and then pointing the url for the cloud-init to the outputted file. Thank you for your help!

I doubt putting anything in the iPXE template will help you with this. Only the ruby-erb part of the templates are rendered on the Foreman side, but actual execution happens on the clientside. So anything that land’s in the final template will be executed in the iPXE environment and needs to be an iPXE command.
I would expect that ruby File functions could work if safemode is off and the logic happens inside some ERB Syntax tags, but that would probably lead to other problems and does generally sound like a bad idea where many things could go wrong.
I can’t really help with the cloud-init problem since we do not use that feature a lot, but I would recommend trying to fix that part rather than implementing a very hacky solution that probably won’t work anyways.

I found a really scuffed solution. Because my business uses iPXE to boot and not PXELinux to boot, I discovered that PXELinux, despite us not loading off of it, will still generate a new config in pxelinux.cfg every system build along with a .ipxe config file. I also found that I can just stick our cloud-init stuff into a PXELinux template type file, associate it with a system, build it, and a system specific cloud-init file is generated and accessible. All I need to do then is in our iPXE template, set cloud-config-url to point to where the PXELinux file (really our cloud-init file) generates.