From bc1a4ce177ede5800227c3c001df05c713df8d54 Mon Sep 17 00:00:00 2001 From: RoshanAssistanz Date: Thu, 2 Mar 2023 16:21:10 +0530 Subject: [PATCH] rabbitmq-20-04 --- .../opt/cloudstack/rabbitmq-cleanup.sh | 37 ++++++++ rabbitmq-20-04/rabbitmq.sh | 7 ++ rabbitmq-20-04/rabbitmq.yaml | 94 +++++++++++++++++++ 3 files changed, 138 insertions(+) create mode 100644 common-files/opt/cloudstack/rabbitmq-cleanup.sh create mode 100644 rabbitmq-20-04/rabbitmq.sh create mode 100644 rabbitmq-20-04/rabbitmq.yaml diff --git a/common-files/opt/cloudstack/rabbitmq-cleanup.sh b/common-files/opt/cloudstack/rabbitmq-cleanup.sh new file mode 100644 index 0000000..9ab15e4 --- /dev/null +++ b/common-files/opt/cloudstack/rabbitmq-cleanup.sh @@ -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 diff --git a/rabbitmq-20-04/rabbitmq.sh b/rabbitmq-20-04/rabbitmq.sh new file mode 100644 index 0000000..88183ec --- /dev/null +++ b/rabbitmq-20-04/rabbitmq.sh @@ -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 \ No newline at end of file diff --git a/rabbitmq-20-04/rabbitmq.yaml b/rabbitmq-20-04/rabbitmq.yaml new file mode 100644 index 0000000..91e2763 --- /dev/null +++ b/rabbitmq-20-04/rabbitmq.yaml @@ -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" \ No newline at end of file