Skip to content

Setting up the Development Environment

Pubudu Gunatilaka edited this page Apr 27, 2019 · 4 revisions

Follow these steps to setup the development environment to easily test a WSO2 product Puppet module.

Note: This is only for developing puppet modules and testing puppet modules locally. If you want to set up a Puppet environment with Puppet master and Puppet Agent for production environment, please follow this guide

Puppet Dev Vagrant Setup

Every product Puppet repo has a testing environment based on Vagrant. When the VM starts, it copies the Puppet folder located by the environment variable PUPPET_HOME to a location inside the VM and runs a puppet apply based on the given information. This information is specified in the config.yaml file and mainly includes,

  • Product name
  • Product version
  • Product profile
  • Product pattern
  • use_hieradata

The Vagrant testing environment can be found in the vagrant folder.

PUPPET_HOME

PUPPET_HOME is the location of where the Puppet modules exist. For example, in a typical Puppet Master, this is at /etc/puppet.

git clone https://github.com/wso2/puppet-common.git

# Run setup.sh as follows to setup testing environment for API Manager. (You need to provide an empty location as the PUPPET_HOME)
./setup.sh -p apim -v 2.1.0

# Do any modifications to Puppet modules if required.
# Copy jdk-8u112-linux-x64.tar.gz file to <PUPPET_HOME>/modules/wso2base/files/

cp jdk-8u112-linux-x64.tar.gz <PUPPET_HOME>/modules/wso2base/files/

# Copy WSO2 API Manager 2.1.0 zip file to <PUPPET_HOME>/modules/wso2am_runtime/files/ 

cp wso2am-2.1.0.zip <PUPPET_HOME>/modules/wso2am_runtime/files

# optional files like MySQL connector etc should also be copied
# cp mysql-connector-java-5.1.38.jar modules/wso2am_runtime/files/config/repository/components/lib/

config.yaml

  • config.yaml contains all the required information for the Dev environment.

  • servers section list down the puppet module that needs to be tested.

  • you can add more servers with the same structure

  • make it to false in enabled section if you do not want to spin a VM for that particular server.

  • You can use the following commands to spin VMs.

  • vagrant up : Will spin all the servers mentioned in the config.yaml (enabled flag should be true or not present)

  • vagrant up hostname : Will spin a server which has the mentioned hostname (eg : vagrant up dev-sandbox-apim.local.dev.wso2.org)

Ex: Testing WSO2 API Manager 2.1.0 on Puppet-Vagrant Setup
  • Prepare the WSO2 APIM module with the relevant packs and the configuration changes, at the PUPPET_HOME.
    • Copy wso2am-2.1.0.zip to <PUPPET_HOME>/modules/wso2am_runtime/files/ folder.
    • Copy jdk-8u112-linux-x64.tar.gz to <PUPPET_HOME>/modules/wso2base/files/ folder.
  • Open <PUPPET_COMMON>/vagrant/config.yaml and edit with the relevant details to look like the following.
  • export PUPPET_HOME=/your/puppet/home
---
servers:
  -
    enabled: true
    hostname: default
    facters:
      product_name: wso2am_runtime
      product_version: 2.1.0
      product_profile: default
      environment: dev
      platform: default
      use_hieradata: true
      pattern: pattern-0
    box: ubuntu/trusty64
    ip: 192.168.100.91
    ram: 2048
    cpu: 1
  • Navigate to the <PUPPET_COMMON>/vagrant/ directory and run the following command.
vagrant up
  • You will see an output similar to the following while Vagrant starts a VM with the Puppet provisioner. Wait until the Puppet modules are applied, and the Finished catalog run in xx.xx seconds message is displayed.
Provisioning VirtualBox with hostname: 
default
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'ubuntu/trusty64'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'ubuntu/trusty64' is up to date...
............
==> default: Setting the name of the VM: default
==> default: Clearing any previously set forwarded ports...
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
    default: Adapter 2: hostonly
==> default: Forwarding ports...
    default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Running 'pre-boot' VM customizations...
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: 
    default: Vagrant insecure key detected. Vagrant will automatically replace
    default: this with a newly generated keypair for better security.
    default: 
    default: Inserting generated public key within guest...
    default: Removing insecure key from the guest if it's present...
    default: Key inserted! Disconnecting and reconnecting using new SSH key...
==> default: Machine booted and ready!
==> default: Setting hostname...
==> default: Configuring and enabling network interfaces...
==> default: Rsyncing folder: /home/pubudu/WSO2/source-code/puppet/test-pp-apim/hieradata/ => /puppet/hieradata
==> default: Rsyncing folder: /home/pubudu/WSO2/source-code/puppet/test-pp-apim/files/ => /puppet/files
==> default: Rsyncing folder: /home/pubudu/WSO2/source-code/puppet/puppet-common/vagrant/ => /vagrant
==> default: Rsyncing folder: /home/pubudu/WSO2/source-code/puppet/puppet-common/manifests/ => /tmp/vagrant-puppet/manifests-f1cdacee9b482560d4b83aa22fd42992
==> default: Rsyncing folder: /home/pubudu/WSO2/source-code/puppet/test-pp-apim/modules/ => /tmp/vagrant-puppet/modules-2b3d88a89e773669abd3b9d83daa7dd9
==> default: Running provisioner: shell...
    default: Running: inline script
.............
==> default: Info: Creating state file /var/lib/puppet/state/state.yaml
==> default: Debug: Stored state in 0.02 seconds
==> default: Notice: Finished catalog run in 47.08 seconds
  • To destroy the test VM, simply run vagrant destroy -f.