Sunday, October 02, 2016

Oracle Linux and opcinit for package installation

When deploying an Oracle Linux instance on the Oracle public cloud you will get a vanilla installation based upon the template you have selected. In some cases that might very well be exactly what you want and what you need. However, in many cases you want to ensure you have a Oracle Linux deployment that is tailored to your liking, or to the needs of the end-users who will use this machine.

You will have a couple of options to ensure your Oracle Linux instance is more than only the template based deployment. For once, you can build your own template and include everything you think is needed in a template and is specific to the need of your company or your customers.

Another and more direct and agile way of doing things is using the post deployment scripting options. Whenever you deploy a standard Oracle Linux template provided by Oracle it will run opc-init (or also named opcinit). The opc-init scripting is provided by Oracle and runs every time you create an instance based upon the template it is included in.

What opc-init is intended for is to do the final configuration, prebootstrapping tasks, that cannot be included in the template. For example, including specific packages to be installed that should not be part of the template or running specific application configuration scripts. Also the option is provided to run chef recipes that can do a full configuration and deployment for you.

Using the userdata section
Whenever you like to influence, or rather add, functions to the standard tasks opc-init is executing when you deploy a new Oracle Linux instance you will have to ensure you include this in the “userdata” section of orchestration JSON. Within the Oracle Public Cloud an orchestration describes the entire configuration of your instance in a JSON format and you can use this to fully automate your deployment.

Even if you do not use an API and the JSON orchestration file and you are using the web interface to create a new Oracle Linux instance, in the background still the orchestration JSON is used and you are given the option to add additional information to the used orchestration JSON file, or more specific to the  userdata section.



In the above screenshot you can see how we add an execution step to be executed by opc-init. The example shows that we want to have httpd installed to the Oracle Linux instance we deploy.

Adding packages
In case you want to add packages to your Oracle Linux deployment you can use the “packages” option, as we already showed in the above section. The part you have to add to the overall userdata of the JSON, or by using the web interface is shown below:

{
 "packages": ["httpd"],
}

In essence there is nothing more to it than ensuring this part is included and you will have httpd installed as soon as your Oracle Linux installation becomes available.

In case you would require more than one single package the JSON should look like the one below to ensure Oracle Linux and opcinit will recognize all packages and will install them. In this example we will install both httpd and wget on Oracle Linux by invoking the packages option for opcinit.

{
 "packages": ["httpd", "wget"],
}

Doing more with opcinit
Adding packages is only a small example of what can be done by using opcinit. However, in a lot of cases this will be what is required and what will help you in building a better deployment in most simple cases.

No comments: