How-to: Install YUM packages

Overview

This example illustrates how the SSH plugin can be used to install some YUM packages in Linux (specifically the Linux variants Centos and Red Hat).

Three steps are required to use the plugin:

  • Define resources for enabling usage of the plugin
  • Define credentials for authentication.
  • Define module.

..And finally Pineapple should be invoked to execute the module to configure the targeted resources.

For information about how to define resource, credentials and modules, refer to the plugin usage page.

Part of the default configuration

This example is included in the default configuration created by Pineapple, so there is no need to create it by hand.

  • Define resources

    A resource defines a entity in a IT environment which is manageable by Pineapple through some protocol. In this example, the entity is a Linux OS and the used protocol is SSH. One resource is defined for each Linux host where the JVM should be installed.

    In this example we will use the linux-vagrant environment defined as part of the default configuration. The environment defines a network with three hosts:

    • Node1 with IP Address: 192.168.34.10
    • Node2 with IP Address: 192.168.34.11
    • Node3 with IP Address: 192.168.34.12

    To enable SSH usage for these hosts, three resources are defined within the linux-vagrant environment in the resources file located at ${user.home}/.pineapple/conf/resources.xml:

    <?xml version="1.0" encoding="UTF-8"?>
    <configuration xmlns="http://pineapple.dev.java.net/ns/environment_1_0"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://pineapple.dev.java.net/ns/environment_1_0
        http://pineapple.dev.java.net/ns/environment_1_0.xsd">
         
        <environments>
            <environment description="Vagrant multi-machine Linux environment" id="linux-vagrant">
                <resources>
                    <resource plugin-id="com.alpha.pineapple.plugin.ssh" credential-id-ref="ssh-node1" id="ssh-node1" >
                        <property value="192.168.34.10" key="host"/>
                        <property value="22" key="port"/>
                        <property value="1000" key="timeout"/>
                    </resource>
                    <resource plugin-id="com.alpha.pineapple.plugin.ssh" credential-id-ref="ssh-node2" id="ssh-node2" >
                        <property value="192.168.34.11" key="host"/>
                        <property value="22" key="port"/>
                        <property value="1000" key="timeout"/>
                    </resource>
                    <resource plugin-id="com.alpha.pineapple.plugin.ssh" credential-id-ref="ssh-node3" id="ssh-node3" >
                        <property value="192.168.34.12" key="host"/>
                        <property value="22" key="port"/>
                        <property value="1000" key="timeout"/>
                    </resource>
                </resources>
            </environment>
        </environments>
    </configuration> 
    

    Each resource is defined with a different ID and IP address. All other properties are identical. The role of the attribute plugin-id is to bind the resource definition to the plugin code at runtime which implements the SSH plugin.

Define credentials

Since SSH requires authentication, each resource defines a reference to a credential. A credential defines the user name and password used for authentication when a SSH session is created to a host.

Three credentials are created within the linux-vagrant environment to support authentication. The credentials are defined in the credentials file located at ${user.home}/.pineapple/conf/credentials.xml:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<configuration xmlns="http://pineapple.dev.java.net/ns/environment_1_0">
    <environments>
        <environment description="Vagrant multi-machine Linux environment" id="linux-vagrant">
            <credentials>
                <credential password="vagrant" user="vagrant" id="ssh-node1"/>
                <credential password="vagrant" user="vagrant" id="ssh-node2"/>
                <credential password="vagrant" user="vagrant" id="ssh-node3"/>
            </credentials>
        </environment>
    </environments>     
</configuration>

Define module

A module defines input to Pineapple and consists in its minimal form of a single XML file containing a model:

The module is located at ${user.home}/.pineapple/modules/ssh-005-install-jvm-rpm-linux64 and it has the structure:

ssh-005-install-jvm-rpm-linux64
 |
 +--- models     
 |     +--- linux-vagrant.xml
 +--- bin        
       +--- jdk-7u25-linux-x64.rpm.DOWNLOAD.ME

Download JVM

Download the Java SE JDK version 7u25 (update to a newer if you please) in the Linux x64 flavor as a RPM package, e.g. jdk-7u25-linux-x64.rpm and place it in the ${user.home}/.pineapple/modules/ssh-005-install-jvm-rpm-linux64/bin directory.

Define model

In the models directory, a model file named linux-vagrant is defined with the content:

<?xml version="1.0" encoding="UTF-8"?>
<mmd:models xmlns:mmd="http://pineapple.dev.java.net/ns/module_model_1_0" 
   xmlns:shp="http://pineapple.dev.java.net/ns/plugin/ssh_1_0">
   <mmd:model target-resource="regex:ssh-node.*">
      <mmd:content>
         <shp:ssh>
            <shp:copy-to source="modulepath:bin/jdk-7u25-linux-x64.rpm" destination="/tmp/jdk-7u25-linux-x64.rpm"/>
            <shp:execute command="sudo chmod a+x /tmp/jdk-7u25-linux-x64.rpm" />
            <shp:execute command="sudo yum --assumeyes install /tmp/jdk-7u25-linux-x64.rpm" />
         </shp:ssh>
      </mmd:content>
   </mmd:model>
</mmd:models>

The configuration details

Two schema are used in the model file. The http://pineapple.dev.java.net/ns/module_model_1_0 is used to define the namespace mmd which defines the general infrastructure for models. The http://pineapple.dev.java.net/ns/plugin/ssh_1_0 schema is used to define the namespace shp which is used to define the model for the SSH plugin. Since multiple schemas are used to define the model file, the elements are qualified.

The target-resource attribute defines a reference to the resource which is targeted when the model executed. In this case, the value regex:ssh-node.* defines a regular expression for targeting multiple resources, e.g. all the resources starting with ssh-node.

The main part of the model consists of four commands, which performs the installation steps:

  • Copy the file from the bin directory within the module to the tmp directory on the accessed host. The usage of the modulepath: variable in the source file attribute defines the source directory relative to module.
  • Change execution rights for the JVM.
  • Install the JVM into the /usr/java/jdk1.7.0_25 directory.
  • Change ownership of the JVM directory to user weblogic of the group oinstall.

The execute commands in the model is executed using sudo. The requirement for sudo depends on the privileges of the user used by the SSH plugin to connect to a given host. The users was defined in credentials file in the previous section.

Invoke Pineapple to execute model

Start your Pineapple client of choice:

  • Select the modules named ssh-005-install-jvm-rpm-linux64
  • Select the linux-vagrant model.
  • Invoke the deploy-configuration operation to install the JVM at the three nodes defines in the linux-vagrant environment.