This repository contains the code to automatically configure a web server running Mattermost using Ansible. To perform the task, I have started by creating two servers running Ubuntu 16.04 with Ansible configured on one of them. After configuring Ansible, I made an SSH connection between the two servers. This connection was used to perform operations on the web server using the Ansible server. After that, I have updated the Ubuntu packages and installed MySQL Database server and Mattermost server. One admin and user have been created as the users of Mattermost server. The configuration of the server was done as the last stage of the project. this configuration included email notifications and storage options. For email confirmation, I have used Zoho mail.
Clone the repository by git clone https://github.ncsu.edu/rdasori/HW2-DevOps.git
Create a configuration server. This server will be using a "push-based model", where we will be sending configuration commands to other external servers. It also needs to be configured with Ansible.
Create a Virtual Machine.
$ cd servers/ansible-srv
$ baker bake
Create another virtual machine for the web server.
$ cd servers/web-srv
$ baker bake
Create a new public/private key pair from the host machine by running the following command.
ssh-keygen -t rsa -b 4096 -C "web-srv" -f web-srv
After generating the keys, you need to copy them onto the servers. The private key will be sent over to the configuration server. The public key will be sent over to the web-server.
Go to the ansible-srv (cd servers/ansible-srv
, then baker ssh
).
Using a file editor, paste and store your private key in a file:
ansible-srv $ vim ~/.ssh/web-srv
ansible-srv $ chmod 600 ~/.ssh/web-srv
Go inside the web-srv. Copy the web-srv.pub file from your host.
web-srv $ vim ~/.ssh/authorized_keys
Inside the ansible-srv, test your connection between the servers:
ssh -i ~/.ssh/web-srv vagrant@192.168.33.100
This completes the basic configuration of Ubuntu on both the servers with ansible configured on one of them.
Go to ansible-srv/playbook and run ansible-playbook prereq.yml -i inventory
.
It will update the ubuntu packages.
Go to ansible-srv/playbook and run ansible-playbook mysql.yml -i inventory
.
It will install the MySQL database server and will also set up the mmuser. It will also install install all the required dependencies such as pip, pip3 and jq.
Go to ansible-srv/playbook and run ansible-playbook mattermost_installation.yml -i inventory
.
It will install the mattermost server. If everything goes perfectly. We can see the webpage on 192.168.33.100:8065.
Go to ansible-srv/playbook and run ansible-playbook mattermost_user_creation.yml -i inventory
.
It will create a team and an admin and will also add it to the team. We can log in to the system by using the following credentials. This step has been made idempotent. It will check if the admina dn team exists. Once a team has been created, it will not create the same team again.
-
For admin: Username: admin@example.com Password: Password
-
For the user: Username: user@example.com Password: Password
As the last step to set up the email, I have created a temporary account at Zoho and have added the SMTP connection among my server.
Complete the email notification step by running ansible-playbook mattermost_config_restart.yml -i inventory
. This will edit the configuration of the email notification. After that, it will restart the server so that we can see the changes made.
If you want to set up the SMTP connection and you are using Zoho, go to vars/vars.yml and edit the SMTPUsername and SMTPPassword. If you are using some other SMTP, then configure the SMTPServer and SMTPPort as well.
- Introduced modularity in the code by dividing the code into small logical working modules.
- Used vault to store the sensitive data as a separate file.
- Applied idempotency in user creation
The link for screencast is available here.