Creating Task with TaskTypeManagement
-
@cjenness Yep I got that. That custom task function isn’t working as I “thought” it might. I’m still testing, but I think we might end up having to create a feature request for this action. I have see others post for something similar. Its a bit beyond the scope of what FOG was intended to do.
-
Thank you for taking the time to check on this for me.
-
@cjenness The tasktypeedit plugin was designed to do this. It also means you may need to build your own hook to handle the more specifics.
-
Okay sorry thinking too much I think.
Seeing as you are getting error 500, can you provide your apache error logs?
-
I think the error is in the arguments.
Where is the
$TaskType
variable being set? (I’m guessing the 500 error will show something like:
Attempting to run non-existent method get on null at line ###). -
I’ve actually fixed the 500 error. I was missing a comma after boot.wim in the hook in OP. But I am not sure how to get the task type manager to call the hook.
-
So for the hook, I have just been editing the file /var/www/fog/lib/hooks/boottask.hook.php. The only part I have edited so far are the arguments that I posted above.
-
Can you paste the contents of the file (or upload the hook) here please?
-
@cjenness Okay, if it’s the example, mark the active flag as true, that’s all you need to do.
-
Here is the entire file. So I have marked the flag as true and I no longer get the http 500 error, but I am not sure how to create a task with this hook.
<?php /** * Alters the boot task to make a custom entry. * * PHP version 5 * * @category BootTask * @package FOGProject * @author Tom Elliott <tommygunsster@gmail.com> * @license http://opensource.org/licenses/gpl-3.0 GPLv3 * @link https://fogproject.org */ /** * Alters the boot task to make a custom entry. * * @category BootTask * @package FOGProject * @author Tom Elliott <tommygunsster@gmail.com> * @license http://opensource.org/licenses/gpl-3.0 GPLv3 * @link https://fogproject.org */ class BootTask extends Hook { /** * The name of this hook. * * @var string */ public $name = 'BootTask'; /** * The description of this hook. * * @var string */ public $description = 'Alter the boot task to make a custom task hook'; /** * Is this hook active or not. * * @var bool */ public $active = true; /** * Initializes object. * * @return void */ public function __construct() { parent::__construct(); self::$HookManager ->register( 'IPXE_EDIT', array( $this, 'changeTask' ) ); } /** * Change the task. * * @param mixed $arguments The items to alter. * * @return void */ public function changeTask($arguments) { if (!isset($arguments['ipxe']['task'])) { return; } $TaskType = self::getClass('TaskType') ->set('name', 'trusty-install') ->load('name'); if (!$TaskType->isValid()) { return; } $keys = array_keys($arguments['ipxe']['task']); if (!in_array($TaskType->get('id'), $keys)) { return; } $arguments['ipxe']['task'][$TaskType->get('id')] = array( 'cpuid --ext 29 && set arch amd64 ||', 'kernel http://${fog-ip}/win2012/${arch}/wimboot', 'initrd http://${fog-ip}/win2012/${arch}/media/Boot/BCD', 'initrd http://${fog-ip}/win2012/${arch}/media/Boot/boot.sdi', 'initrd http://${fog-ip}/win2012/${arch}/media/sources/boot.wim', 'boot ||', ); $arguments['Host'] ->get('task') ->set( 'stateID', self::getCompleteState() )->save(); } }
-
@cjenness In the FOG web GUI click on one of your hosts or groups, then click ‘Basic tasks’ on the left and ‘Advanced’ to show all the tasks available. Do you see “BootTask” here?
-
Well the “BootTask” would be whatever task type was created. The “boottask” is just the hook that makes that hook operate.
-
Thank you guys for your help. So my question now is how do I tell the task type editor to use the hook that I just created?
-
Nevermind, I figured it out. You have to title your new task the name (trusty-install) in this portion.
$TaskType = self::getClass(‘TaskType’)
->set(‘name’, ‘trusty-install’)
->load(‘name’);
if (!$TaskType->isValid()) {
return; -
Sorry to resurrect an old thread, but this just came up as something we need to be able to do (assign a custom boot task to hosts/groups of hosts). My understanding of the discussion below is that I should
- Enable plugins (
Fog Configuration->Fog Settings->Plugin System->PluginSys Enabled
) - Activate the
tasktypeedit
plugin - Edit
lib/hooks/boottask.hook.php
, settingpublic $active = true;
Then I should be able to visit a
host page -> Basic Tasks -> Advanced Tasks
and see ‘trusty-install’ as one of the options, but I don’t see any change to the menu. Have I missed something in the configuration? - Enable plugins (
-
@ianabc Have not had any time to look into this. Haven’t used that plugin in a long time and need to fiddle with it before I can give you any answer. Might be on the weekend.
-
@ianabc Had a bit more time to look into this now. You have missed one important point here. You need to manually create a new TaskType (web UI -> main menu -> TaskTypes -> Create New Task Type) and name that
trusty-install
- exactly the name of the task that is used inlib/hooks/boottask.hook.php
(line 73). As soon as you’ve created this task type you should see it inHost -> Basic Tasks
(orHost -> Basic Tasks -> Advanced Tasks
if you’ve checked the “Is Advanced” checkbox when creating it!).Now you can schedule this task type for any client or group and when it boots up it uses the arguments you set in
lib/hooks/boottask.hook.php
(line 83 to 93). But only if the names match. So if you name your new taskbababoo
you need to have that in yourlib/hooks/boottask.hook.php
line 73 as well. -