Skip to content

Commit

Permalink
[NEW] added redis-server installation ansible playbook
Browse files Browse the repository at this point in the history
  • Loading branch information
ismoilovdevml committed Sep 9, 2024
1 parent 0d36923 commit 2181ab7
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Ansible/redis/inventory.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[redis_servers]
server1 ansible_host=34.69.104.233 ansible_user=ismoilovdev
server2 ansible_host=34.27.32.115 ansible_user=ismoilovdev
server3 ansible_host=34.170.180.55 ansible_user=ismoilovdev
75 changes: 75 additions & 0 deletions Ansible/redis/redis_install.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
---
- name: Install and configure Redis
hosts: redis_servers
become: yes
tasks:

- name: Detect operating system family
set_fact:
os_family: "{{ ansible_os_family }}"

# Ubuntu/Debian uchun Redis o'rnatish
- name: Install Redis on Debian-based systems
when: os_family == "Debian"
block:
- name: Install prerequisites
apt:
name:
- lsb-release
- curl
- gpg
state: present
update_cache: yes

- name: Add Redis GPG key
apt_key:
url: https://packages.redis.io/gpg
state: present
keyring: /usr/share/keyrings/redis-archive-keyring.gpg

- name: Add Redis repository
apt_repository:
repo: "deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb {{ ansible_distribution_release }} main"
state: present

- name: Update apt cache and install Redis
apt:
name: redis
state: present
update_cache: yes

# RedHat/Rocky uchun Redis o'rnatish
- name: Install Redis on RedHat-based systems
when: os_family == "RedHat"
block:
- name: Install Redis package
yum:
name: redis
state: present

# Redis service-ni ishga tushirish va yoqish
- name: Enable and start Redis service
systemd:
name: redis-server
enabled: yes
state: started

# Konfiguratsiya faylini sozlash
- name: Configure Redis to listen on all interfaces
lineinfile:
path: /etc/redis/redis.conf
regexp: "^bind 127.0.0.1"
line: "bind 0.0.0.0"
state: present

- name: Update Redis-server configuration - set protected-mode to no
lineinfile:
path: /etc/redis/redis.conf
regexp: '^protected-mode'
line: 'protected-mode no'
state: present

- name: Restart Redis service after configuration change
systemd:
name: redis-server
state: restarted

0 comments on commit 2181ab7

Please sign in to comment.