ansible批量修改redis和sentinel的密码

ansible批量修改redis和sentinel的密码

最近在读《infrastructure as code》这本书,书中给了一个怪圈。 大概是这个意思:

服务器配置不一致 -》 不敢用自动化工具,害怕用会损坏什么 -》 因此在自动化工具外手动操作 -》 导致近一步的配置不一致

然后就如此恶性循环,因此从今天起所有操作必须强迫自己用自动化工具做,帮自己跳出怪圈。
好,直接上代码:

- hosts: 'redis-cluster-p*'
tasks:
- name: stop redis
service:
name: redis
state: stopped
- name: stop redis-sentinel
service:
name: redis-sentinel
state: stopped
- name: change masterauth
lineinfile:
path: /etc/redis.conf
regexp: '^masterauth'
line: 'masterauth newpasswordxxx'
backup: yes
- name: change requirepass
lineinfile:
path: /etc/redis.conf
regexp: '^requirepass'
line: 'requirepass newpasswordxxx'
backup: yes
- name: change sentinel
lineinfile:
path: /etc/redis-sentinel.conf
regexp: '^sentinel auth-pass mymaster'
line: 'sentinel auth-pass mymaster newpasswordxxx'
backup: yes
- name: start redis
service:
name: redis
state: started
- name: start redis-sentinel
service:
name: redis-sentinel
state: started