galaxyproject / ansible-cloudman-image

An Ansible role for building a machine image for CloudMan.
https://galaxy.ansible.com/list#/roles/2747
MIT License
8 stars 5 forks source link

This Ansible role is for building the machine image required to run CloudMan. It is likely to be used in the context of the Galaxy on the Cloud playbook.

Requirements

The role has been developed and tested on Ubuntu 16.04. It requires sudo access.

Dependencies

This role leverages Oracle Java on the target system and uses smola.java role for this purpose. It also uses galaxyprojectdotorg.galaxy-os role. To satisfy these requirements it is necessary to install the required roles with the following commands (this will download the given roles from Ansible Galaxy and place them in roles subdirectory; unfortunately, Ansible does not have an option to have this done automatically):

$ ansible-galaxy install smola.java -p roles
$ ansible-galaxy install galaxyprojectdotorg.galaxy-os -p roles

Additionally, if targeting AWS instances, it is required to install boto (v2) and awscli Python packages as well as export the following environment vars with their appropriate values: EC2_REGION, AWS_ACCESS_KEY, AWS_SECRET_KEY. If you have multiple profiles defined for your aws command (i.e., in ~/aws/credentials) and you don't want to use the default one, also do export AWS_PROFILE=<profile name>. The target instance will need to have an elastic IP associated with it and you will also need to set the path to your Python interpreter in the inventory file under the localhost host definition:

[localhost]
127.0.0.1 ansible_python_interpreter=/usr/local/bin/python

Role variables

All of the listed variabls are stored in defaults/main.yml. Check that file for all the available variables.

Individual variables can be set or overridden by setting them directly in a playbook for this role (see an example below for vnc_password). Alternatively, they can be set by creating group_vars directory in the root directory of the playbook used to execute this role and placing a file with the variables there. Note that the name of this file must match the value of hosts setting in the corresponding playbook (e.g., image-builder for the sample playbook provided below).

Required variables

Optional variables

Control flow variables

The following variables can be set to either yes or no to indicate if the given part of the role should be executed:

Example playbook

To use the role, it is necessary to launch a cloud instance, create a hosts file that contains access information for the instance, for example:

[image-builder]
130.56.250.204 ansible_ssh_private_key_file=key.pem ansible_ssh_user=ubuntu

[localhost]
127.0.0.1 ansible_python_interpreter=/usr/local/bin/python

Next, set any variables as desired and place the role into a playbook file (e.g., playbook.yml). This playbook assumes the role has been placed into roles/galaxyprojectdotorg.cloudman-image directory:

- hosts: image-builder
  sudo: yes
  roles:
    - galaxyprojectdotorg.cloudman-image
      vnc_password: <some_password>
      psql_galaxyftp_password: <a_different_password>

Finally, run the playbook with:

$ ansible-playbook playbook.yml -i hosts [--extra-vars cleanup=yes]

NOTE: setting the cleanup variable will disable ssh access to the current instance! While this is not set as the default value, an instance must be cleaned before creating an image.

Upon completion, an image can be create using the cloud console.