Skip to content

Commit

Permalink
enh: Move source installation in splitted files
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel Mutel committed Jul 9, 2021
1 parent 1a8bb6f commit 9fe8f2a
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 65 deletions.
3 changes: 3 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
---
## Installation options
redis_install_method: "source"
redis_version: 2.8.24
redis_install_dir: /opt/redis
redis_dir: /var/lib/redis/{{ redis_port }}
redis_config_file_name: "{{ redis_port }}.conf"
redis_download_url: "http://download.redis.io/releases/redis-{{ redis_version }}.tar.gz"
redis_package: redis-server
redis_pin_package: false

redis_protected_mode: "yes"
# Set this to true to validate redis tarball checksum against vars/main.yml
Expand Down
14 changes: 13 additions & 1 deletion tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,26 @@
- include: check_vars.yml

- include: download.yml
when: redis_install_method == "source"
tags:
- download

- include: dependencies.yml
when: redis_install_method == "source"
tags:
- install

- include: install.yml
- include: setup.yml
tags:
- install

- include: package.yml
when: redis_install_method == "package"
tags:
- install

- include: source.yml
when: redis_install_method == "source"
tags:
- install

Expand Down
19 changes: 19 additions & 0 deletions tasks/package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
- name: Install Redis package
package:
name: "{{ redis_package }}={{ redis_version }}"
state: present

- name: 'Pin consul release'
copy:
dest: /etc/apt/preferences.d/consul
owner: root
group: root
mode: '0644'
content: |
Package: {{ redis_package }}
Pin: version {{ redis_version }}
Pin-Priority: 1001
when:
- redis_pin_package
- ansible_distribution == "Ubuntu" or ansible_distribution == "Debian"
113 changes: 58 additions & 55 deletions tasks/server.yml
Original file line number Diff line number Diff line change
@@ -1,63 +1,66 @@
---
- name: create redis working directory
file:
path: "{{ redis_dir }}"
state: directory
recurse: yes
owner: "{{ redis_user }}"
- name: post setup source installation
block:
- name: create redis working directory
file:
path: "{{ redis_dir }}"
state: directory
recurse: yes
owner: "{{ redis_user }}"

- name: create redis init script
template:
src: "{{ item }}"
dest: /etc/init.d/{{ redis_service_name }}
mode: 0755
# Choose the distro-specific template. We must specify the templates
# path here because with_first_found tries to find files in files/
with_first_found:
- files:
- "{{ ansible_os_family }}/redis.init.j2"
- default/redis.init.j2
paths:
- ../templates
when: redis_as_service and ansible_service_mgr|default() != "systemd"

- name: create redis systemd service
template:
src: "{{ item }}"
dest: /etc/systemd/system/{{ redis_service_name }}.service
mode: 0644
with_first_found:
- files:
- "{{ ansible_os_family }}/redis.service.j2"
- default/redis.service.j2
paths:
- ../templates
register: redis_unit_file
when: redis_as_service and ansible_service_mgr|default() == "systemd"

- name: create systemd tmpfiles configuration
template:
src: etc/tmpfiles.d/redis.conf.j2
dest: /etc/tmpfiles.d/redis.conf
mode: 0644
when:
- redis_as_service
- ansible_service_mgr|default() == 'systemd'
- (redis_pidfile|dirname).startswith('/var/run') or (redis_pidfile|dirname).startswith('/run')
- name: create redis init script
template:
src: "{{ item }}"
dest: /etc/init.d/{{ redis_service_name }}
mode: 0755
# Choose the distro-specific template. We must specify the templates
# path here because with_first_found tries to find files in files/
with_first_found:
- files:
- "{{ ansible_os_family }}/redis.init.j2"
- default/redis.init.j2
paths:
- ../templates
when: redis_as_service and ansible_service_mgr|default() != "systemd"

- name: reload systemd daemon
systemd:
daemon_reload: true
when:
- redis_as_service
- ansible_service_mgr|default() == "systemd"
- redis_unit_file is changed
- name: create redis systemd service
template:
src: "{{ item }}"
dest: /etc/systemd/system/{{ redis_service_name }}.service
mode: 0644
with_first_found:
- files:
- "{{ ansible_os_family }}/redis.service.j2"
- default/redis.service.j2
paths:
- ../templates
register: redis_unit_file
when: redis_as_service and ansible_service_mgr|default() == "systemd"

- name: create systemd tmpfiles configuration
template:
src: etc/tmpfiles.d/redis.conf.j2
dest: /etc/tmpfiles.d/redis.conf
mode: 0644
when:
- redis_as_service
- ansible_service_mgr|default() == 'systemd'
- (redis_pidfile|dirname).startswith('/var/run') or (redis_pidfile|dirname).startswith('/run')

- name: reload systemd daemon
systemd:
daemon_reload: true
when:
- redis_as_service
- ansible_service_mgr|default() == "systemd"
- redis_unit_file is changed
when: redis_install_method == "source"

- name: set redis to start at boot
service:
name: "{{ redis_service_name }}"
enabled: yes
when: redis_as_service
when: redis_as_service or redis_install_method == "package"

# Check then create log dir to prevent aggressively overwriting permissions
- name: check if log directory exists
Expand Down Expand Up @@ -85,7 +88,7 @@
owner: "{{ redis_user }}"
group: "{{ redis_group }}"
when: redis_logfile != '""'

- name: update permissions of log file if needed
file:
state: file
Expand Down Expand Up @@ -124,15 +127,15 @@
dest: /etc/sysconfig/{{ redis_service_name }}
src: redis.init.conf.j2
mode: 0600
when: ansible_os_family == "RedHat"
when: ansible_os_family == "RedHat" and redis_install_method == "source"
notify: "restart redis"

- name: add redis init config file
template:
dest: /etc/default/{{ redis_service_name }}
src: redis.init.conf.j2
mode: 0600
when: ansible_os_family == "Debian"
when: ansible_os_family == "Debian" and redis_install_method == "source"
notify: "restart redis"

# Flush handlers before ensuring the service is started to prevent
Expand Down
9 changes: 9 additions & 0 deletions tasks/setup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
- name: enable overcommit in sysctl
sysctl:
name: vm.overcommit_memory
value: "1"
state: present
reload: yes
ignoreerrors: yes
when: redis_travis_ci is not defined
9 changes: 0 additions & 9 deletions tasks/install.yml → tasks/source.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
---
- name: enable overcommit in sysctl
sysctl:
name: vm.overcommit_memory
value: "1"
state: present
reload: yes
ignoreerrors: yes
when: redis_travis_ci is not defined

- name: compile redis
shell: umask 0022 && make -j{{ ansible_processor_cores|default(1) + 1 }}{{ ' 32bit' if redis_make_32bit|bool else '' }}{{ ' BUILD_TLS=yes' if redis_make_tls|bool else '' }}
args:
Expand Down

0 comments on commit 9fe8f2a

Please sign in to comment.