Saturday, August 24, 2013

ACS acceptance.sql passes

Last week, the Ansible playbook created an 11.2g Oracle database that passed the ArsDigita SQL acceptance test.

Next up, building AOL server, then the Oracle driver and finally ACS.

Saturday, August 17, 2013

Setup Oracle 11.2g Virtualbox for Ansible

This is a follow-on to my last post, Creating a Vagrant box from Oracle 11.2g Virtualbox Appliance. It tells how to modify the Vagrant box so it is Ansible-ready.

Start up the base Virtualbox instance.

If you successfully got vagrant up to spin up a VirtualBox, you will see a new entry in the list that VirtualBox displays when it starts up (the bottom one in the screenshot below).

To get the Vagrant box to support Ansible, we need to modify the original one and then re-export it. In my case, the original box is called "oracle_11.2g", so I pick that one, click Start, and login as root (password = oracle).

Note:

One thing I found suprising about Vagrant is that an up/halt cycle of the vagrant box saves state. That is, if you

  1. vagrant up,
  2. install some software,
  3. vagrant halt, and then
  4. vagrant up again
the installed software is still there.

To restart from a blank state (say, if you want to retest your Ansible script from step 1), you need to delete the VirtualBox that Vagrant generates, then run vagrant up.

Install EPEL

The version of Oracle Linux that comes in the 11.2g appliance does not provide a Python version greater than 2.4. (I'm guessing Oracle built there's based on Centos 5.9). To get a more recent Python, you need to install "Extra Packages for Enterprise Linux". I followed How to Enable EPEL Repository for RHEL/CentOS 6/5

  1. Logged in as root, right click and select "Open Terminal".
  2. Get and install the package of EPEL GPG keys and repository information.
    [root@localhost ~]# wget http://download.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm
    --2013-08-16 06:43:58--  http://download.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm
    Resolving download.fedoraproject.org... 66.135.62.201, 67.203.2.67, 66.35.62.166, ...
    Connecting to download.fedoraproject.org|66.135.62.201|:80... connected.
    HTTP request sent, awaiting response... 302 FOUND
    Location: http://mirror.pnl.gov/epel/5/i386/epel-release-5-4.noarch.rpm [following]
    --2013-08-16 06:43:59--  http://mirror.pnl.gov/epel/5/i386/epel-release-5-4.noarch.rpm
    Resolving mirror.pnl.gov... 192.101.102.2
    Connecting to mirror.pnl.gov|192.101.102.2|:80... connected.
    HTTP request sent, awaiting response... 200 OK
    Length: 12232 (12K) [application/octet-stream]
    Saving to: `epel-release-5-4.noarch.rpm'
    
    100%[==============================>] 12,232      --.-K/s   in 0.09s   
    
    2013-08-16 06:44:00 (128 KB/s) - `epel-release-5-4.noarch.rpm' saved [12232/12232]
    
    [root@localhost ~]# rpm -ivh epel-release-5-4.noarch.rpm
    warning: epel-release-5-4.noarch.rpm: Header V3 DSA signature: NOKEY, key ID 217521f6
    Preparing...                ################################# [100%]
       1:epel-release           ################################# [100%]
    [root@localhost ~]# 
    

Install Python 2.6

# yum update
# yum install python26
# cd /usr/bin
# ln -sf python26 python
[root@localhost bin]# python -V
Python 2.6.8
#

Shut down the Virtualbox

# halt -p

Export the Box

We repeat the steps from the last log entry, except that we remove the old version before adding the new one.

$ cd ~/VirtualBox\ VMs/oracle_11.2g
$ rm package.box
$ vagrant package --base oracle_11.2g
[oracle_11.2g] Clearing any previously set forwarded ports...
[oracle_11.2g] Creating temporary directory for export...
[oracle_11.2g] Exporting VM...
[oracle_11.2g] Compressing package to: /Users/mark/VirtualBox VMs/oracle_11.2g/package.box
$ vagrant box remove oracle_11.2g
Removing box 'oracle_11.2g' with provider 'virtualbox'...
$ vagrant box add oracle_11.2g package.box
Downloading or copying the box...
Extracting box...te: 216M/s, Estimated time remaining: --:--:--)
Successfully added box 'oracle_11.2g' with provider 'virtualbox'!
$

Add static IP to Vagrant box

$ cd ~/src/cm3/ansible
$ vi Vagrantfile
...
$ cat Vagrantfile
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "oracle_11.2g"
  config.vm.network :private_network, ip: "192.168.67.10"
end
$ vagrant up
$ ping 192.168.67.10
PING 192.168.67.10 (192.168.67.10): 56 data bytes
64 bytes from 192.168.67.10: icmp_seq=0 ttl=64 time=1.071 ms
^C
--- 192.168.67.10 ping statistics ---
1 packets transmitted, 1 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 1.071/1.071/1.071/0.000 ms
$

Test to make sure ansible will connect on ssh

By default, Ansible ssh's in on the usual port.

$ ssh vagrant@192.168.67.10
vagrant@192.168.67.10's password:
Last login: Sat Aug 17 18:54:12 2013 from 192.168.67.1
[vagrant@localhost ~]$ exit

Simple Ansible command

Add the static IP of the Vagrant host as well as the ssh credentials to the Ansible hosts file

$ vi /etc/ansible/hosts
...
$ cat /etc/ansible/hosts
[vagrant]
192.168.67.10 ansible_ssh_user=vagrant ansible_ssh_pass=vagrant ansible_ssh_pass=vagrant
$

Hello World, in Ansible

$ cat playbook.yml
- hosts: vagrant
  sudo: yes
  tasks:
  - name: Test task.
    command: /bin/echo "Hello World!"
$

Action!

$ ansible-playbook playbook.yml

PLAY [vagrant] ***********************************************************

GATHERING FACTS **********************************************************
ok: [192.168.67.10]

TASK: [Test task.] *******************************************************
changed: [192.168.67.10]

PLAY RECAP ***************************************************************
192.168.67.10              : ok=2    changed=1    unreachable=0    failed=0

$
Next up ... we build an Ansible playbook to install AOLSever, start up Oracle and install ArsDigita Community System.

Wednesday, August 14, 2013

Creating a Vagrant box from Oracle 11.2g Virtualbox Appliance

I'm having a hell of a time trying to get a box up and running with v3 of ArsDigita Community System, the version described in the book Philip and Alex's Guide to Web Publishing.

My current plan is to create a Vagrant box with Oracle 11.2g and use Ansible to automate as much of the setup as possible.

Here are the best source code links I have found so far:

I've looked at OpenACS a bunch. I really wanted to use it as it would save me a ton of time, but I'm not a big fan. Their web site is hard to navigate, not all the ACS 3.0 modules were converted, and the focus of 4.0 seems to have shifted to bug tracking and CMS, which seems like a poor decision in retrospect. The quality of the ArsDigita documentation is so much better, and I expect the code, UX and data schemas will also be superior. So I'm going to try this route.

This blog entry documents step 1: creating the vagrant box from the Oracle Virtualbox appliance.

Create Oracle Virtualbox Instance

From a brief look at the Oracle store, it looks I could get a one-CPU perpetual license for Oracle for somewhere around $150. (In the ArsDigita Oracle install documentation, they say that Oracle would cost $40, and that is circa 2000. That's a 11% annual rate of increase, not bad!) In any case, Oracle is free for development uses.

  1. Apply for an OTN account.  You have to give Oracle your info (name, email, phone #, etc) to get an account.  Click the appliance download link and you'll get the login and register screen.
  2. Make sure you have a download manager, in case the download fails.  It's a 4 gig download.  (I used Download Them All.)
  3. Download the appliance: http://www.oracle.com/technetwork/database/enterprise-edition/databaseappdev-vm-161299.html
  4. Spin up Virtualbox, and pick "File -> Import Appliance", pick the Oracle_Developer_Day.ova file.  After a couple minutes, you have a new Virtualbox running Oracle Linux with 11.2g.

Vagrant setup

Add a vagrant user,

[oracle@localhost ~]$ su - root
Password: oracle
[root@localhost ~]# adduser vagrant
[root@localhost ~]# usermod -G wheel vagrant
[root@localhost ~]# passwd vagrant
Changing password for user vagrant.
New UNIX password:
BAD PASSWORD: it is based on a dictionary word
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
[root@localhost ~]#

let the vagrant user sudo without a password,

[root@localhost ~]# cp /etc/sudoers.orig /etc/sudoers
[root@localhost ~]# visudo
<
edits:
  * don't require TTY (so password-less sudo works via SSH)
  * don't require password for users in wheel group sudo 
>
[root@localhost ~]# diff /etc/sudoers /etc/sudoers.orig
56c56
< Defaults    requiretty
---
> # Defaults    requiretty
86c86
< # %wheel        ALL=(ALL)       NOPASSWD: ALL
---
> %wheel      ALL=(ALL)       NOPASSWD: ALL

install the vagrant public key,

Note: Oracle Linux certificate bundle does not come with the DigiCert one (see http://bugs.centos.org/view.php?id=4899). So we use the -k argument to tell curl it is OK to accept the "insecure" file from github.

[root@localhost ~]# curl -kL $h/keys/vagrant.pub > vagrant.pub
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   409  100   409    0     0    315      0  0:00:01  0:00:01 --:--:--  399k
[root@localhost ~]# mkdir ~vagrant/.ssh
[root@localhost ~]# cp vagrant.pub ~vagrant/.ssh/authorized_keys
[root@localhost ~]# chmod 700 ~vagrant/.ssh
[root@localhost ~]# chmod 600 ~vagrant/.ssh/authorized_keys 
[root@localhost ~]# chown vagrant.vagrant ~vagrant/.ssh
[root@localhost ~]# chown vagrant.vagrant ~vagrant/.ssh/authorized_keys 

and open port 2222 for SSH.

[root@localhost ~]# vi /etc/ssh/sshd_config 
...
Port 22
Port 2222
...

Export the Vagrant Box

In VirtualBox GUI, rename Oracle VM from "Oracle Developer Days" to "oracle_11.2g" (mainly cosmetic).  Then we package up the box and add it to Vagrant:

$ cd ~/VirtualBox\ VMs/oracle_11.2g
$ time vagrant package --base oracle_11.2g
[oracle_11.2g] Clearing any previously set forwarded ports...
[oracle_11.2g] Creating temporary directory for export...
[oracle_11.2g] Exporting VM...
[oracle_11.2g] Compressing package to: /Users/mark/VirtualBox VMs/oracle_11.2g/package.box

real 11m6.57s
user 5m3.42s
sys 0m6.07s
$ vagrant box add oracle_11.2g package.box
Successfully added box 'oracle_11.2g' with provider 'virtualbox'!
$

Spin up the Vagrant Box

$ cat > Vagrantfile
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "oracle_11.2g"
end
^D
$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
[default] Importing base box 'oracle_11.2g'...
[default] Matching MAC address for NAT networking...
[default] Setting the name of the VM...
[default] Clearing any previously set forwarded ports...
[default] Creating shared folders metadata...
[default] Clearing any previously set network interfaces...
[default] Preparing network interfaces based on configuration...
[default] Forwarding ports...
[default] -- 22 => 2222 (adapter 1)
[default] Booting VM...
[default] Waiting for VM to boot. This can take a few minutes.
[default] VM booted and ready for use!
[default] Mounting shared folders...
[default] -- /vagrant
The box should open without error. If there are problems, Vagrant shows you the stdout and stderr output, which should give you a clue as to the problem. To shut it down, type $ vagrant halt. Next up, configuring the server with Ansible.

Friday, August 2, 2013

Vagrant, Virtualbox and OpenBSD 5.3

  1. Create instance in VirtualBox
    1. Download 5.3 ISO.
    2. Open it as the CD when Virtualbox starts.
    3. Configure VM: network adapter = NAT, no audio.
    4. Install OpenBSD.
  2. Setup OS for vagrant:
    1. Set hostname to vagrant
      # cat vagrant > /etc/myname
      # hostname vagrant
      
    2. Use DHCP
      # echo dhcp > /etc/hostname.em0
      # rm -f /etc/resolv.conf
      
    3. Install bash, as vagrant assumes this is the shell.
      # pkg_add bash
      
    4. Install python for provisioning with ansible.
      # pkg_add python
      Ambiguous: choose package for python
       a       0: <None>
               1: python-2.5.4p18
               2: python-2.7.3p1
               3: python-3.2.3.p0
      Your choice: 2
      ...
      
    5. Add vagrant user and put in wheel group.
      # adduser vagrant  
      shell = bash
      group = vagrant
      password = vagrant
      ...
      # usermod -G wheel vagrant
      
    6. Let users in wheel group sudo without a password.
      # visudo
      [uncomment the line:]
      %wheel ALL=(ALL) NOPASSWD: SETENV: ALL
      
    7. Get vagrant SSH keys
      # export h=http://github.com/mitchellh/vagrant/raw/master
      # ftp $h/keys/vagrant -o vagrant
      # ftp $h/keys/vagrant.pub -o vagrant.pub
      # cp vagrant ~vagrant/.ssh
      # cp vagrant.put ~vagrant/.ssh/authorized_keys
      # chmod 0700 ~vagrant/.ssh
      # chmod 0640 ~vagrant/.ssh/authorized_keys
      # chmod 0640 ~vagrant/.ssh/vagrant
      
    8. Vagrant uses port 2222.
      # sudo vi /etc/ssh/sshd_config
      [uncomment Port 22 line and add Port 2222 line after that.]
      
  3. Package up the virtual box.
    1. Use a standard name for the box.
      - Open VirtualBox.
      - Settings --> General --> Basic
      - Set name to vagrant_openbsd_5.3
      
    2. Export box.
      $ cd ~/VirtualBox\ VMs/vagrant_openbsd_5.3
      $ rm -f package.box
      $ vagrant package --base vagrant_openbsd_5.3
      [vagrant_openbsd_5.3] Clearing any previously set forwarded ports...
      [vagrant_openbsd_5.3] Creating temporary directory for export...
      [vagrant_openbsd_5.3] Exporting VM...
      [vagrant_openbsd_5.3] Compressing package to: /Users/mark/VirtualBox VMs/vagrant_openbsd_5.3/package.box
      $
      
  4. Install the box into vagrant.
    $ vagrant box remove vagrant_openbsd_5.3 virtualbox
    $ vagrant box add vagrant_openbsd_5.3 package.box
    Downloading or copying the box...
    Extracting box...te: 439M/s, Estimated time remaining: --:--:--)
    Successfully added box 'vagrant_openbsd_5.3' with provider 'virtualbox'!
    $ vagrant box list
    openbsd             (virtualbox)
    vagrant_openbsd_5.3 (virtualbox)
    $
    
  5. Install vagrant-guests-openbsd. It's actively developed: Vagrant 1.2.7 was released on July 27, 2013 and the vagrant-guests-openbsd plugin was updated on August 3, 2013.
    $vagrant plugin install vagrant-guests-openbsd
    
  6. Setup Vagrantfile. Using , as it provides better than what comes with Vagrant.
    # -*- mode: ruby -*-
    # vi: set ft=ruby :
    
    VAGRANTFILE_API_VERSION = "2"
    
    Vagrant.require_plugin "vagrant-guests-openbsd"
    
    Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
    
      # Every Vagrant virtual environment requires a box to build off of.
      config.vm.box = "vagrant_openbsd_5.3"
    
      # 
      config.vm.guest = :openbsd_v2
      
      config.vm.synced_folder "../", "/vagrant", :disabled => true
      #config.vm.synced_folder "../", "/vagrant", :nfs => true
    
      config.vm.network :private_network, ip: "192.168.67.10", netmask: "255.255.255.0"
    
      # Uncomment to debug.
      #config.vm.provider "virtualbox" do |v|
      #  v.gui = true
      #end
    
    end
    
  7. Use it.
    $ time vagrant up
    Bringing machine 'default' up with 'virtualbox' provider...
    [default] Setting the name of the VM...
    [default] Clearing any previously set forwarded ports...
    [default] Creating shared folders metadata...
    [default] Clearing any previously set network interfaces...
    [default] Preparing network interfaces based on configuration...
    [default] Forwarding ports...
    [default] -- 22 => 2222 (adapter 1)
    [default] Booting VM...
    [default] Waiting for VM to boot. This can take a few minutes.
    [default] VM booted and ready for use!
    [default] No guest additions were detected on the base box for this VM! Guest
    additions are required for forwarded ports, shared folders, host only
    networking, and more. If SSH fails on this machine, please install
    the guest additions and repackage the box to continue.
    
    This is not an error message; everything may continue to work properly,
    in which case you may ignore this message.
    [default] Mounting shared folders...
    
    real  0m51.05s
    user  0m1.46s
    sys 0m0.55s
    
    
    $ vagrant ssh
    Last login: Fri Aug  2 15:39:10 2013 from 10.0.2.2
    OpenBSD 5.3 (GENERIC) #50: Tue Mar 12 18:35:23 MDT 2013
    
    Welcome to OpenBSD: The proactively secure Unix-like operating system.
    
    Please use the sendbug(1) utility to report bugs in the system.
    Before reporting a bug, please try to reproduce it with the latest
    version of the code.  With bug reports, please try to ensure that
    enough information to reproduce the problem is enclosed, and if a
    known fix for it exists, include that as well.
    
    $ whoami
    vagrant
    $ hostname
    vagrant
    $ exit
    Connection to 127.0.0.1 closed.
    
    
    $ time vagrant halt
    [default] Attempting graceful shutdown of VM...
    
    real  0m14.15s
    user  0m1.23s
    sys 0m0.50s
    $