Coder Social home page Coder Social logo

geerlingguy / ansible-role-redis Goto Github PK

View Code? Open in Web Editor NEW
237.0 12.0 188.0 60 KB

Ansible Role - Redis

Home Page: https://galaxy.ansible.com/geerlingguy/redis/

License: MIT License

Jinja 100.00%
ansible role redis cache memcached key-value

ansible-role-redis's Introduction

Ansible Role: Redis

CI

Installs Redis on Linux.

Requirements

On RedHat-based distributions, requires the EPEL repository (you can simply add the role geerlingguy.repo-epel to install ensure EPEL is available).

Role Variables

redis_enablerepo: epel

(Used only on RHEL/CentOS) The repository to use for Redis installation.

Available variables are listed below, along with default values (see defaults/main.yml):

redis_port: 6379
redis_bind_interface: 127.0.0.1

Port and interface on which Redis will listen. Set the interface to 0.0.0.0 to listen on all interfaces.

redis_unixsocket: ''

If set, Redis will also listen on a local Unix socket.

redis_timeout: 300

Close a connection after a client is idle N seconds. Set to 0 to disable timeout.

redis_loglevel: "notice"
redis_logfile: /var/log/redis/redis-server.log

Log level and log location (valid levels are debug, verbose, notice, and warning).

redis_databases: 16

The number of Redis databases.

# Set to an empty set to disable persistence (saving the DB to disk).
redis_save:
  - 900 1
  - 300 10
  - 60 10000

Snapshotting configuration; setting values in this list will save the database to disk if the given number of seconds (e.g. 900) and the given number of write operations (e.g. 1) have occurred.

redis_rdbcompression: "yes"
redis_dbfilename: dump.rdb
redis_dbdir: /var/lib/redis

Database compression and location configuration.

    redis_maxmemory: 0

Limit memory usage to the specified amount of bytes. Leave at 0 for unlimited.

redis_maxmemory_policy: "noeviction"

The method to use to keep memory usage below the limit, if specified. See Using Redis as an LRU cache.

redis_maxmemory_samples: 5

Number of samples to use to approximate LRU. See Using Redis as an LRU cache.

redis_appendonly: "no"

The appendonly option, if enabled, affords better data durability guarantees, at the cost of slightly slower performance.

redis_appendfsync: "everysec"

Valid values are always (slower, safest), everysec (happy medium), or no (let the filesystem flush data when it wants, most risky).

# Add extra include files for local configuration/overrides.
redis_includes: []

Add extra include file paths to this list to include more/localized Redis configuration.

The redis package name for installation via the system package manager. Defaults to redis-server on Debian and redis on RHEL.

redis_package_name: "redis-server"

(Default for RHEL shown) The redis package name for installation via the system package manager. Defaults to redis-server on Debian and redis on RHEL.

redis_requirepass: ""

Set a password to require authentication to Redis. You can generate a strong password using echo "my_password_here" | sha256sum.

redis_disabled_commands: []

For extra security, you can disable certain Redis commands (this is especially important if Redis is publicly accessible). For example:

redis_disabled_commands:
  - FLUSHDB
  - FLUSHALL
  - KEYS
  - PEXPIRE
  - DEL
  - CONFIG
  - SHUTDOWN
redis_extra_config: |-
  # Extra redis configuration lines can be added here.

Extra Redis configuration lines that will be appended to the end of the redis.conf file.

Dependencies

None.

Example Playbook

- hosts: all
  roles:
    - role: geerlingguy.redis

License

MIT / BSD

Author Information

This role was created in 2014 by Jeff Geerling, author of Ansible for DevOps.

ansible-role-redis's People

Contributors

agrrh avatar bmcclure avatar danielshiplett avatar frinux avatar geerlingguy avatar leventyalcin avatar tersmitten avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ansible-role-redis's Issues

redis 6.2.1 Failed with result 'protocol'

redis 6.2.1 Failed with result 'protocol'
Fixed after adding "supervised auto" to templates/redis.conf.j2

OS VERSION="20.04.2 LTS (Focal Fossa)"

pre_tasks:
- name: Add chris-lea APT repositories
apt_repository:
repo: "ppa:redislabs/redis"
state: present
update_cache: yes

Explicitly disable RDB persistence

Doc says:

"# Set to an empty set to disable persistence (saving the DB to disk)."

So, when setting:

redis_save: []

However, this just writes nothing about the Redis "save" settings. If for whatever reason RDB persistence is enabled by default this role won't disable it.

Add Replication

Would find it very useful if this role also supported Redis Sentinel. Would you be opposed to adding that functionality?

Thanks -
John

'vm-enabled no' startup error.

I'm seeing the same issue as those reported here:
bennojoy/redis#6

Shell output:

$ redis-server --version
Redis server v=2.8.4 sha=00000000:0 malloc=jemalloc-3.4.1 bits=64 build=a44a05d76f06a5d9

$ sudo redis-server /etc/redis/redis.conf 

*** FATAL CONFIG FILE ERROR ***
Reading the configuration file, at line 34
>>> 'vm-enabled no'
Bad directive or wrong number of arguments

redis_requirepass not working

Hello, I just use the role, but I'm getting an error running a Node.Js instance:

Redis server does not require a password, but a password was supplied.

which means that redis is not working:

vars:
    nodejs_version: "10.x"
    nodejs_npm_global_packages:
      - name: pm2
    redis_requirepass: "aaa..."
  roles:
    - geerlingguy.nodejs
    - geerlingguy.redis

`redis-server` installation fails when IPv6 is disabled

I used this Redis role after OS hardening role which disabled all IPv6 settings in sysctl.conf. That resulted in the failure of apt-get install redis-server (I'm on Ubuntu server) command.

Error output is:

Reading package lists...
Building dependency tree...
Reading state information...
redis-server is already the newest version (5:4.0.9-1ubuntu0.1).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
1 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Setting up redis-server (5:4.0.9-1ubuntu0.1) ...
Job for redis-server.service failed because a timeout was exceeded.
See \"systemctl status redis-server.service\" and \"journalctl -xe\" for details.
invoke-rc.d: initscript redis-server, action \"start\" failed.
* redis-server.service - Advanced key-value store
   Loaded: loaded (/lib/systemd/system/redis-server.service; disabled; vendor preset: enabled)
   Active: activating (auto-restart) (Result: timeout) since Wed 2019-01-30 15:26:36 MSK; 7ms ago
     Docs: http://redis.io/documentation,
           man:redis-server(1)

Jan 30 15:26:36 eps-lw-banking systemd[1]: \u001b[0;1;31m\u001b[0;1;39m\u001b[0;1;31mFailed to start Advanced key-value store.\u001b[0m
dpkg: error processing package redis-server (--configure):
 installed redis-server package post-installation script subprocess returned error exit status 1
Errors were encountered while processing:
 redis-server

The problem is that default redis.conf from redis-server package contains bind 127.0.0.1 ::1 line, so Redis tries to bind on disabled IPv6 address and hangs.

I found discussions of this problem on Ubuntu and Debian bugtrackers. I understand that this is more redis-server package problem than the problem of this role, but it would be great if this role had a workaround for this situation.

By default, this role is configured to set bind to 127.0.0.1 (redis_bind_interface setting), so I found the following solution: I changed the order of Redis configuration and Redis installation tasks in the play, and I also added the task for creating the /etc/redis dir:

- name: Ensure Redis configuration dir exists.
  file:
    path: "{{ redis_conf_path | dirname }}"
    state: directory
    mode: 0755

- name: Ensure Redis is configured.
  template:
    src: redis.conf.j2
    dest: "{{ redis_conf_path }}"
    mode: 0644
  notify: restart redis

# Setup/install tasks.
- include_tasks: setup-Debian.yml
  when: ansible_os_family == 'Debian'

Now, when redis-server installation happens, the installer uses preconfigured redis.conf and all works even if IPv6 is totally disabled.

Expose all configuration variable as redis_* ansible vars

A lot of variable can't be managed by ansible. I don't want to change them by hand, that's the point of using ansible.

As a side note, the syslog part in the template is absurd, you can't say # Ansible managed at the top of the file and then tell the user to edit by hand.

I use my fork at the moment, I send a PR as soon as I test how redis plays with unknown conf variables. If it doesn't play well we will have to create one template per redis version. (like ANXS.postgresql role does)

Does not enable as a systemd service

Using this role I found that systemctl status redis-server would return

redis-server.service - Advanced key-value store
   Loaded: loaded (/lib/systemd/system/redis-server.service; disabled; vendor preset: enabled)
   Active: active (running) since Wed 2018-12-05 19:35:24 UTC; 2min 39s ago
     Docs: http://redis.io/documentation,
           man:redis-server(1)
 Main PID: 13355 (redis-server)
    Tasks: 4 (limit: 4383)
   CGroup: /system.slice/redis-server.service
           `-13355 /usr/bin/redis-server 127.0.0.1:6379

In tasks/main.yml there is the line service: "name={{ redis_daemon }} state=started enabled=yes" which should enable the service.

To get around this I added my own task after the geerlingguy.redis role completed:

- name: enable redis-server
  systemd:
    name: redis-server
    enabled: yes
  when: ansible_service_mgr == 'systemd'

which effectively didn't change anything.
I finally tried:

- name: Ensure redis-server is enabled
  shell: systemctl enable redis-server
  register: enable_result
  when: ansible_service_mgr == 'systemd'
  changed_when: "'Created symlink' in enable_result.stderr" 

this did work with the output:

changed: [voltserv-app-04] => {
    "changed": true,
    "cmd": "systemctl enable redis-server",
    "delta": "0:00:00.500761",
    "end": "2018-12-05 19:03:05.330731",
    "invocation": {
        "module_args": {
            "_raw_params": "systemctl enable redis-server",
            "_uses_shell": true,
            "argv": null,
            "chdir": null,
            "creates": null,
            "executable": null,
            "removes": null,
            "stdin": null,
            "warn": true
        }
    },
    "rc": 0,
    "start": "2018-12-05 19:03:04.829970",
    "stderr": "Synchronizing state of redis-server.service with SysV service script with /lib/systemd/systemd-sysv-install.\nExecuting: /lib/systemd/systemd-sysv-install enable redis-server\nCreated symlink /etc/systemd/system/redis.service -> /lib/systemd/system/redis-server.service.",
    "stderr_lines": [
        "Synchronizing state of redis-server.service with SysV service script with /lib/systemd/systemd-sysv-install.",
        "Executing: /lib/systemd/systemd-sysv-install enable redis-server",
        "Created symlink /etc/systemd/system/redis.service -> /lib/systemd/system/redis-server.service."
    ],
    "stdout": "",
    "stdout_lines": []
}changed: [voltserv-app-04] => {
    "changed": true,
    "cmd": "systemctl enable redis-server",
    "delta": "0:00:00.500761",
    "end": "2018-12-05 19:03:05.330731",
    "invocation": {
        "module_args": {
            "_raw_params": "systemctl enable redis-server",
            "_uses_shell": true,
            "argv": null,
            "chdir": null,
            "creates": null,
            "executable": null,
            "removes": null,
            "stdin": null,
            "warn": true
        }
    },
    "rc": 0,
    "start": "2018-12-05 19:03:04.829970",
    "stderr": "Synchronizing state of redis-server.service with SysV service script with /lib/systemd/systemd-sysv-install.\nExecuting: /lib/systemd/systemd-sysv-install enable redis-server\nCreated symlink /etc/systemd/system/redis.service -> /lib/systemd/system/redis-server.service.",
    "stderr_lines": [
        "Synchronizing state of redis-server.service with SysV service script with /lib/systemd/systemd-sysv-install.",
        "Executing: /lib/systemd/systemd-sysv-install enable redis-server",
        "Created symlink /etc/systemd/system/redis.service -> /lib/systemd/system/redis-server.service."
    ],
    "stdout": "",
    "stdout_lines": []
}

I would expect that the service should be enabled to start with, and also that the initial attempt to enable would work. I wouldn't rule out user error but figured I'd submitted an issue anyway. Let me know if I can provide any other info.

- Ansible version: ansible 2.6.2
  config file = None
  configured module search path = [u'/Users/greggbailey/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python2.7/site-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 2.7.15 (default, Jun 17 2018, 12:46:58) [GCC 4.2.1 Compatible Apple LLVM 9.1.0 (clang-902.0.39.2)]
- Machine running ansible playbook: macOS Mojave 10.14.1
- Linux version: NAME="Ubuntu"
VERSION="18.04.1 LTS (Bionic Beaver)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 18.04.1 LTS"
VERSION_ID="18.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=bionic
UBUNTU_CODENAME=bionic
- geerlinguy.redis: 1.6.0 (also experienced issue on 1.5.1)

New Options To Fix Warning Messages

Hi, we use this Ansible Role. So far so good but we get the following warnings when starting Redis:

#1 WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.

#2 WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.

#3 WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.

Although these are only warnings it would be nice to have the option to fix them. This blog post describes all these warnings and gives (bash like) solutions on how to get rid of them:

I'm envisioning some new options a user could set, theoretical examples:

Here are some Ansible snippets with the same solutions as described in the blog post that could be inspiring.

Fix for 1 and 2

https://github.com/QafooLabs/redis-testing/blob/master/provision.yml

Fix for 2

https://github.com/akishin/ansible-playbooks/blob/master/gitlab-unicorn/roles/redis/tasks/main.yml

Fix for 3

https://github.com/jamielinux/ansible-discourse/blob/master/roles/redis/files/disable-transparent-huge-pages.service

There are many other examples in GitHub but no reusable Ansible role repo seems to have all of them in one place.

Thank you for your consideration.

'check_mode is not a legal parameter'

When using current master 155a98cd I get followig error:

web: Running ansible-playbook...
 [WARNING]: It is unnecessary to use '{{' in loops, leave variables in loop
expressions bare.

 [WARNING]: It is unnecessary to use '{{' in conditionals, leave variables in
loop expressions bare.

ERROR: check_mode is not a legal parameter in an Ansible task or handler
Ansible failed to complete successfully. Any error output should be
visible above. Please fix these errors and try again.

What am I doing wrong?

Redis Cluster

Do you want to support redis cluster in this role? When yes, then I can provide a pull request.

Multiple Instances?

I have a need to run 2 redis instances on the same server.

Each would be the same, but using a different backup strategy. (Underlying requirement is a queue with sensitive data that can't get written to disk, and accepting the failure tolerance that goes with that)

Would it be possible to provision both instances using this role? Or would I be better off installing 1 (which I already have) and using Ansible file manipulation to create the second one "by hand"?

Thanks

package is not a legal parameter in an Ansible task or handler

When using the current master (a76cee5) of ansible-role-redis, I get this error (with ansible 1.9.4):

ERROR: package is not a legal parameter in an Ansible task or handler

I reverted to tag 1.3.0 and it works again.

Maybe the master only works with ansible 2+?

Thanks for providing this role :)

i am ruuning my ansible code i got this error

fatal: [13.127.200.142]: FAILED! => {"failed": true, "msg": "Unable to create local directories(/home/ubuntu/.ansible/cp): [Errno 13] Permission denied: '/home/ubuntu/.ansible/cp'"}

Add redis_install_from_source option

Add an option to install Redis from source (so users can have the latest possible version, instead of just the versions available through the default apt repos or EPEL).

Error when installing from official Redis repository on Ubuntu

This happens when configuring a Ubuntu 20.04 server with the official Redis Ubuntu PPA (not the built-in one). I don't see documentation related to this method not being supported, and so I'm creating this issue. The reason I am using this repo is that Ubuntu 20.04's repo defaults to Redis 5 but I want to install Redis 6.

I set the following variables in my playbook:

---
redis_package: redis
redis_maxmemory: 512M
redis_maxmemory_policy: allkeys-lfu
redis_save: []

I have this set in my pre_tasks:

  pre_tasks:
    - name: Add repository for packages
      apt_repository:
        repo: "{{ item }}"
        state: present
      with_items:
        - ppa:redislabs/redis

I see an error during the playbook run which I can manually reproduce too. Here's the output:

Oct 31 23:58:55 localhost systemd[1]: redis-server.service: Failed with result 'protocol'.
Oct 31 23:58:55 localhost systemd[1]: Failed to start Advanced key-value store.
Full output
$ apt-get install redis
Reading package lists... Done
Building dependency tree
Reading state information... Done
redis is already the newest version (6:6.2.6-1rl1~focal1).
0 upgraded, 0 newly installed, 0 to remove and 68 not upgraded.
2 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] Y
Setting up redis-server (6:6.2.6-1rl1~focal1) ...
Job for redis-server.service failed because the service did not take the steps required by its unit configuration.
See "systemctl status redis-server.service" and "journalctl -xe" for details.
invoke-rc.d: initscript redis-server, action "start" failed.
โ— redis-server.service - Advanced key-value store
     Loaded: loaded (/lib/systemd/system/redis-server.service; disabled; vendor preset: enabled)
     Active: activating (auto-restart) (Result: protocol) since Sun 2021-10-31 23:58:55 UTC; 5ms ago
       Docs: http://redis.io/documentation,
             man:redis-server(1)
    Process: 33353 ExecStart=/usr/bin/redis-server /etc/redis/redis.conf (code=exited, status=0/SUCCESS)
   Main PID: 33353 (code=exited, status=0/SUCCESS)

Oct 31 23:58:55 localhost systemd[1]: redis-server.service: Failed with result 'protocol'.
Oct 31 23:58:55 localhost systemd[1]: Failed to start Advanced key-value store.
dpkg: error processing package redis-server (--configure):
 installed redis-server package post-installation script subprocess returned error exit status 1
dpkg: dependency problems prevent configuration of redis:
 redis depends on redis-server (<< 6:6.2.6-1rl1~focal1.1~); however:
  Package redis-server is not configured yet.
 redis depends on redis-server (>= 6:6.2.6-1rl1~focal1); however:
  Package redis-server is not configured yet.

dpkg: error processing package redis (--configure):
 dependency problems - leaving unconfigured
No apport report written because the error message indicates its a followup error from a previous failure.
                                                                                                          Errors were encountered while processing:
 redis-server
 redis
E: Sub-process /usr/bin/dpkg returned an error code (1)

After searching about this, I found the configuration option supervised which is set to no by default. But this needs to be set to systemd (or auto) for it to work as a service.

Now, I am not sure why this works right now. But adding supervised auto in my redis.conf is enough to get it to run without errors. I see this setting is present since Redis 3.2, so it might be safe to set it in the template here.

How is defined ansible_os_family?

in the main inside tasks there is a include_vars: "{{ ansible_os_family }}.yml"
but i can't find this variable anywhere and indeed the deploy is failing.
where can i find it?

many thanks

Error with redis pid file

Hello,

I used this role to install redis on debian system.
When starting the command systemctl status redis-server, the error message below is displayed:

May 02 21:41:46 netbox-db-dc1-01 systemd[1]: redis-server.service: Can't open PID file /run/redis/redis-server.pid

The systemd configuration file provided by the package is using /run/redis/redis-server.pid as pid file.

The template in this project is using /var/run/redis/redis-server.pid.

Provide packages for Redis from redis.io

Hi,

i would be nice if this ansible role provide a possibility to got redis packes from the redis.io repository.
Currently Debian Std. Repo provides redis 6.0.x and debian backport 7.0.x.
On redis.io, redis is available up to 7.2.x.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.