notes
  • computer-networking
    • extend-wifi-with-router
    • how-the-internet-works
    • idk
    • networking-devices
    • osi-model
    • tcp-ip
    • Types of VPN
  • databases
    • Foreign Keys
    • Redis
    • simple-queries
  • devops
    • ansible
    • Manual deployment
    • docker
    • Workflow file
    • nginx
    • promethues-grafana
    • terraform
  • hardware
    • Power
  • home-server
    • proxmox-basics
    • proxmox-setup
    • storage
  • languages-frameworks
    • programming-paradigms
    • programming-languages
      • Regex Notes
      • c
        • basics
        • pointers-memory
      • cpp
        • basics
        • running-cpp
      • php
        • basics
        • choizez
        • frameworks
          • laravel
      • python
        • venv
        • concepts
          • Using lambda
        • frameworks
          • django
            • django
            • start
      • java
        • advanced
          • functional-programming
          • reactive-programming
        • concepts
          • how-java-works
          • serialization
          • sockets
          • threads
        • extra
          • collection-framework
          • generics-and-wildcards
          • Regular Expressions (Regex)
          • streams
        • frameworks
          • orm
        • fundamentals
          • OOP
          • conditionals
          • data-structures
          • data-types
          • exceptions
          • files
          • Functions (aka method)
          • Loops
          • packages
          • type-casting
      • javascript
        • frameworks
          • morgan
          • Using Sequelize with PostgreSQL in JavaScript
  • operating-system
    • basics
    • linux-directories
    • Basic Unix Terminal Commands
  • others
    • dark-web
    • piracy
  • system-design
    • system-design
  • web-dev
    • full-stack
  • books
    • sicp
      • Recursion thought process
      • 1
        • 1.1
        • 1.2
        • 1.3
      • 2
        • 2.1
  • certifications
    • aws-certified-cloud-practitioner
      • core-services
      • other-services
    • comptia-a+
      • Cloud
      • hardware
      • Important terms
      • Important terms
      • Troubleshooting
  • cloud
    • aws
      • aws-cli
      • aws-ec2-deployment
  • dsa
    • algorithms
      • back-tracking
      • bfs
      • Binary Search
      • bit-manipulation
      • Bubble sort
      • bucket-sort
      • counting-sort
      • dfs
      • Divide & Conquer
      • djikstras-algorithm
      • dynamic-programming
      • external-sorting
      • greedy-algorithm
      • Heap sort
      • Insertion sort
      • kadanes-algorithm
      • Merge sort
      • Permutation
      • quick-sort
      • Radix Sort
      • recurrence-relation
      • recursion
      • Selection sort
      • sliding-window
      • subset
      • time-space-complexity
      • topological-sort
      • tree-traversals
      • Two Pointers Technique
    • data-structures
      • data-structures
  • security
    • authentication
      • What is JWT (JSON Web Token)?
    • software-architecture-design
      • design-patterns
Powered by GitBook
On this page
  1. devops

ansible

Ansible is a software tool to automate the deployment, configuration, and management of IT infrastructure and applications.

Ansible :

  • Inventory , at /etc/ansible/hosts

[aws_ec2]
3.27.145.170 ansible_ssh_private_key_file=/home/ubuntu/ansiblefolder/todo.pem

Add servers that you want to configure here

  • Add playbook

---
- name: Install dependencies
  hosts: aws_ec2
  become: true
  vars:
    repo_path: /home/ubuntu/to-do-fullstack
  tasks:
    - name: Update apt package cache
      apt:
        update_cache: yes
    - name: Install Node.js and npm
      apt:
        name:
          - nodejs
          - npm
        state: present

    - name: Install Git
      apt:
        name: git
        state: present

    - name: Install Postgres
      apt:
        name: postgresql
        state: present

    - name: Install Nginx
      apt:
        name: nginx
        state: present

    - name: Install PM2
      npm:
        name: pm2
        global: yes

    - name: Ensure the repository is already cloned
      stat:
        path: "/home/ubuntu/to-do-fullstack"
      register: git_repo_status
    - name: Git clone
      git:
        repo: 'https://github.com/aloysiustanrs/to-do-fullstack'
        dest: " {{ repo_path }}"
      when: not git_repo_status.stat.exists

    - name: Frontend  npm install
      npm:
        path: "{{ repo_path }}/frontend"
        state: present
    - name: Build frontend
      command: npm run build
      args:
        chdir: "{{ repo_path }}/frontend"
    - name: Backend  npm install
      npm:
        path: "{{ repo_path }}/backend"
        state: present

    - name: Copy nginx configuration template
      template:
        src: /home/ubuntu/ansiblefolder/nginx.conf.j2
        dest: /etc/nginx/sites-available/yomy.online
    - name: Create symlink from sites-available to sites-enabled
      file:
        src: /etc/nginx/sites-available/yomy.online
        dest: /etc/nginx/sites-enabled/yomy.online
        state: link
      notify:
        - Restart Nginx
  handlers:
    - name: Restart Nginx
      service:
        name: nginx
        state: restarted

What I did : install required apps, clone code using git, setup nginx to run frontend

Can add more tasks like : setup backend to pm2 service, setup env variables, setup firewall, setup ssl, configure db user

PreviousdevopsNextManual deployment

Last updated 1 month ago