Skip to content

Python get endpoint for users application, which has then been containerised, ec2 instance provisioned for it then used Ansible used for Configuration

Notifications You must be signed in to change notification settings

elsie-dev/Docker-CI-Ansible-Terraform

Repository files navigation

Task Summary

Python application written in Flask with get user endpoints for two dummy users.

Containerization, setting up CICD infrastructure as Code and Configuration management for the application.

Containers + CI/CD steps:

  • Created a Dockerfile to build the image locally using Docker and run a container
  • Prepared CI process that builds the container image, and pushes it to a registry (GitHub Container Registry for this case). The Ci runs on push to the main branch periodically on Saturday at 7 pm

Configuration Management

  • Preparing a machine with Linux distribution, used Terraform for this.

  • Created a playbook that does the following:

    • Creates a user with script nice-script.sh in their home directory. The script lists all mounted file systems
    • Create a user with username John and User ID 1234, in-home directory: /better-place/john
    • User John should run the sudo command without providing his password and installing Tmux and Vim packages. Then lastly install Terraform CLI

    Ansible Setup:

Since Ansible is part of Python, I installed Ansible using the Python method. Defined all the requirements in the requirements.txt. Then installed them with the command

pip install -r deploy_requirements.txt

Ansible SSH:

  • Generating public key using ssh-keygen for Ansible
  • Giving the key from AWS EC2 terraform configuration with chmod 700 permission
  • Creating ansible_hosts and replacing them with the IP address of your instance
  • Creating a playbook file with your instruction

To test your ssh connection run the command:

 ansible hosts_to_add_key -m ping -i ansible_hosts
  ansible hosts_to_add_key -m ping -i ansible_hosts
  --user ubuntu --key-file ~/path to your ec2 key.pem

If you specify the right path and have the proper permission, you should see the successful output as shown below before running your playbook.

Ansible

To run your playbook use the command:

ansible-playbook add-key.yml -i ansible_hosts -user ubuntu --key-file ~/keys/popo.pem -e "key=~/.ssh/id_rsa.pub"

References used:

Pushing Images to Container Registry

Ansible Getting Started

Installing Terraform

Ansible

Side Note: I understand as a DevOps best practice Infrastructure as Cod/Configuration setup should be in a different Repo with the application repo, but instead included them together for other reasons

About

Python get endpoint for users application, which has then been containerised, ec2 instance provisioned for it then used Ansible used for Configuration

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published