Created
May 1, 2023 21:37
Full Ansible Playbook for Redis configuration
This file contains 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
--- | |
- 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