Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python cassandra installer #2

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
# ansible-cassandra
# Cassandra Database

Install [Cassandra](http://cassandra.apache.org/) database

## Role Variables

##Optional

## License

Apache License, Version 2.0
95 changes: 95 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
---

# Cassandra release history
# 2.1.8 2015-07-09
# 2.1.9 2015-08-28
# 2.2.0 2015-07-21
# 2.2.1 2015-09-01
# 3.0.0 2015-08-28

cassandra_version: 2.2.1
cassandra_install_dir: /usr/local/etc
cassandra_log_dir: /var/log/cassandra
cassandra_data_root_dir: /app/cassandra
cassandra_link: "{{ cassandra_install_dir }}/cassandra"
cassandra_log_file: "{{ cassandra_log_dir }}/cassandra.log"
cassandra_owner: cassandra # do not confuse with cassandra_user (db username)
cassandra_group: cassandra
cassandra_num_tokens: 256
cassandra_cluster_name: monasca
cassandra_initial_token: " " # in case of cluster must be calculated
cassandra_endpoint_snitch: "SimpleSnitch" # in case of cluster: RackInferringSnitch
cassandra_hinted_handoff_enabled: true
cassandra_max_hint_window_in_ms: 10800000 # 10,800,000 = 3 hours
cassandra_hinted_handoff_throttle_in_kb: 1024
cassandra_max_hints_delivery_threads: 2
cassandra_authenticator: AllowAllAuthenticator
cassandra_authorizer: AllowAllAuthorizer
cassandra_permissions_validity_in_ms: 2000
cassandra_partitioner: org.apache.cassandra.dht.Murmur3Partitioner
cassandra_disk_failure_policy: stop
cassandra_key_cache_size_in_mb: " "
cassandra_key_cache_save_period: 14400
cassandra_row_cache_size_in_mb: 0
cassandra_row_cache_save_period: 0
cassandra_memory_allocator: NativeAllocator
cassandra_row_cache_provider: SerializingCacheProvider
cassandra_commitlog_sync: periodic
cassandra_commitlog_sync_period_in_ms: 10000
cassandra_commitlog_segment_size_in_mb: 32
cassandra_concurrent_reads: 32
cassandra_concurrent_writes: 32
cassandra_trickle_fsync: false
cassandra_trickle_fsync_interval_in_kb: 10240
cassandra_storage_port: 7000
cassandra_ssl_storage_port: 7001
cassandra_start_native_transport: true
cassandra_native_transport_port: 9042
cassandra_start_rpc: true
cassandra_rpc_port: 9160
cassandra_rpc_keepalive: true
cassandra_rpc_server_type: sync
cassandra_thrift_framed_transport_size_in_mb: 15
cassandra_incremental_backups: false
cassandra_snapshot_before_compaction: false
cassandra_auto_snapshot: true
cassandra_column_index_size_in_kb: 64
cassandra_compaction_throughput_mb_per_sec: 16
cassandra_read_request_timeout_in_ms: 10000
cassandra_range_request_timeout_in_ms: 10000
cassandra_write_request_timeout_in_ms: 10000
cassandra_counter_write_request_timeout_in_ms: 10000
cassandra_cas_contention_timeout_in_ms: 1000
cassandra_truncate_request_timeout_in_ms: 60000
cassandra_request_timeout_in_ms: 10000
cassandra_dynamic_snitch_update_interval_in_ms: 100
cassandra_dynamic_snitch_reset_interval_in_ms: 600000
cassandra_cross_node_timeout: false
cassandra_dynamic_snitch_badness_threshold: 0.1
cassandra_request_scheduler: org.apache.cassandra.scheduler.NoScheduler
cassandra_internode_compression: all
cassandra_inter_dc_tcp_nodelay: true
cassandra_auto_bootstrap: false
cassandra_max_heap_size:
cassandra_heap_newsize:

#-- Cassandra Opscenter Agent (process running on each Cassandra node)

ops_agent_home_dir: "{{ cassandra_link }}"
ops_agent_link: "{{ cassandra_link }}/ops-agent"
ops_agent_log_file: "{{ cassandra_log_file }}/cassandra-ops-agent.log"

#-- Cassandra Opscenter (web admin interface)

opscenter_basename: opscenter
opscenter_version: 5.1.3
opscenter_install_dir: "{{ install_dir }}"
opscenter_agent_basename: "datastax-agent-{{ opscenter_version }}"
opscenter_agent_fname: "datastax-agent-{{ opscenter_version }}.tar.gz"
opscenter_agent_url: "http://downloads.datastax.com/community/datastax-agent-{{ opscenter_version }}.tar.gz"
opscenter_home_dir: "{{ install_dir }}/{{ opscenter_basename }}-{{ opscenter_version }}"
opscenter_home_link: "{{ install_dir }}/{{ opscenter_basename }}"
opscenter_log_file: "{{ log_dir }}/{{ opscenter_basename }}/{{ opscenter_basename }}.log"
opscenter_log_dir: "{{ log_dir }}/{{ opscenter_basename }}"
opscenter_owner: www-data
opscenter_group: www-data
15 changes: 15 additions & 0 deletions handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---

# we moved these handlers to tasks at the end of the install tasks for better timing and control
# of their execution

#- name: reload supervisor on change
# shell: supervisorctl reread && supervisorctl update
# when: (supervisor_reload|changed) # supervisor is register variable
#
#- name: restart supervisor on change
# shell: service supervisor stop && service supervisor start
# when: (supervisor_restart|changed) # supervisor is register variable

#- name: restart cassandra
# supervisorctl: name=cassandra state=restarted
17 changes: 17 additions & 0 deletions meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
galaxy_info:
author: Michael Bielinski
description: Install Cassandra Database - Originally based on the version by Pjan Vandaele
license: MIT
min_ansible_version: 1.3
platforms:
- name: Ubuntu
versions:
- all
- name: Debian
versions:
- all
categories:
- database
- database:nosql
dependencies: []
52 changes: 52 additions & 0 deletions tasks/_ops_agent.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---

- name: download the cassandra agent in /tmp if not yet present
command: >
wget {{ opscenter_agent_url }}
chdir=/tmp
creates=/tmp/{{ opscenter_agent_fname }}

- name: expand the cassandra agent in the install dir
command: >
tar -xvzf /tmp/{{ opscenter_agent_fname }}
chdir={{ ops_agent_home_dir }}
creates={{ ops_agent_home_dir }}/{{ opscenter_agent_basename }}

- name: update the cassandra agent permissions
file: >
path={{ ops_agent_home_dir }}/{{ opscenter_agent_basename }}
owner={{ cassandra_owner }}
group={{ cassandra_group }}
state=directory recurse=yes

- name: create a symbolic link to the agent
file: >
path={{ ops_agent_link }}
src={{ ops_agent_home_dir }}/{{ opscenter_agent_basename }}
state=link
force=yes

- name: configure ip address of ops center
lineinfile: >
dest="{{ ops_agent_link }}/conf/address.yaml"
create=yes
regexp='^(stomp_interface.*)$'
line="stomp_interface: {{ cassandra_opscenter_host }}"

- name: supervisor init script
template: >
src=etc_init.d_cassandra-ops-agent.sh.j2
dest=/etc/init.d/cassandra-ops-agent.sh
owner=root
group=root
mode=0755
register: supervisor_reload

- name: supervisor config script
template: >
src=etc_supervisor.d_cassandra-ops-agent.conf.j2
dest=/etc/supervisor/conf.d/cassandra-ops-agent.conf
owner=root
group=root
mode=0644
register: supervisor_reload
34 changes: 34 additions & 0 deletions tasks/_supervise.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
- name: install supervisord
apt: pkg=supervisor state=installed

- name: ensure supervisord is running and enabled
service: name=supervisor state=started enabled=yes

- name: add supervisord config file
template: >
src=supervisord.conf.j2
dest=/etc/supervisor/supervisord.conf
owner=root
group=root
mode=0644
register: supervisor_restart

- name: supervisor init script
template: >
src=etc_init.d_cassandra.sh.j2
dest=/etc/init.d/cassandra.sh
owner=root
group=root
mode=0755
register: supervisor_reload

- name: install the supervisord cassandra script
template: >
src=etc_supervisor.d_cassandra.conf.j2
dest=/etc/supervisor/conf.d/cassandra.conf
owner=root
group=root
mode=0644
register: supervisor_reload

16 changes: 16 additions & 0 deletions tasks/configure.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
- name: Update the cassandra configuration
template: >
src=conf_{{ item }}.{{cassandra_version}}.j2
dest={{ cassandra_link }}/conf/{{ item }}
owner={{ cassandra_owner }}
group={{ cassandra_group }}
mode=0644
with_items:
- cassandra.yaml
- cassandra-env.sh
register: restart_cassandra

- name: restart cassandra
supervisorctl: name=cassandra state=restarted
when: (restart_cassandra|changed)
97 changes: 97 additions & 0 deletions tasks/install.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
---
- name: Create group
group: name={{ cassandra_group }} system=yes

- name: Create user
user: name={{ cassandra_owner }} system=yes group={{ cassandra_group }}

- name: Create download directory
file: path="{{ download_tmp_dir }}" state=directory recurse=yes

- name: Fetch
get_url: url=http://archive.apache.org/dist/cassandra/{{ cassandra_version }}/apache-cassandra-{{ cassandra_version }}-bin.tar.gz
dest={{ download_tmp_dir }}/apache-cassandra-{{ cassandra_version }}-bin.tar.gz
register: get_url_result
until: get_url_result.state == 'file'
retries: 5
delay: 1

- name: Expand to the install directory
unarchive: >
src={{ download_tmp_dir }}/apache-cassandra-{{ cassandra_version }}-bin.tar.gz
dest={{ cassandra_install_dir }}
copy=no

- name: Update the owner and group
file: >
path={{ cassandra_install_dir }}/apache-cassandra-{{ cassandra_version }}
owner={{ cassandra_owner }}
group={{ cassandra_group }}
state=directory recurse=yes

- name: Create a symbolic link
file: path={{ cassandra_link }} src={{ cassandra_install_dir }}/apache-cassandra-{{ cassandra_version }} state=link force=yes

- name: Create the data directory
file: >
path={{ cassandra_data_root_dir }}
owner={{ cassandra_owner }}
group={{ cassandra_group }}
mode=0750
state=directory

- name: Create the working subdirectories
file: >
path={{ cassandra_data_root_dir }}/{{ item }}
owner={{ cassandra_owner }}
group={{ cassandra_group }}
mode=0750
state=directory
with_items:
- data
- commitlog
- saved_caches

- name: Create local log directory
file: >
path={{ cassandra_link }}/logs
owner={{ cassandra_owner }}
group={{ cassandra_group }}
recurse=yes
mode=0755
state=directory

- name: Link log directory to local log directory
file: >
src={{ cassandra_link }}/logs
dest={{ cassandra_log_dir }}
owner={{ cassandra_owner }}
group={{ cassandra_group }}
state=link

- name: Create accessible links to commands
file: >
src={{ cassandra_link }}/bin/{{ item }}
dest=/usr/bin/{{ item }}
owner=root
group=root
state=link
with_items:
- cassandra
- cqlsh
- cqlsh.py
- nodetool
- debug-cql

- include: _supervise.yml
- include: _ops_agent.yml

# these are normally in the handlers, but we want execution to happen at this point, not at a later time

- name: reload supervisor on change
shell: supervisorctl reread && supervisorctl update
when: (supervisor_reload|changed)

- name: restart supervisor on change
shell: service supervisor stop && service supervisor start
when: (supervisor_restart|changed)
13 changes: 12 additions & 1 deletion tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
---
---
- include: stop.yml
when: run_mode == 'Stop'

- include: install.yml
when: not skip_install and ( run_mode == 'Install' or run_mode == 'Deploy' )

- include: configure.yml
when: run_mode == 'Configure' or run_mode == 'Deploy'

- include: start.yml
when: run_mode == 'Start' or run_mode == 'Deploy'
7 changes: 7 additions & 0 deletions tasks/start.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
- name: Enable and start cassandra
supervisorctl: name=cassandra state=started

- name: wait for cassandra port
wait_for: port={{ cassandra_native_transport_port }} host={{ cassandra_bind_address | default('127.0.0.1') }} state=started timeout=180
register: first_wait
3 changes: 3 additions & 0 deletions tasks/stop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
- name: Stop cassandra
supervisorctl: name=cassandra state=stopped
Loading