{"id":19141757,"url":"https://github.com/ramitsurana/ansible-ec2-docker-deployment","last_synced_at":"2025-05-06T23:44:50.814Z","repository":{"id":50146573,"uuid":"93485056","full_name":"ramitsurana/ansible-ec2-docker-deployment","owner":"ramitsurana","description":"Deploying wordpress blog using docker \u0026 ansible on AWS","archived":false,"fork":false,"pushed_at":"2018-10-06T12:16:56.000Z","size":35,"stargazers_count":18,"open_issues_count":0,"forks_count":54,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-19T16:11:20.329Z","etag":null,"topics":["ansible","aws","docker"],"latest_commit_sha":null,"homepage":"https://ramitsurana.github.io/ansible-ec2-docker-deployment/","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ramitsurana.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-06-06T06:42:16.000Z","updated_at":"2024-02-18T19:35:32.000Z","dependencies_parsed_at":"2022-09-11T16:10:27.687Z","dependency_job_id":null,"html_url":"https://github.com/ramitsurana/ansible-ec2-docker-deployment","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ramitsurana%2Fansible-ec2-docker-deployment","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ramitsurana%2Fansible-ec2-docker-deployment/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ramitsurana%2Fansible-ec2-docker-deployment/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ramitsurana%2Fansible-ec2-docker-deployment/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ramitsurana","download_url":"https://codeload.github.com/ramitsurana/ansible-ec2-docker-deployment/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252788404,"owners_count":21804280,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ansible","aws","docker"],"created_at":"2024-11-09T07:24:38.747Z","updated_at":"2025-05-06T23:44:50.798Z","avatar_url":"https://github.com/ramitsurana.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Ansible-ec2-docker-deployment\nUsing Ansible to setup Wordpress, MariaDB \u0026 ELK Stack to an AWS EC2 instance with Docker Compose \n\n## Prerequisites\n\n* Pythonv2.7\n* Ansible\n* Python Boto    \n* Git\n\n( For Manual Installation - https://github.com/ramitsurana/ansible-ec2-docker-deployment/blob/master/Installation.md)\n\n## Design\n\n![arch](https://user-images.githubusercontent.com/8342133/27880020-2d11dfce-61e1-11e7-800e-9af806aa4903.png)\n\nThe design of the model is to deploy the ELK stack,Wordpress and Redis on top of the docker in an EC2 instance.This is done using docker compose and dockerfiles.The provisioning of the system is done using ansible.The base os is Ubuntu 14.04.For successful results,please avoid Ubuntu 16.04 as it does not contain pre-installed python. For the same, you can use: \n\n````\n$ sudo apt-get install python-minimal -y\n````\n\n[Ref](https://github.com/ansible/ansible/issues/19584)\n\nThe file structure is as follows:\n\n* Docker\n  - app\n    - app1\n      - docker-compose.app.yml\n    - app-deploy.yml\n  - elk\n    - elk1    \n      - docker-compose.yml\n    - elk-deploy.yml\n\n* Deploy \n  - ec2-configure.yml\n\n* Ansible\n  - Info\n    - aws-credentials.yml\n    - specs.yml\n  - provision.yml\n  - vpc-provision.yml\n  - hosts\n\n## Steps:\n\n```\n$ git clone https://github.com/ramitsurana/ansible-ec2-docker-deployment/\n$ cd ansible-ec2-docker-deployment/\n```\n\n### Configuring Hosts\n\nPlease create and add the following lines at **/etc/ansible/hosts** file :\n\n````\n[local]\n127.0.0.1\n\n[ec2]\n\u003cEC2-IP\u003e ansible_user=ubuntu\n````\n\nYou can choose the EC2 IP by choosing an elastic Ip for your instance.This is good way to fix an IP as it may change after a reboot of EC2 instance. This setting can be observed at EC2 Dashboard \u003e Elastic IP. \n\nSimilarly you should also create another file at /etc/ansible/ansible.cfg.This is the main configuration file for ansible to run.You can uncomment add some sections in it as represented below:\n\n````\n[defaults]\n\n# some basic default values...\n\ninventory      = /etc/ansible/hosts\nlibrary        = /usr/share/my_modules/\nremote_tmp     = $HOME/.ansible/tmp\nlocal_tmp      = $HOME/.ansible/tmp\nforks          = 5\npoll_interval  = 15\nsudo_user      = root\n#ask_sudo_pass = True\n#ask_pass      = True\n#transport      = smart\nremote_port    = 22\n#module_lang    = C\n#module_set_locale = True\n\n````\n### Creating VPC \n\nThis can be done using the vpc-provision.yml file present in the ansible dir.It requires you to put your aws credentials [here](https://github.com/ramitsurana/ansible-ec2-docker-deployment/blob/master/ansible/info/aws-credentials.yml).The [specs.yml](https://github.com/ramitsurana/ansible-ec2-docker-deployment/blob/master/ansible/info/specs.yml) file is already configured. The command to run the ansible playbook is as follows:\n\n````\n$ sudo ansible-playbook vpc-provision.yml -i hosts -vv\n````\n\n### Creating EC2 \n\nThis can be done using the provision.yml file present in the ansible dir.It requires you to put your aws credentials [here](https://github.com/ramitsurana/ansible-ec2-docker-deployment/blob/master/ansible/info/aws-credentials.yml).The [specs.yml](https://github.com/ramitsurana/ansible-ec2-docker-deployment/blob/master/ansible/info/specs.yml) file stated the region,ami and instance type.The command to run the ansible playbook is as follows:\n\n````\n$ sudo ansible-playbook provision.yml -i hosts -vv\n````\n\nRemember to associate your Elastic IP with the EC2 instance.This can be observed under Elastic IP \u003e Associate.\n\n### Configuring EC2\n\nWe can start configuring our EC2 instance by running some basic commands such as:\n\n````\n//Installing Docker\n$ sudo apt-get clean \u0026\u0026 update -y\n$ apt-get install apt-transport-https ca-certificates curl software-properties-common -y\n$ apt-get install curl -y\n$ sudo apt-get install docker.io -y\n$ sudo usermod -aG docker ${USER}\n$ sudo service docker restart\n\n//Installing docker compose\n$ sudo sudo apt-get install python-pip python-dev build-essential -y\n$ sudo pip install docker-compose==1.3.0\n````\n\nThis can be done using the ec2-configure.yml file present in the repo.The command would be:\n\n````\n$ sudo ansible-playbook ec2-configure.yml -vv --private-key  \u003cpath-to-keypair\u003e\n````\n\n### Deploying ELK Stack using Docker Compose\n\nIt can be done using the ansible playbook.\n\n````\n$ sudo ansible-playbook elk-deploy.yml -vv --private-key \u003ckeypair\u003e\n````\n\nThe playbook consists of the below commands:\n\n````\n$ cp elk1/docker-compose.yml ~/home/ubuntu/\n$ sudo docker-compose -f ~/home/ubuntu/docker-compose.yml up -d\n$ sudo rm -f ~/home/ubuntu/docker-compose.yml \n\n````\n\n### Deploying Wordpress and Mariadb Containers using Docker Compose\n\nIt can be done using the ansible playbook.\n\n\n````\n$ sudo ansible-playbook app-deploy.yml -vv --private-key \u003ckeypair\u003e\n````\n\nThe playbook consists of the following below commands:\n\n````\n$ cp app1/docker-compose.yml ~/home/ubuntu/\n$ sudo docker-compose -f ~/home/ubuntu/docker-compose.app.yml up -d\n$ sudo rm -f ~/home/ubuntu/docker-compose.app.yml \n````\n\n### Output\n\n**Add tag Owner : \u003cYOUR-NAME\u003e in EC2 instance.**\n\nThe output can be observed using the ip address of the ec2 instance.The Public DNS would be like ec2-xxx-xxx-xxx.compute.amazonaws.com.\n\nService   | Port | \n|:--------|------:|\n|Wordpress | 8080|\n|Kibana    | 5601|\n\n**Please check the inbound and outbound rules in case of any page loading and reloading errors.You can check it out at EC2 Dashboard \u003e Security Groups.**\n\nSample video output can be found out [here](https://youtu.be/BHcSNVzWRlo) :\n\n\u003ca href=\"http://www.youtube.com/watch?feature=player_embedded\u0026v=BHcSNVzWRlo\" target=\"_blank\"\u003e\u003cimg src=\"http://img.youtube.com/vi/BHcSNVzWRlo/0.jpg\" alt=\"IMAGE ALT TEXT HERE\" width=\"540\" height=\"350\" /\u003e\u003c/a\u003e\n\n## License\n\nMIT License\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Framitsurana%2Fansible-ec2-docker-deployment","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Framitsurana%2Fansible-ec2-docker-deployment","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Framitsurana%2Fansible-ec2-docker-deployment/lists"}