EM 24ai: Configure EM agent manually after failure

Problem:

While installing EM 24ai, everything was configured except for the agent which is the last step. It failed with the following vague error:

...
1. state_dir=/u03/em24/agent/agent_inst
2. agentBaseDir=/u03/em24/agent
3. oraHome=/u03/em24/agent/agent_24.1.0.0.0
INFO: oracle.sysman.top.agent:Agent Home is : {0}
SEVERE: oracle.sysman.top.agent:Agent configuration has failed
INFO: oracle.sysman.top.agent:AgentConfiguration:agent configuration finished with status = false
INFO: oracle.sysman.top.agent:AgentConfiguration:agent configuration finished with status = false
INFO: oracle.sysman.top.agent:The plug-in Agent Configuration Assistant has failed its perform method

Solution:

Make sure agent_inst directory is empty, otherwise rename the folder and recreate:

$ cd /u03/em24/agent
$ mv agent_inst agent_inst2
$ mkdir agent_inst; chmod 755 agent_inst

Make sure libnsl package is installed, otherwise install it using yum:

$ yum install libnsl

Reconfigure agent manually:

$ /u03/em24/middleware/oms_home/oui/bin/runConfig.sh ORACLE_HOME=/u03/em24/middleware/oms_home MODE=perform ACTION=configure COMPONENT_XML={encap_oms.1_0_0_0_0.xml}

Setting the invPtrLoc to /u03/em24/middleware/oms_home/oraInst.loc
...
Setting system property CUSTOM_INVENTORY to {0}
chain install is :true

Cloning of agent home completed successfully
Agent Configuration completed successfully
The following configuration scripts need to be executed as the "root" user. Root script to run : /u03/em24/agent/agent_24.1.0.0.0/root.sh

perform - mode finished for action: configure

Run root.sh script that is requested in the output of the above command:

# /u03/em24/agent/agent_24.1.0.0.0/root.sh

It worked for me and I hope it will work for you as well. The solution was found after a lot of digging, and there might be another solution too.