Skip to content

Commit

Permalink
Merge pull request #7 from Respheal/master
Browse files Browse the repository at this point in the history
Cleanup pass
  • Loading branch information
Respheal authored Dec 2, 2020
2 parents f5b54d7 + acb2852 commit 51a7464
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 39 deletions.
2 changes: 1 addition & 1 deletion handlers/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
- name: restart redis
systemd:
daemon_reload: yes
name: '{{ redis_daemon }}'
name: "{{ redis_daemon }}"
state: restarted
10 changes: 5 additions & 5 deletions tasks/Debian.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
state: present
filename: "stretch-backports"
when:
- ansible_distribution == 'Debian'
- ansible_distribution_major_version == '9'
- ansible_distribution == "Debian"
- ansible_distribution_major_version == "9"

- name: (Debian 9) Install Redis from backports
package:
Expand All @@ -15,13 +15,13 @@
state: present
register: redis_installed
when:
- ansible_distribution == 'Debian'
- ansible_distribution_major_version == '9'
- ansible_distribution == "Debian"
- ansible_distribution_major_version == "9"

- name: (Ubuntu) Update APT cache
apt:
force_apt_get: true
update_cache: true
cache_valid_time: "3600"
state: present
when: ansible_distribution == 'Ubuntu'
when: ansible_distribution == "Ubuntu"
6 changes: 3 additions & 3 deletions tasks/RedHat.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
---
- name: (RedHat 7) Install Remi repo
when: ansible_distribution_major_version == '7'
package:
name: 'https://rpms.remirepo.net/enterprise/remi-release-{{ ansible_distribution_major_version }}.rpm'
name: "https://rpms.remirepo.net/enterprise/remi-release-7.rpm"
state: present
when: ansible_distribution_major_version == "7"

- name: (RedHat 7) Install Redis
when: ansible_distribution_major_version == '7'
package:
name: "{{ redis_packages }}"
enablerepo: "remi"
state: present
register: redis_installed
when: ansible_distribution_major_version == "7"
78 changes: 78 additions & 0 deletions tasks/facts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
---

- name: (Debian) Include os_family vars
include_vars: Debian.yml
when: ansible_os_family == "Debian"

- name: Set lists of required variables
set_fact:
redis_required_strings:
- redis_conf
- redis_daemon
- redis_conf_bind
- redis_conf_daemonize
- redis_conf_supervised
- redis_conf_pidfile
- redis_conf_logfile
- redis_conf_maxmemory
- redis_conf_maxmemory_policy
redis_required_ints:
- redis_conf_timeout
required_lists:
- redis_packages

- name: Check required Redis variables (strings)
fail:
msg: |
Invalid value for variable for '{{ item }}': {{ lookup('vars', item) }}
Supported types : String
Supported values : Any non-null string
when: >-
lookup('vars', item) is not string
or lookup('vars', item) == 0
with_items: "{{ redis_required_strings }}"

- name: Check required Redis variables (integers)
fail:
msg: |
Invalid value for variable for '{{ item }}': {{ lookup('vars', item) }}
Supported types : Integer
Supported values : A number between 0-65535
when: >-
lookup('vars', item)|int < 0
or lookup('vars', item)|int > 65535
with_items: "{{ redis_required_ints }}"

- name: Check required Redis variables (lists)
fail:
msg: |
Invalid value for variable for '{{ item }}': {{ lookup('vars', item) }}
Supported types : List, string
Supported values : Any non-null list or string
when: >-
lookup('vars', item) is not iterable
or lookup('vars', item) == 0
with_items: "{{ required_lists }}"

- name: Check variable 'systemd_restart_setting'
fail:
msg: |
Invalid value for variable 'systemd_restart_setting': '{{ systemd_restart_setting }}'
Supported types : String
Supported values : "no", "on-success", "on-failure", "on-abnormal",
"on-watchdog", "on-abort", "always"
failed_when: >-
systemd_restart_setting not in
['no', 'on-success', 'on-failure', 'on-abnormal',
'on-watchdog', 'on-abort', 'always']
or systemd_restart_setting is not string
or systemd_restart_setting == 0
when: >-
(redis_systemd_restart is defined
and redis_systemd_restart)
or (systemd_restart is defined
and systemd_restart)
41 changes: 16 additions & 25 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,19 @@
---
# tasks file for inmotion.redis

- name: (Redis) Include os_family vars
include_vars: "{{ ansible_os_family }}.yml"
vars:
targets:
- Debian
when: ansible_os_family in targets

- name: (Redis) Include os_family tasks
include: '{{ ansible_os_family }}.yml'
vars:
targets:
- Debian
- RedHat
when: ansible_os_family in targets

- name: (Redis) Install Redis if not yet performed
- name: Include variables and set facts
include: facts.yml

- name: Handle os_family errata
include: "{{ ansible_os_family }}.yml"

- name: Install Redis if not yet performed
package:
name: "{{ redis_packages }}"
state: present
when: not redis_installed.changed

- name: (Redis) Get Redis version
- name: Get Redis version
register: redis_installed_version
shell: |
set -o pipefail
Expand All @@ -31,27 +22,27 @@
executable: /bin/bash
changed_when: false

- name: (Redis) Set Redis version as fact
- name: Set Redis version as fact
set_fact:
redis_version: '{{ redis_installed_version.stdout_lines[0] }}'
redis_version: "{{ redis_installed_version.stdout_lines[0] }}"

- name: (Redis) Configure Redis
- name: Configure Redis
template:
src: redis.conf.j2
dest: '{{ redis_conf }}'
dest: "{{ redis_conf }}"
owner: root
group: root
mode: '0644'
mode: 0644

- name: Include systemd restart configuation
include: systemd.yml
when: >-
when: >-
( redis_systemd_restart|default(False)
or systemd_restart|default(False) )
and systemd_restart_setting is defined
- name: (Redis) Enable and start redis service
- name: Enable and start redis service
service:
name: '{{ redis_daemon }}'
name: "{{ redis_daemon }}"
state: started
enabled: true
4 changes: 2 additions & 2 deletions tasks/systemd.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# tasks/facts.yml

- name: (Debian) Install python-apt package
- name: (Debian/Python 3) Install python-apt package
package:
name: python3-apt
state: present
when:
- ansible_python_version is version('3.0', '>=')
- ansible_os_family == "Debian"

- name: (Debian) Install python-apt package
- name: (Debian/Python 2) Install python-apt package
package:
name: python-apt
state: present
Expand Down
6 changes: 3 additions & 3 deletions templates/redis.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ bind {{ redis_conf_bind }}
protected-mode yes
{% endif %}

{% if redis_conf_unixsocket == true %}
{% if redis_conf_unixsocket %}
port 0
{% else %}
port 6379
{% endif %}

{% if redis_conf_unixsocket == true %}
{% if redis_conf_unixsocket %}
unixsocket {{ redis_conf_unixsocket_location }}
unixsocketperm {{ redis_conf_unixsocket_permissions }}
{% endif -%}
Expand Down Expand Up @@ -75,7 +75,7 @@ repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
{% endif -%}

{% if redis_conf_requirepass != false %}
{% if redis_conf_requirepass %}
#
# SECURITY
#
Expand Down

0 comments on commit 51a7464

Please sign in to comment.