Feature request: option to run a software item only after the host has been renamed and joined to the domain (with record failed Chocolatey packages)
-
Hello everyone,
I would like to propose a small option on a software item (or on a group association): “run only after the host has been renamed and joined to the domain”.
Today, on a fresh deploy, the agent enrolls, runs the snapins and then runs the Chocolatey software module, and only after that does it rename the host and join it to the domain, which ends in a reboot. That order is fine for Chrome or VLC. It is a problem for installers that do their real work in a second stage after the first one returns. Our case is the Avast Business agent: the MSI returns 0 in about ten seconds, but the antivirus itself is downloaded and installed afterwards, over the next few minutes. If the join reboot lands in the middle, the install can be left half done, and from FOG’s side everything looks fine because the Chocolatey package reported success.
What we do today is a workaround inside the package script: if the computer name is still the image name, the script throws on purpose, so nothing gets installed, and then we rely on FOG running the software again after the reboot. It works, but it has some rough edges that a native option would remove:
-
When the script throws, the software status row for that host is not updated. It keeps the old state (
convergedfrom a previous run), so the web UI never shows that the package failed. We only knew from the host itself. -
We had to rely on the retry. By watching the web server log we saw that after each boot the agent runs the Chocolatey module about four times, roughly a minute apart, and then not again for hours (we saw passes about every six hours). So if the retry after the join reboot is missed, the next chance is a long way off.
-
The software status list of the host survives a new deploy. When an image is deployed, pending tasks such as snapins are cleared, but the old software status rows stay, so a freshly cloned host still shows software as
convergedorinstalledfrom the previous install. That is also why a failed package could not be told apart from an old success. The machine is new after a deploy, so that list should not be kept. -
We first tried to detect “not joined yet” with the domain membership, but that does not work: the agent renames the host and joins the domain in the same step, and both only become effective after the reboot, so right before it Windows already reports the host as part of the domain while it still has the image name. The host name was the only reliable signal.
So the request would be, in order of importance:
-
An option per software item (or per group) to defer it until after the rename/join reboot.
-
Recording a failed Chocolatey run in the software status (failed, with the output), instead of leaving the previous status.
-
Clearing the host’s software status list when a deploy finishes, the same way pending snapin tasks are cleared, since the machine is new.
I am not sure the ordering is the only thing behind our Avast problem, since we also had a separate crash of the vendor installer that seems unrelated, so I am only asking for the generic behavior, which would help with any installer that continues working after it returns.
Happy to share logs or test a patch if it helps. Thanks!
-
-
@lperoma Thanks for the detail. On the first two points: the next agent release will hold software until the rename/join reboot has happened, and a finished deploy will clear the host’s software status.
On the status row not updating: the server writes that row on every report, failures included, so something else is happening. Could you post the agent log lines from the pass where the script threw? Look for the line that starts with
software "<your package id>":, plus the matching lines in the web server log. Also, which page shows the staleconverged: the host’s Software tab, or the installed-software inventory? -
@lperoma Both changes are out now, so you can test them.
- Agent 0.1.30 waits for the rename/join restart before it runs software, and the snapins wait with it. Agents update themselves to it. After the restart, the first check-in runs the software under the new name. You can drop the name check from your package script.
- A finished deploy now clears the host’s software status. That is on dev-branch, so update your server to dev-branch to get it.
One thing to know: if a user stays logged in on a renamed PC, the restart waits for them to log off, so software waits too. Turn on “Enforce Hostname | AD Join Reboots” on the host to restart after the grace period instead. Details: https://docs.fogproject.org/en/latest/management/web/software/#software-waits-for-a-rename-or-a-domain-join
The log lines for the stale status are still useful if you can grab them.
-
@Tom-Elliott
Test result with the agent log: software waits for the rename/join restart, but not while the rejoin is still blockedThanks a lot, Tom, for the quick work on this, for the agent change and for #2214. I tested it on a fresh Deploy: image captured with agent 0.1.35, server 1.6.1.59 (27a1194fb, dev-branch with #2214). The deferral works, but software still ran twice before it kicked in. Times are UTC (web server and agent logs are UTC+1 and have been converted).
14:02:30 Post_Stage3.php, deploy finished (task complete, software status list cleared by #2214) 14:02:41 PXE boot.php (reboot after imaging) 14:03:06 Agent 0.1.35 enrolls (GET enroll, identity/check 409, POST enroll 200, identity/check 200) 14:04:06 PXE boot.php (second reboot, before the domain join) 14:04:22 Agent contacts (enroll, identity/check, poll 14:04:23) 14:04:26 "Run before software" snapin downloaded; result rc 0 at 14:05:11 14:06:49 SOFTWARE PASS 1: our package downloaded from the Chocolatey feed (200) 14:07:43 8 x POST /agent/v1/result: six packages "installed", rc 0; our Avast package has no status row. Agent update payload downloaded 14:07:54 Agent is now 0.1.36, update state ok 14:08:07 SOFTWARE PASS 2: package downloaded again; at 14:08:20 the six packages are "converged", still no row for the Avast package 14:08:23 POST /fog/agent/v1/directory/rejoin/start 14:08:25 AD: computer account password set (pwdLastSet) = the domain join 14:08:39 PXE boot.php: the rename/join restart 14:08:48 AD: computer object changed (whenChanged), first boot under the new name 14:08:49 First agent contact after the restart (enroll, identity/check, poll 14:08:54) 14:09:11 SOFTWARE PASS 3 (first one after the restart): package downloaded again (200) 14:09:31 Avast console: NO_SERVICES / ANTIVIRUS: INSTALLING 14:09:37 Avast package reported "installed", rc 0 (first time it has a status row); the other six "converged" 14:10:01 Pass 4: all seven packages "converged" 14:13:17 Avast console: SAFE / ANTIVIRUS: ACTIVATED (3 min 46 s after INSTALLING)The matching agent log lines (fog-agent.log, local time +01:00):
15:04:25 directory rejoin: blocked (directory_observation_required) 15:07:42 software "avast-business-agent": installed, exit 4294967295, outcome failed, installed "" 15:07:54 directory rejoin: blocked (directory_observation_required) 15:08:19 software "avast-business-agent": installed, exit 4294967295, outcome failed, installed "" 15:08:24 directory rejoin: native success; Windows restart and verification pending 15:08:25 software: deferred; a rename or domain join is waiting for its restart 15:08:25 reboot: applied (directory-rejoin: directory rejoin needs a Windows restart, mode reboot) 15:08:54 directory rejoin: verified after Windows restart 15:09:35 software "avast-business-agent": installed, exit 0, outcome success, installed "1.0.0"What I see:
- The deferral works.
software: deferredappears right after the join, and pass 3 only ran afterdirectory rejoin: verified after Windows restart. - The gap is before the join. From enrollment (15:03) until 15:08:24 the rejoin was
blocked (directory_observation_required), so nothing was pending and software ran twice while the computer was still named INSTALACION (the image name). What is that observation, and could software also wait while a join is expected but still blocked? - The failed run was not stored. The agent logged
outcome failed(exit 4294967295) for our package in both early passes, and the 7 results were posted, but the host had only 6 software status rows, none for that package, until after the restart (point 2 of my first post is still open). - The Avast install worked, but only thanks to our own name check in the package script, which made it skip passes 1 and 2 and let pass 3 through.
- The status list was empty right after the deploy finished, so #2214 works. That one is a big help, thank you.
Happy to test a patch or send more logs.
- The deferral works.