---标签:src,sysctl,name,redis,一键,state,playbook,yes From: https://blog.51cto.com/dayu/5815075
- name: install redis
hosts: all
serial: 2
vars:
- version: "redis-7.0.5"
- user: "redis"
- id: "88"
- INSTALL_DIR: "/apps/redis"
- CPUS: "2"
- PASSWORD: "123456"
tasks:
- name: rocky prepare
yum:
name: "{{ item }}"
state: present
loop:
- gcc
- make
- jemalloc-devel
- systemd-devel
when: ansible_distribution_file_variety == "RedHat"
- name: ubuntu prepare
apt:
update_cache: yes
name: "{{ item }}"
state: present
loop:
- gcc
- make
- libjemalloc-dev
- libsystemd-dev
when: ansible_distribution_file_variety == "Debian"
- name: group
group:
name: "{{ user }}"
gid: "{{ id }}"
state: present
- name: create user
user:
name: "{{ user }}"
shell: /sbin/nologin
system: yes
group: "{{ user }}"
uid: "{{ id }}"
- name: install redis
unarchive:
src: "{{ version }}.tar.gz"
dest: "/usr/local/src/"
owner: root
group: root
- name: shell make
shell: "cd /usr/local/src/{{ version }} && make -j {{ CPUS }} USE_SYSTEMD=yes PREFIX={{ INSTALL_DIR }} install"
- name: link
file:
src: "{{ INSTALL_DIR }}/bin/{{ item }}"
path: "/usr/bin/{{ item }}"
state: link
loop:
- redis-benchmark
- redis-check-aof
- redis-check-rdb
- redis-cli
- redis-sentinel
- redis-server
- name: dir
file:
path: "{{ INSTALL_DIR }}/{{ item }}"
state: directory
loop:
- etc
- log
- data
- run
- name: conf
template:
src: redis.conf.j2
dest: "{{ INSTALL_DIR }}/etc/redis.conf"
- name: chown
shell: "chown -R redis.redis {{ INSTALL_DIR }}"
- name: sysctl net.core.somaxconn
sysctl:
name: net.core.somaxconn
value: 1024
sysctl_set: yes
- name: sysctl vm.overcommit_memory
sysctl:
name: vm.overcommit_memory
value: 1
sysctl_set: yes
- name: service
template:
src: redis.service.j2
dest: /lib/systemd/system/redis.service
- name: start
service:
daemon_reload: yes
name: redis
state: started
enabled: yes