Skip to content

Commit

Permalink
rabbitmq-20-04
Browse files Browse the repository at this point in the history
  • Loading branch information
RoshanAssistanz committed Mar 2, 2023
1 parent 1da48d9 commit bc1a4ce
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 0 deletions.
37 changes: 37 additions & 0 deletions common-files/opt/cloudstack/rabbitmq-cleanup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash

RED='\033[1;31m'
NC='\033[0m'

echo -e "${RED}
################################################################################################################
# Your MarketPlace App has been deployed successfully! #
# Passwords are stored under /root/ #
################################################################################################################
${NC}"

echo
echo -e "${RED}This message will be removed in the next login!${NC}"
echo
echo
echo -e "${RED}Refer to the below RabbitMQ Admin details${NC}"
echo
cat /root/.admin_password
echo

#Cleanup script
rm -rf /usr/local/src/
mkdir -p /usr/local/src/
rm -rf /var/lib/cloud/instances/*
rm -rf /var/lib/cloud/data/*
find /var/log -mtime -1 -type f -exec truncate -s 0 {} \; >/dev/null 2>&1
rm -rf /var/log/*.gz /var/log/*.[0-9] /var/log/*-????????
cat /dev/null > /var/log/lastlog; cat /dev/null > /var/log/wtmp
apt-get -y autoremove >/dev/null 2>&1
apt-get -y autoclean >/dev/null 2>&1
history -c
cat /dev/null > /root/.bash_history
unset HISTFILE

rm -rf /root/.bashrc
cp /etc/skel/.bashrc /root
7 changes: 7 additions & 0 deletions rabbitmq-20-04/rabbitmq.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

mkdir -p {/usr/local/src/rabbitmq-20-04/opt/cloudstack/,/usr/local/src/rabbitmq-20-04/}

cd /usr/local/src/rabbitmq-20-04/opt/cloudstack/ && wget https://raw.githubusercontent.com/stackbill/marketplace/main/common-files/opt/cloudstack/rabbitmq-cleanup.sh

cd /usr/local/src/rabbitmq-20-04/ && wget https://raw.githubusercontent.com/stackbill/marketplace/main/rabbitmq-20-04/rabbitmq.yaml
94 changes: 94 additions & 0 deletions rabbitmq-20-04/rabbitmq.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
- name: RabbitMQ Setup
hosts: localhost
tasks:
- name: Restarting sshd
shell: "sed -i 's/#Match User anoncvs/ForceCommand echo Please wait until the installation is completed..../g' /etc/ssh/sshd_config && systemctl restart sshd"

- name: Updating Packages
ansible.builtin.apt:
update_cache: yes

- name: Installing Dependencies
apt:
name: [ 'curl', 'software-properties-common', 'apt-transport-https', 'lsb-release' ]
state: latest

- name: Import Erlang GPG Key and repo
shell: "{{ item }}"
with_items:
- curl -fsSL https://packages.erlang-solutions.com/ubuntu/erlang_solutions.asc | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/erlang.gpg
- echo "deb https://packages.erlang-solutions.com/ubuntu $(lsb_release -cs) contrib" | sudo tee /etc/apt/sources.list.d/erlang.list

- name: Updating Packages
ansible.builtin.apt:
update_cache: yes

- name: Installing Erlang
apt:
name: erlang
state: present

- name: Add RabbitMQ Repository
shell: curl -s https://packagecloud.io/install/repositories/rabbitmq/rabbitmq-server/script.deb.sh | sudo bash

- name: Updating Packages
ansible.builtin.apt:
update_cache: yes

- name: Installing rabbitmq
apt:
name: rabbitmq-server
state: present

- name: Enable the RabbitMQ Management Web dashboard
shell: sudo rabbitmq-plugins enable rabbitmq_management

- name: Restarting service rabbitmq
service:
name: rabbitmq-server
state: restarted

- name: Generating Admin password
shell: openssl rand -hex 24
register: adminpassword

- debug:
var: adminpassword.stdout

- name: Storing mysql password
copy:
dest: "/root/.admin_password"
content: |
rabbitmq_user = mqadmin
rabbitmq_pass = "{{ adminpassword.stdout }}"
- name: Adding Admin User
shell: "{{ item }}"
with_items:
- sudo rabbitmqctl add_user mqadmin {{ adminpassword.stdout }}
- sudo rabbitmqctl set_user_tags mqadmin administrator
- sudo rabbitmqctl set_permissions -p / mqadmin ".*" ".*" ".*"
- sudo rabbitmqctl delete_user guest
- sudo rabbitmq-diagnostics
ignore_errors: true

- name: Creating a directory for shell script
ansible.builtin.file:
path: /opt/cloudstack
state: directory

- name: Copy files for shell script
copy:
src: "{{ item.confsrc }}"
dest: "{{ item.confdest }}"
with_items:
- { confsrc: '/usr/local/src/rabbitmq-20-04/opt/cloudstack/rabbitmq-cleanup.sh', confdest: '/opt/cloudstack/'}

- name: Adding a line for shell script
lineinfile:
path: /root/.bashrc
line: "chmod +x /opt/cloudstack/rabbitmq-cleanup.sh && /opt/cloudstack/rabbitmq-cleanup.sh"
state: present

- name: Restarting sshd
shell: "sed -i 's/ForceCommand echo Please wait until the installation is completed..../#Match User anoncvs/g' /etc/ssh/sshd_config && systemctl restart sshd"

0 comments on commit bc1a4ce

Please sign in to comment.