Create a Couchbase Cluster with Ansible
Join the DZone community and get the full member experience.
Join For Free[This blog was syndicated from http://blog.grallandco.com]
Introduction
Ansible
Create a Couchbase Cluster
- Install Couchbase on each nodes of the cluster, as documented here.
- Take one of the node and "initialize" the cluster, using cluster-init command.
- Add the other nodes to the cluster, using server-add command.
- Rebalance, using rebalance command.
- Create a Bucket, using bucket-create command.
Ansible Playbook for Couchbase
[couchbase-main] vm1.grallandco.com [couchbase-nodes] vm2.grallandco.com vm3.grallandco.com
# Adminisrator user and password admin_user: Administrator admin_password: password # ram quota for the cluster cluster_ram_quota: 1024 # bucket and replicas bucket_name: ansible bucket_ram_quota: 512 num_replicas: 2
- name: Couchbase Installation hosts: all user: root tasks: - name: download Couchbase package get_url: url=http://packages.couchbase.com/releases/2.0.1/couchbase-server-enterprise_x86_64_2.0.1.deb dest=~/. - name: Install dependencies apt: pkg=libssl0.9.8 state=present - name: Install Couchbase .deb file on all machines shell: dpkg -i ~/couchbase-server-enterprise_x86_64_2.0.1.deb
- Download the product, the get_url command will only download the file if not already present
- Install the dependencies with the apt command, the state=present allows the system to only install this package if not already present
- Install Couchbase with a simple shell command. (here I am not checking if Couchbase is already installed)
- name: Initialize the cluster and add the nodes to the cluster hosts: couchbase-main user: root tasks: - name: Configure main node shell: /opt/couchbase/bin/couchbase-cli cluster-init -c 127.0.0.1:8091 --cluster-init-username=${admin_user} --cluster-init-password=${admin_password} --cluster-init-port=8091 --cluster-init-ramsize=${cluster_ram_quota} - name: Create shell script for configuring main node action: template src=couchbase-add-node.j2 dest=/tmp/addnodes.sh mode=750 - name: Launch config script action: shell /tmp/addnodes.sh - name: Rebalance the cluster shell: /opt/couchbase/bin/couchbase-cli rebalance -c 127.0.0.1:8091 -u ${admin_user} -p ${admin_password} - name: create bucket ${bucket_name} with ${num_replicas} replicas shell: /opt/couchbase/bin/couchbase-cli bucket-create -c 127.0.0.1:8091 --bucket=${bucket_name} --bucket-type=couchbase --bucket-port=11211 --bucket-ramsize=${bucket_ram_quota} --bucket-replica=${num_replicas} -u ${admin_user} -p ${admin_password}
- Initialization of the cluster using the Couchbase CLI, on line 06 and 07
{% for host in groups['couchbase-nodes'] %} /opt/couchbase/bin/couchbase-cli server-add -c 127.0.0.1:8091 -u ${admin_user} -p ${admin_password} --server-add={{ hostvars[host]['ansible_eth0']['ipv4']['address'] }}:8091 --server-add-username=${admin_user} --server-add-password=${admin_password} {% endfor %}
./bin/ansible-playbook -i ./couchbase/hosts ./couchbase/couchbase.yml -vv

./bin/ansible-playbook -i ./couchbase/hosts ./couchbase/couchbase-uninstall.yml
Published at DZone with permission of Don Pinto, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Comments