chouseknecht.cluster-up-role

Build Status

cluster-up-role

This role helps you install the OpenShift client and create a local OpenShift instance using oc cluster up. It is designed for demo and testing purposes for Ansible Container by automating the steps found in the Install and Configure OpenShift guide.

It specifically does the following:

  • Downloads and installs the OpenShift Client (oc)
  • Installs socat if you're on OSX
  • Adds a hostname linked to your public IP address to the /etc/hosts file
  • Starts the OpenShift cluster
  • Provides admin access to the developer account
  • Creates a route to make the local registry accessible
  • Sets up a persistent volume
  • Logs into the cluster as developer using the oc client and sets the project to default

Supported platforms and testing

Currently, this role has mainly been tested on OSX using Docker for Mac. It works almost on Travis, which runs on Ubuntu. If you try using it on anything other than OSX, you might find some bugs. If you do, please report them or submit a pull request so we can keep improving the role.

Hostname

By default, the hostname local.openshift is added to your /etc/hosts file, linking it to your current IP address. You can change this by using the openshift_hostname parameter if you want a different name.

When the cluster is created, it's linked to your local network IP. If you're using a laptop or mobile device, you’ll likely need to recreate the cluster whenever you switch networks. Linking a hostname to your actual IP address makes this easier.

Insecure registry

If you haven't set the insecure registry option in Docker, the role will fail the first time you run it. It will show a message telling you which subnet to add. You'll also need to set the openshift_hostname value, which defaults to local.openshift. After making those changes and restarting Docker, run the role again, and it should work.

Prerequisites

You need the following installed:

  • Docker Engine or Docker for Mac
  • sudo access to update /etc/hosts and install the oc binary to /usr/local/bin.

NOTE: If you’re using Linux, please follow the create a docker group instructions to run docker commands without using sudo.

Example Playbook

When using the role, make sure to set gather_facts to true. This allows the role to determine the host IP address and OS family.

Here’s a sample playbook with all default settings. You can find this exact example in files/cluster-up.yml. Copy and modify it for your setup:

    ---
    - hosts: localhost
      remote_user: root
      connection: local
      gather_facts: yes
      roles:
        - role: chouseknecht.cluster-up-role
          openshift_github_user: openshift
          openshift_github_name: origin
          openshift_github_url: https://api.github.com/repos
          openshift_release_tag_name: ""
          openshift_client_dest: /usr/local/bin  
          openshift_force_client_install: yes
          openshift_volume_name: project-data
          openshift_volume_path: "{{ lookup('env','HOME') }}/volumes/project/data"
          openshift_hostname: local.openshift
          openshift_recreate: yes

After installing the role, copy file/cluster-up.yml to your project directory and run it using the --ask-sudo-pass option. Here’s how:

# Install the role 
$ ansible-galaxy install chouseknecht.cluster-up-role

# Copy the playbook to the current directory 
$ cp ${ANSIBLE_ROLES_PATH}/chouseknecht.cluster-up-role/files/cluster-up.yml .

# Create a localhost inventory file
$ echo "localhost">./inventory

# Run the playbook
$ ansible-playbook -i inventory --ask-sudo-pass cluster-up.yml

Deploying your Ansible Container project

Next, we will create a new project, install the Container Enabled role jenkins-container, and launch the Jenkins service in our local OpenShift cluster.

NOTE: To follow this example, you need Ansible Container version 0.3.0. Refer to Installing from Source for guidance.

# Create a new project folder
$ mkdir jenkins

# Navigate into the project folder
$ cd jenkins

# Initialize the project
$ ansible-container init

# Install the jenkins-container role
$ ansible-container install awasilyev.jenkins-container

# Build the images
$ ansible-container build

# Create the deployment playbook and role
$ ansible-container shipit openshift --local-images

# Move into the ansible directory
$ cd ansible

# Run the shipit playbook
$ ansible-playbook shipit-openshift.yml

This creates a new project called jenkins on OpenShift. To view it, log into the OpenShift console at https://local.openshift:8443/console using the username and password both set to developer. Click on jenkins to see the project overview.

Watch a video on deploying Jenkins by clicking the image below:

Deploy Jenkins

Role Variables

You can change how the role behaves using these variables:

  • openshift_github_user: Default is openshift - the owner of the GitHub repo where the oc client can be downloaded.
  • openshift_github_name: Default is origin - the name of the GitHub repo.
  • openshift_github_url: Default is https://api.github.com/repos - GitHub API address.
  • openshift_release_tag_name: Empty by default - the specific release tag for the oc binary.
  • openshift_client_dest: Default is /usr/local/bin - where oc will be installed (needs to be in your PATH).
  • openshift_force_client_install: Default is yes - should it replace the existing oc binary?
  • openshift_volume_name: Default is project-data - the name of the volume.
  • openshift_volume_path: Default is {{ lookup('env','HOME') }}/volumes/project/data - local path for the new volume.
  • openshift_hostname: Default is local.openshift - the hostname to refer to the local registry when pushing images.
  • openshift_recreate: Default is yes - should it recreate the cluster if it’s already running?
  • openshift_up_options: Any additional options for oc cluster up, separated by spaces.

Dependencies

None

License

Apache v2

Author

@chouseknecht

Informazioni sul progetto

Install the latest oc client and create a local OpenShift cluster using `oc cluster up`.

Installa
ansible-galaxy install chouseknecht.cluster-up-role
Licenza
apache-2.0
Download
159
Proprietario
Ansible Galaxy Engineering Manager