Created
April 22, 2024 16:31
-
-
Save hasan2001jk/dfe8c8792931ac765db630c64e5fd680 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
--- | |
- hosts: ubuntu | |
become: yes | |
tasks: | |
- name: Update and upgrade apt packages | |
apt: | |
upgrade: yes | |
update_cache: yes | |
- name: Install required packages | |
apt: | |
name: | |
- python3-pip | |
- python3-dev | |
- libpq-dev | |
- postgresql | |
- nginx | |
state: present | |
- name: Install virtualenv via pip | |
pip: | |
name: virtualenv | |
state: present | |
- name: Install Django and Django REST Framework | |
pip: | |
name: | |
- django | |
- djangorestframework | |
state: present | |
virtualenv: /opt/venv | |
virtualenv_python: python3 | |
- name: Ensure database is created | |
postgresql_db: | |
name: mydatabase | |
- name: Ensure user has access to the database | |
postgresql_user: | |
db: mydatabase | |
name: myuser | |
password: secretpass | |
priv: ALL | |
- name: Start and enable Nginx | |
service: | |
name: nginx | |
state: started | |
enabled: yes | |
- name: Remove default nginx config | |
file: | |
path: /etc/nginx/sites-enabled/default | |
state: absent | |
- name: Deploy Nginx config | |
copy: | |
src: /path/to/your/nginxconfig | |
dest: /etc/nginx/sites-available/myapp | |
mode: 0644 | |
- name: Enable Nginx configuration | |
file: | |
src: /etc/nginx/sites-available/myapp | |
dest: /etc/nginx/sites-enabled/myapp | |
state: link | |
- name: Restart Nginx | |
service: | |
name: nginx | |
state: restarted | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment