Goglides Dev 🌱

Goglides Dev 🌱 is a community of amazing users

We are working on this space so that IT professionals can grow together.

Create account Log in
Balkrishna Pandey
Balkrishna Pandey

Posted on

Openshift-UPI: Create custom ignition files using Filetranspiler

Creating Ignition file with filetranspiler tool

In the Openshift UPI deployment method, since we have to generate our ignition config, so to simplify the process, I am going to use the filetranspiler tool for creating custom ignition files. This tool creates an Ignition file from a fake root. Please follow the official GitHub URL for more information.

Installation of filetranspiler tool

The best way to install this project is to run it as a container. So that you can avoid OS-related dependencies.
First, clone the project from GitHub.

git clone https://github.com/ashcrow/filetranspiler.git 
Enter fullscreen mode Exit fullscreen mode
  • Now, you can run the following command to build the project
podman build . -t filetranspile:latest
Enter fullscreen mode Exit fullscreen mode

Now you can run the filetranspiler as follows, make sure to mount the host directory that has your ignition file and fake root into the container,

podman run --rm -ti --volume `pwd`:/srv:z filetranspile:latest -i install-dir/bootstrap.ign -f bootstrap/fakeroot -o install-dir/custom-bootstrap.ign
Enter fullscreen mode Exit fullscreen mode

You can also create an alias run filetranspiler as generally as follows,

alias filetranspile="podman run --rm -ti --volume `pwd`:/srv:z filetranspile:latest"
filetranspile -i install-dir/bootstrap.ign -f bootstrap/fakeroot -o install-dir/custom-bootstrap.ign
Enter fullscreen mode Exit fullscreen mode

If you do not like the container approach, you can install filetranspiler in Fedora using rpm package manager as follows,

curl -LO https://download.copr.fedorainfracloud.org/results/eminguez/eminguez-RPMs/fedora-33-x86_64/01784152-filetranspiler/filetranspiler-1.1.0-1.fc33.x86_64.rpm
sudo rpm -ivh filetranspiler-1.1.0-1.fc33.x86_64.rpm
Enter fullscreen mode Exit fullscreen mode

Testing filetranspiler tool

Once you have installed this tool, create a fake root directory. Run the following script to test,

mkdir -p fakeroot/etc
echo "master-0.goglides.io" > fakeroot/etc/hostname
ln -s hostname fakeroot/etc/hostname.link
echo "nameserver 8.8.8.8" >fakeroot/etc/resolv.conf
mkdir -p fakeroot/etc/sysconfig/network-scripts
cat <<EOF > fakeroot/etc/sysconfig/network-scripts/ifcfg-eno1np0
BOOTPROTO=none
DEFROUTE=yes
IPADDR=192.168.7.213
IPV4_FAILURE_FATAL=no
NAME=eno1np0
EOF
Enter fullscreen mode Exit fullscreen mode

At the end of this script, your folder structure should look like this,

tree fakeroot
Enter fullscreen mode Exit fullscreen mode

Filetransfile

Now we need a startup ignition.json to test; let's create a test file as follows,

cat <<EOF > ignition.json
{
 "ignition": { "version": "3.0.0" },
 "systemd": {
  "units": [{
  "name": "example.service",
  "enabled": true,
  "contents": "[Service]\nType=oneshot\nExecStart=/usr/bin/echo Hello World\n\n[Install]\nWantedBy=multi-user.target"
  }]
 }
}
EOF
Enter fullscreen mode Exit fullscreen mode

Once your directory structure is in place, then use filetranspiler binary to create your custom ignition.

 filetranspile -i ignition.json -f fakeroot -o custom-ignition.ign
Enter fullscreen mode Exit fullscreen mode

This will create a custom-ignition.ign file with the following content,

cat custom-ignition.ign | jq . 
Enter fullscreen mode Exit fullscreen mode

FileTransfile JSON Output

If you want to see a pretty output on-screen, use the following command.

filetranspile -i ignition.json -f fakeroot -p
Enter fullscreen mode Exit fullscreen mode

To know more about this tool, run the help menu,

filetranspile --help
Enter fullscreen mode Exit fullscreen mode
usage: filetranspile [-h] [-i IGNITION] -f FAKE_ROOT [-o OUTPUT] [-p]
  [--dereference-symlinks] [--format {json,yaml}]
  [--version]
optional arguments:
 -h, --help show this help message and exit
 -i IGNITION, --ignition IGNITION
  Path to ignition file to use as the base
 -f FAKE_ROOT, --fake-root FAKE_ROOT
  Path to the fake root
 -o OUTPUT, --output OUTPUT
  Where to output the file. If empty will print to
  stdout
 -p, --pretty Make the output pretty
 --dereference-symlinks
  Write out file contents instead of making symlinks
  NOTE: Target files must exist in the fakeroot
 --format {json,yaml} What format of file to write out. `yaml` or `json`
  (default)
 --version shows the program's version number and exit
Enter fullscreen mode Exit fullscreen mode

Now we know how to generate custom ignition files, let's move to the next topic.

Discussion (0)