-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added ansible playbook to deploy app
- Loading branch information
1 parent
70651c2
commit b3d0168
Showing
7 changed files
with
143 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[defaults] | ||
inventory = inventory | ||
host_key_checking = False | ||
forks = 32 | ||
|
||
[ssh] | ||
pipelining = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
--- | ||
username: vagrant | ||
|
||
docker_dir: /home/{{ username }}/docker | ||
|
||
packages: | ||
- unzip | ||
- wget | ||
- curl | ||
- git | ||
- htop | ||
- build-essential | ||
- nano | ||
- python3 | ||
- python3-pip | ||
|
||
docker_dependencies: | ||
- apt-transport-https | ||
- ca-certificates | ||
- gnupg2 | ||
- curl | ||
- software-properties-common | ||
- python3-pip | ||
- virtualenv | ||
- python3-setuptools | ||
- docker-compose | ||
|
||
docker_packages: | ||
- docker-ce | ||
- docker-compose | ||
- cgroupfs-mount |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[server] | ||
192.168.60.4 | ||
|
||
[server:vars] | ||
ansible_user = vagrant | ||
ansible_ssh_private_key_file = ~/.vagrant.d/insecure_private_key |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--- | ||
- name: Setup docker and deploy flask app | ||
hosts: all | ||
become: true | ||
|
||
tasks: | ||
- name: Perform essential tasks | ||
ansible.builtin.import_tasks: tasks/essential.yml | ||
- name: Setup docker | ||
ansible.builtin.import_tasks: tasks/docker.yml | ||
- name: Deploy the app | ||
ansible.builtin.import_tasks: tasks/flask.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
- name: Deploy the docker container | ||
community.docker.docker_container: | ||
name: flask-stock | ||
image: rishavnandi/flask-stock:latest-slim | ||
pull: true | ||
state: started | ||
restart_policy: unless-stopped | ||
ports: | ||
- "5000:5000" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
--- | ||
- name: Set amd64 architecture | ||
ansible.builtin.set_fact: | ||
docker_arch: amd64 | ||
when: ansible_architecture == "x86_64" | ||
|
||
- name: Set arm64 architecture | ||
ansible.builtin.set_fact: | ||
docker_arch: arm64 | ||
when: ansible_architecture == "aarch64" or ansible_architecture == "arm64" | ||
|
||
- name: Install docker dependencies | ||
ansible.builtin.apt: | ||
name: "{{ docker_dependencies }}" | ||
state: present | ||
|
||
- name: Add docker gpg key | ||
ansible.builtin.apt_key: | ||
url: https://download.docker.com/linux/ubuntu/gpg | ||
state: present | ||
|
||
- name: Add docker repository | ||
ansible.builtin.apt_repository: | ||
repo: deb [arch={{ docker_arch }}] https://download.docker.com/linux/ubuntu {{ ansible_distribution_release }} stable | ||
state: present | ||
|
||
- name: Update apt and install docker | ||
block: | ||
- name: Attempt installation | ||
ansible.builtin.apt: | ||
update_cache: true | ||
name: "{{ docker_packages }}" | ||
state: present | ||
rescue: | ||
- name: Fix the dumb Ubuntu Jammy error | ||
ansible.builtin.replace: | ||
path: /etc/systemd/system/multi-user.target.wants/docker.service | ||
regexp: "fd://" | ||
replace: "unix://" | ||
when: ansible_distribution == 'Ubuntu' and ansible_distribution_version is version('22.04', '>=') | ||
|
||
- name: Ensure docker group exists | ||
ansible.builtin.group: | ||
name: docker | ||
state: present | ||
|
||
- name: Add user to docker group | ||
ansible.builtin.user: | ||
name: "{{ username }}" | ||
groups: docker | ||
append: true | ||
|
||
- name: Enable docker service | ||
ansible.builtin.service: | ||
name: docker | ||
enabled: true | ||
state: started | ||
|
||
- name: Create docker directory | ||
ansible.builtin.file: | ||
path: "{{ docker_dir }}" | ||
state: directory | ||
owner: "{{ username }}" | ||
group: "{{ username }}" | ||
mode: 0755 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--- | ||
- name: Update the server | ||
ansible.builtin.apt: | ||
update_cache: yes | ||
cache_valid_time: 3600 | ||
upgrade: yes | ||
|
||
- name: Install packages | ||
ansible.builtin.apt: | ||
name: "{{ item }}" | ||
state: present | ||
loop: "{{ packages }}" |