Skip to content

Commit

Permalink
Create ssh key and droplet
Browse files Browse the repository at this point in the history
  • Loading branch information
aktech committed May 27, 2020
1 parent 6c0c94c commit 370878b
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@ FROM python:3.8-slim-buster
RUN apt-get update -y && \
apt-get install -y python-pip python-dev && \
apt-get install -y libpq-dev && \
apt-get install -y postgresql-client
apt-get install -y postgresql-client && \
apt install -y openssh-client


WORKDIR /app
COPY ./requirements.txt /app/requirements.txt
RUN pip install -r requirements.txt

COPY ./start.sh /app/start.sh
RUN chmod +x /app/start.sh
RUN mkdir -p /root/.ssh


EXPOSE 8000
Expand Down
Empty file removed __init__.py
Empty file.
3 changes: 3 additions & 0 deletions deployment/ansible.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[defaults]
ansible_user = root
host_key_checking = False
39 changes: 39 additions & 0 deletions deployment/digital_ocean_droplet.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
- hosts: localhost
connection: local
gather_facts: false
vars_files:
- vars/default.yml

tasks:
- openssh_keypair:
path: /tmp/id_ssh_rsa

- name: "Create ssh key"
digital_ocean_sshkey:
name: "ansible-tutorial-ssh-key"
ssh_pub_key: "{{ lookup('file', '/tmp/id_ssh_rsa.pub') }}"
state: present
register: docker_ssh_key

- digital_ocean_droplet:
unique_name: yes # "yes" makes it idempotent
region: nyc3
image: ubuntu-20-04-x64
size_id: s-1vcpu-1gb
wait: yes
name: "{{ droplet_name }}"
state: present
ssh_keys: [ "{{ docker_ssh_key.data.ssh_key.id }}" ]
register: created_droplet

- digital_ocean_tag:
name: ansible-tutorial-django
resource_id: "{{ created_droplet.data.droplet.id }}"
state: present
register: tag_response

- name: add hosts
add_host:
name: "{{ created_droplet.data.ip_address }}"
groups: "do"
27 changes: 27 additions & 0 deletions deployment/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
- hosts: do
tasks:
- name: Install prerequisites for Docker repository
apt:
name: ['apt-transport-https', 'ca-certificates', 'curl', 'gnupg2', 'software-properties-common']
update_cache: yes

- name: Add Docker GPG key
apt_key: url=https://download.docker.com/linux/ubuntu/gpg

- name: Add Docker APT repository
apt_repository:
repo: deb [arch=amd64] https://download.docker.com/linux/{{ansible_distribution|lower}} {{ansible_distribution_release}} stable

- name: Install Docker CE
apt:
name: ['docker-ce', 'docker-ce-cli', 'containerd.io']
update_cache: yes

- name: Install prerequisites for docker-compose
apt:
name: ['python3-pip', 'python3-setuptools', 'virtualenv']

- name: Install docker-compose
pip:
name: docker-compose
3 changes: 3 additions & 0 deletions deployment/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
- import_playbook: digital_ocean_droplet.yml
- import_playbook: docker.yml
2 changes: 2 additions & 0 deletions deployment/vars/default.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
droplet_name: ansible-tutorial

0 comments on commit 370878b

Please sign in to comment.