Section 2 - Automated device onboarding

During this section you need to bear in mind two important things:

Now it’s time to prepare your edge device:

  1. Open the “Jobs” page in the AAP and keep it visible while performing the following steps.

  2. It’s time to boot our edge device VM or physical server and perform the onboarding (if you didn’t already). You need to boot from network (using the NIC that is connected to the edge local manager internal network). You will need to configure your VM or Physical BIOS to boot from the right interface. If your edge device was already deployed in a previous test or it already has Linux installed on it you can also use efibootmgr to select the “Next boot order” from the CLI:

[root@edge-848bcd4d1537 ~]# efibootmgr 
BootCurrent: 0004
Timeout: 3 seconds
BootOrder: 0004,0000,0003,0002,0001
Boot0000* EFI Hard Drive (TS128GMTS952T2)
Boot0001* Internal EFI Shell
Boot0002* EFI PXE 0 for IPv4 (84-8B-CD-4D-15-37) 
Boot0003* EFI PXE 1 for IPv4 (84-8B-CD-40-55-5F) 
Boot0004* Red Hat Enterprise Linux
[root@edge-848bcd4d1537 ~]# efibootmgr --bootnext 2
BootNext: 0002
BootCurrent: 0004
Timeout: 3 seconds
BootOrder: 0004,0000,0003,0002,0001
Boot0000* EFI Hard Drive (TS128GMTS952T2)
Boot0001* Internal EFI Shell
Boot0002* EFI PXE 0 for IPv4 (84-8B-CD-4D-15-37) 
Boot0003* EFI PXE 1 for IPv4 (84-8B-CD-40-55-5F) 
Boot0004* Red Hat Enterprise Linux

When you system boots from network, you will hit a menu where you will select the image that you will start using PXE boot:

rhde_gitops_pxe.png

Select the user that you are using for the demo/workshop (probably Student 1).

Note

It’s important to say here that in a real production environment there won’t be any manual step to select the right image (since we will have just a single image) so you will get a completely unattended onboarding experienc. Here we need to select the image because the lab is prepared to be used by several people at the same time and the PXE server is unique.

  1. Wait until the server boots. Few seconds later you will see that two Workflow Jobs are automatically launched in AAP:
  1. The magic behind this automated workflow is that, as explained in Section 1 - Creating RHEL Images the GitOps way, the kickstart file crestes an auto-registration Systemd unit and script that is launched on the system first boot. That scripts calls the Event Driven Automation service to start the workflows in AAP. You can now SSH to the edge device and check those script and systemd unit with the following commands as root:

Note

Your edge device is located in an “isolated” network. If you don’t plug your laptop into that network, in order to SSH to the edge device in this demo you will need to first SSH to the local edge manager server and use it as a Jump host. Remember that you have the local edge manager server IP in the local-inventory.yaml file that you used to deploy the lab and you can obtain the edge device IP from the AAP Inventory (the username is ansible).

The script:

cat /var/tmp/aap-auto-registration.sh 
#!/bin/bash
conn_name=\$(nmcli con show | grep -v UUID | head -n 1 | awk '{print \$1}')
IP_ADDRESS=\$(nmcli conn show \$conn_name | grep ip_address | awk '{print \$4}')

#MAC_ADDRESS=\$(ip addr | grep wlp -A 1 | grep link | awk '{print \$2}' | sed 's/://g')
MAC_ADDRESS=\$(ip addr | grep \$conn_name -A 1 | grep link | awk '{print \$2}' | sed 's/://g')
STUDENT='1'


if [ -z "\$IP_ADDRESS" ] || [ -z "\$MAC_ADDRESS" ] || [ -z "\$STUDENT" ]; then
    echo "One or more required variables are empty. Script failed."
    exit 1
fi

JSON="{\
\"ip_address\": \"\$IP_ADDRESS\", \
\"student\": \"\$STUDENT\", \
\"mac_address\": \"\$MAC_ADDRESS\" \
}"

/usr/bin/curl -H 'Content-Type: application/json' --data "\$JSON" https://eda../endpoint

Note

In the command output you will get something similar but with those `` variables substituted with the values that you have in your extra_vars.yml file that you used for the deployment.

The Systemd unit:

cat /etc/systemd/system/aap-auto-registration.service 
[Unit]
Description=Register to Ansible Automation Platform
After=network.target
After=connect-wifi.service
ConditionPathExists=!/var/tmp/aap-registered

[Service]
Type=simple
ExecStart=/bin/bash -c 'while true; do /var/tmp/aap-auto-registration.sh && /usr/bin/touch /var/tmp/aap-registered && break; done'

[Install]
WantedBy=default.target

Note

Please note that for this demo we are not authenticating the EDA requests for simplicity.