Ansible-完成redis服务搭建

1.roles/redis/tasks/main.yml

`# 安装redis
yum -y install redis

`# 配置redis服务
sed -i '/bind 127.0.0.1/cbind 127.0.0.1 172.16.1.51' /etc/redis.conf

`# 启动服务并加入自启动
systemctl start redis
systemctl enable redis
- name: Install redis
  yum:
    name: redis
    state: installed

- name: Configure redis
  replace:
    path: /etc/redis.conf
    regexp: '^# bind 127.0.0.1$'
    replace: 'bind 127.0.0.1 172.16.1.51'
  notify: Restart redis

- name: Start redis
  systemd:
    name: redis
    state: started
    enabled: yes

2.roles/redis/handlers/main.yml

# 重启redis服务,使配置文件生效
systemctl restart redis
- name: Restart redis
  systemd:
    name: redis
    state: restarted

你可能感兴趣的:(Ansible-完成redis服务搭建)