Skip to content

nguyentuan1696/infra-ops

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Overview

InfraOps is an infrastructure automation project using Ansible to provision and manage services such as:

  • Nginx (Web server & reverse proxy)
  • Docker (Container management)
  • PostgreSQL (Database)
  • Grafana (Monitoring & visualization)
  • Prometheus (Metrics collection & alerting)

Prerequisites

Ensure you have the following installed:

  • Ansible (>=2.9)
  • SSH access to target servers
  • Python (>=3.6)

Installation

Install via Ansible Galaxy

You can install this role from Ansible Galaxy:

ansible-galaxy install nguyentuan1696.infra-ops

More details at: Ansible Galaxy - InfraOps

Manual Installation

  1. Clone the repository:
git clone https://github.com/nguyentuan1696/infraops.git
cd infraops
  1. Configure your inventory in inventory.yml:
all:
  hosts:
    web:
      ansible_host: 127.0.0.1
      ansible_user: root
  1. Run the Ansible playbook
ansible-playbook -i inventory.yml playbook.yml

Project Structure

infra-ops/
├── group_vars/
├── meta/
├── roles/
│   ├── docker/
│   ├── grafana/
│   ├── nginx/
│   ├── postgresql/
│   └── prometheus/
├── .DS_Store
├── .gitignore
├── Makefile
├── README.md
├── inventory.yml
└── playbook.yml

Notes:

  • group_vars/: Contains group variables used in Ansible.
  • meta/: Contains metadata information for Ansible.
  • roles/: Contains Ansible roles for each service:
    • docker/: Role for installing and configuring Docker.
    • grafana/: Role for installing and configuring Grafana.
    • nginx/: Role for installing and configuring Nginx.
    • postgresql/: Role for installing and configuring PostgreSQL.
    • prometheus/: Role for installing and configuring Prometheus.
  • .gitignore: File that specifies files and directories Git should ignore.
  • Makefile: File containing automation commands.
  • README.md: File with instructions and information about the project.
  • inventory.yml: Inventory file defining target servers for Ansible.
  • playbook.yml: Main playbook file to execute roles.

Monitoring Dashboard

Once deployed, access Grafana at: http://your-server-ip:9090

Note

  1. Access the Server: Log in to your server and create an SSH key.

    ssh-keygen -t rsa -b 4096 -f ~/.ssh/id_rsa_ansible -N ""
  2. Add the Public Key: Append the contents of id_rsa_ansible.pub to the authorized_keys file to allow SSH access.

    cat ~/.ssh/id_rsa_ansible.pub >> ~/.ssh/authorized_keys
  3. Set Correct Permissions: Ensure that the permissions for the authorized_keys file and the .ssh directory are set correctly to enhance security.

    chmod 600 ~/.ssh/authorized_keys
    chmod 700 ~/.ssh
  4. Copy the Private Key: Make sure to securely copy the contents of ~/.ssh/id_rsa_ansible to your local machine or wherever you need to use it.

    cat ~/.ssh/id_rsa_ansible

Important Notes

  • Keep your private key secure and do not share it publicly.
  • Ensure that the SSH service is running on your server to allow connections.
  • If you encounter any issues, check the SSH configuration and firewall settings.

Completely remove PostgreSQL

To completely remove PostgreSQL from your system, follow these steps:

1. Stop the PostgreSQL Service

sudo systemctl stop postgresql

2. Uninstall PostgreSQL and Related Packages

sudo apt remove --purge postgresql postgresql-*

3. Remove PostgreSQL Data and Configuration Files

sudo rm -rf /var/lib/postgresql/
sudo rm -rf /etc/postgresql/
sudo rm -rf /etc/postgresql-common/
sudo rm -rf /var/log/postgresql/

4. Remove PostgreSQL User and Group (Optional)

sudo deluser postgres
sudo delgroup postgres

5. Clean Up Unused Dependencies

sudo apt autoremove
sudo apt autoclean

6. Verify PostgreSQL is Completely Removed

Check if any PostgreSQL-related services or files are still present:

psql --version

or

dpkg -l | grep postgresql

Contributing

Feel free to open issues and pull requests

License

MIT License

Contact

For any inquiries, reach out via email: nguyentuan1696@gmail.com or telegram: @nguyentuan1696

About

InfraOps is an infrastructure automation project using Ansible to provision and manage services

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published