Skip to content

Instantly share code, notes, and snippets.

@SirPhemmiey
Created May 1, 2023 21:37
Show Gist options
  • Save SirPhemmiey/8a7c7949468a5f12de1f0e5b7b272ff7 to your computer and use it in GitHub Desktop.
Save SirPhemmiey/8a7c7949468a5f12de1f0e5b7b272ff7 to your computer and use it in GitHub Desktop.
Full Ansible Playbook for Redis configuration
---
- name: Redis Installation
hosts: redis
become: true
tasks:
- name: Update package repositories
yum:
update_cache: yes
- name: Install Redis
yum:
name: redis
state: present
- name: Start Redis service
systemd:
name: redis
state: started
enabled: yes
- name: Restart Redis service
systemd:
name: redis
state: restarted
- name: Configure Redis
become: yes
lineinfile:
path: /etc/redis.conf
regexp: "{{ item.regexp }}"
line: "{{ item.line }}"
with_items:
- { regexp: "^bind .*", line: "bind 0.0.0.0" }
- { regexp: "^port .*", line: "port 6379" }
- { regexp: "^# requirepass .*", line: "requirepass pass@123" }
notify: Restart Redis service
- name: Install ufw
yum:
name: ufw
state: present
- name: Allow incoming connections on port 6379
community.general.ufw:
name: redis-firewall
rule: allow
port: 6379
from_ip: 0.0.0.0/0
direction: in
- name: Reload firewall rules
community.general.ufw:
state: enabled
- name: Restart Redis service
systemd:
name: ufw
state: restarted
- name: Enable ufw service
systemd:
name: ufw
enabled: yes
state: restarted
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment