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

chore: Fix cassandra deploy scripts #995

Merged
merged 4 commits into from
Nov 14, 2023
Merged
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
2 changes: 1 addition & 1 deletion recipes/newrelic/infrastructure/ohi/cassandra/debian.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ install:
HOSTNAME: {{.NR_CLI_DB_HOSTNAME}}
CONFIG_PATH: /etc/cassandra/cassandra.yaml
REMOTE_MONITORING: true
inventory_source: config/redis
inventory_source: config/cassandra
interval: 60
EOT

Expand Down
6 changes: 3 additions & 3 deletions recipes/newrelic/infrastructure/ohi/cassandra/rhel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ install:
sudo cp /etc/newrelic-infra/integrations.d/cassandra-config.yml.sample /etc/newrelic-infra/integrations.d/cassandra-config.yml;

- |
sudo tee -a /etc/newrelic-infra/integrations.d/cassandra-config.yml > /dev/null <<"EOT"
sudo tee /etc/newrelic-infra/integrations.d/cassandra-config.yml > /dev/null <<"EOT"
integrations:
- name: nri-cassandra
env:
Expand All @@ -122,9 +122,9 @@ install:
env:
INVENTORY: true
HOSTNAME: {{.NR_CLI_DB_HOSTNAME}}
CONFIG_PATH: /etc/cassandra/cassandra.yaml
CONFIG_PATH: /etc/cassandra/conf/cassandra.yaml
REMOTE_MONITORING: true
inventory_source: config/redis
inventory_source: config/cassandra
interval: 60
EOT

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
- debug:
msg: Install Cassandra
msg: Configure

- name: Set default create_newrelic_user (default not create)
set_fact:
Expand All @@ -12,69 +12,42 @@
create_env_var: "false"
when: create_env_var is undefined

- name: Get latest packages info
shell: "apt-get update -y"
# By default JMX security is disabled.
- name: Require authentication
become: true
ansible.builtin.lineinfile:
path: /etc/cassandra/cassandra-env.sh
regexp: "jmxremote.authenticate=false"
line: ' JVM_OPTS="$JVM_OPTS -Dcom.sun.management.jmxremote.authenticate=true"'

- name: Install dependiences
shell: sudo apt install apt-transport-https ca-certificates wget dirmngr gnupg software-properties-common -y
- name: Configure access file
become: true
ansible.builtin.lineinfile:
path: /etc/cassandra/cassandra-env.sh
regexp: "jmxremote.access.file"
line: JVM_OPTS="$JVM_OPTS -Dcom.sun.management.jmxremote.access.file=/etc/cassandra/jmxremote.access"

- name: Get java keys
shell: wget -qO - https://adoptopenjdk.jfrog.io/adoptopenjdk/api/gpg/key/public | sudo apt-key add -
- name: Add passwords file
become: true
ansible.builtin.copy:
dest: /etc/cassandra/jmxremote.password
content: |
cassandra cassandra
newrelic Virtuoso4all!

- name: Get java repo
shell: sudo add-apt-repository --yes https://adoptopenjdk.jfrog.io/adoptopenjdk/deb/
become: yes

- name: update packages
shell: apt-get update -y
become: yes

- name: install java
shell: sudo apt install adoptopenjdk-8-hotspot -y
become: yes

- name: add cassandra keys
shell: wget -q -O - https://www.apache.org/dist/cassandra/KEYS | sudo apt-key add -
become: yes

- name: add cassandra repo
shell: sudo sh -c 'echo "deb https://www.apache.org/dist/cassandra/debian 311x main" > /etc/apt/sources.list.d/cassandra.list'
become: yes

- name: update packages
shell: apt-get update -y
become: yes

- name: install cassandra
shell: apt install cassandra -y
become: yes

- name: Allow to create user
shell: "sudo sed -i 's/authenticator: AllowAllAuthenticator/authenticator: PasswordAuthenticator/g' /etc/cassandra/cassandra.yaml"
become: yes

- name: restart cassandra
shell: systemctl restart cassandra
become: yes

- name: Ensure Cassandra is ready to accept query
shell: cqlsh localhost 9042 -ucassandra -pcassandra -e "SELECT dateof(now()) FROM system.local ;"
register: output
retries: 20
delay: 15
until: output is not failed

- fail:
msg: "Cassandra is not available, details: {{output}}"
when: output is failed
- name: Add access file
become: true
ansible.builtin.copy:
dest: /etc/cassandra/jmxremote.access
content: |
cassandra readwrite
newrelic readonly

- name: Create newrelic login
shell: cqlsh localhost 9042 -ucassandra -pcassandra -e "CREATE USER newrelic WITH PASSWORD 'Virtuoso4all!';"
become: yes
when: create_newrelic_user|bool
- name: Restart Cassandra
become: true
ansible.builtin.systemd:
name: cassandra
state: restarted

- block:
- name: Export USERNAME
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
- debug:
msg: Install Cassandra

- name: Add cassandra repo
shell: echo "deb https://debian.cassandra.apache.org 41x main" | sudo tee -a /etc/apt/sources.list.d/cassandra.sources.list
become: true

- name: add cassandra keys
shell: wget -q -O - https://www.apache.org/dist/cassandra/KEYS | sudo apt-key add -
become: true

- name: Install cassandra
ansible.builtin.apt:
name: cassandra
update_cache: yes
become: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
- debug:
msg: Install dependencies

- name: Update repository cache and install packages
ansible.builtin.apt:
pkg:
- apt-transport-https
- ca-certificates
- wget
- dirmngr
- gnupg
- software-properties-common
- wget
update_cache: true
become: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
- include_tasks: installDependencies.yml
- include_tasks: installCassandra.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
- debug:
msg: Configure

- name: Set default create_newrelic_user (default not create)
set_fact:
create_newrelic_user: "false"
when: create_newrelic_user is undefined

- name: Set default create_env_var (default not create)
set_fact:
create_env_var: "false"
when: create_env_var is undefined

# By default JMX security is disabled.
- name: Require authentication
become: true
ansible.builtin.lineinfile:
path: /etc/cassandra/conf/cassandra-env.sh
regexp: "jmxremote.authenticate=false"
line: ' JVM_OPTS="$JVM_OPTS -Dcom.sun.management.jmxremote.authenticate=true"'

- name: Configure access file
become: true
ansible.builtin.lineinfile:
path: /etc/cassandra/conf/cassandra-env.sh
regexp: "jmxremote.access.file"
line: JVM_OPTS="$JVM_OPTS -Dcom.sun.management.jmxremote.access.file=/etc/cassandra/jmxremote.access"

- name: Add passwords file
become: true
ansible.builtin.copy:
dest: /etc/cassandra/jmxremote.password
content: |
cassandra cassandra
newrelic Virtuoso4all!

- name: Add access file
become: true
ansible.builtin.copy:
dest: /etc/cassandra/jmxremote.access
content: |
cassandra readwrite
newrelic readonly

- name: Restart Cassandra
become: true
ansible.builtin.systemd:
name: cassandra
state: restarted
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
- debug:
msg: Install Cassandra

- name: Add Cassandra repo
become: true
ansible.builtin.blockinfile:
create: true
path: /etc/yum.repos.d/cassandra.repo
block: |
[cassandra]
name=Apache Cassandra
baseurl=https://redhat.cassandra.apache.org/41x/noboolean
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://downloads.apache.org/cassandra/KEYS

- name: Install Cassandra
become: true
ansible.builtin.yum:
name: cassandra
update_cache: true
state: present

- name: Start Cassandra
become: true
ansible.builtin.systemd:
name: cassandra
enabled: true
state: started
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
- debug:
msg: Install dependencies

- name: Update repository cache and install packages
ansible.builtin.yum:
name:
- curl
- wget
update_cache: true
become: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
- debug:
msg: Install Java

- name: Install Java
become: true
ansible.builtin.yum:
name: java-1.8.0-openjdk-devel
update_cache: true
state: present

- name: Add JAVA_HOME env root
shell: "echo 'export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk' >> ~/.bashrc"
become: true
- name: Add JAVA_HOME env user
shell: "echo 'export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk' >> ~/.bashrc"

- name: Add JRE_HOME env root
shell: "echo 'export JRE_HOME=/usr/lib/jvm/java-1.8.0-openjdk/jre' >> ~/.bashrc"
become: true
- name: Add JRE_HOME env user
shell: "echo 'export JRE_HOME=/usr/lib/jvm/java-1.8.0-openjdk/jre' >> ~/.bashrc"

- name: Add JAVA_HOME to path root
shell: "echo 'export PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin' >> ~/.bashrc"
become: true
- name: Add JAVA_HOME to path user
shell: "echo 'export PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin' >> ~/.bashrc"
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
- include_tasks: installDependencies.yml
- include_tasks: installJava.yml
- include_tasks: installCassandra.yml
34 changes: 34 additions & 0 deletions test/manual/definitions/ohi/linux/apache-cassandra-debian10.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"global_tags": {
"owning_team": "virtuoso",
"Environment": "development",
"Department": "product",
"Product": "virtuoso"
},
"resources": [
{
"id": "apachecassdebian10",
"provider": "aws",
"type": "ec2",
"size": "t3.small",
"ami_name": "debian-10-amd64-202?????-*",
"user_name": "admin"
}
],
"services": [
{
"id": "apache1",
"destinations": ["apachecassdebian10"],
"source_repository": "https://github.com/newrelic/open-install-library.git",
"deploy_script_path": "test/deploy/linux/apache/install/debian/roles",
"port": 80
},
{
"id": "cassandra1",
"destinations": ["apachecassdebian10"],
"source_repository": "https://github.com/newrelic/open-install-library.git",
"deploy_script_path": "/test/deploy/linux/cassandra/install/debian/roles",
"port": 9042
}
]
}
15 changes: 6 additions & 9 deletions test/manual/definitions/ohi/linux/apache-cassandra-linux2.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,24 @@
"provider": "aws",
"type": "ec2",
"size": "t3.small",
"ami_name": "amzn2-ami-hvm-2.0.????????.?-x86_64-gp2"
"ami_name": "amzn2-ami-hvm-2.0.????????.?-x86_64-gp2",
"user_name": "ec2-user"
}
],
"services": [
{
"id": "apache1",
"destinations": [
"apachecasslinux2"
],
"destinations": ["apachecasslinux2"],
"source_repository": "https://github.com/newrelic/open-install-library.git",
"deploy_script_path": "test/deploy/linux/apache/install/rhel/roles",
"port": 80
},
{
"id": "cassandra1",
"destinations": [
"apachecasslinux2"
],
"destinations": ["apachecasslinux2"],
"source_repository": "https://github.com/newrelic/open-install-library.git",
"deploy_script_path": "test/deploy/linux/cassandra/install/linux2/roles",
"deploy_script_path": "/test/deploy/linux/cassandra/install/rhel/roles",
"port": 9042
}
]
}
}
Loading