Playbook部署redis

1、编写安装redis playbook

cat << 'CAT_END' > install_redis.yaml
- hosts: redis
  tasks:
    - name: Install redis Server
      yum:
        name: redis
        state: present
    - name: Configure httpd Server
      copy:
        src: ./conf/redis.conf.j2
        dest: /etc/redis.conf
        owner: redis
        group: root
        mode: '0640'
        backup: yes
      notify: restart redis server
    - name: Systemd redis Server
      systemd:
        name: redis
        state: started
        enabled: yes
  handlers:
    - name: restart redis server
      systemd:
        name: redis
        state: restarted
CAT_END

2、语法检查

ansible-playbook install_redis.yaml --syntax-check

3、准备配置文件

scp root@192.168.10.16:/etc/redis.conf conf/redis.conf.j2
sed -i '/^bind 1/c bind 0.0.0.0' conf/redis.conf.j2 

4、部署redis

]# ansible-playbook install_redis.yaml 

PLAY [redis] *************************************************************************************************************************************************

TASK [Gathering Facts] ***************************************************************************************************************************************
ok: [192.168.10.15]

TASK [Install redis Server] **********************************************************************************************************************************
ok: [192.168.10.15]

TASK [Configure httpd Server] ********************************************************************************************************************************
changed: [192.168.10.15]

TASK [Systemd redis Server] **********************************************************************************************************************************
changed: [192.168.10.15]

RUNNING HANDLER [restart redis server] ***********************************************************************************************************************
changed: [192.168.10.15]

PLAY RECAP ***************************************************************************************************************************************************
192.168.10.15              : ok=5    changed=3    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

5、测试登陆

]# redis-cli 
127.0.0.1:6379> 

 

posted @ 2023-05-12 11:39  小粉优化大师  阅读(32)  评论(0编辑  收藏  举报