ansible-playbook 安装redis
时间: 2024-05-20 22:09:38 浏览: 27
安装redis可以使用ansible-playbook,可以使用以下步骤进行操作:
1. 创建一个新的playbook文件,比如"install_redis.yml"。
2. 在playbook文件中,定义主机组和变量。例如:
```
---
- hosts: webserver
become: true
vars:
redis_port: 6379
redis_version: 5.0.5
```
3. 添加任务,用于安装Redis。你可以使用"apt"模块或"yum"模块,具体根据你的操作系统来选择:
```
- name: Install Redis
apt:
name: redis-server
state: present
update_cache: yes
become: true
```
4. 添加任务,用于修改Redis配置文件。你可以使用"lineinfile"模块或"template"模块,具体根据你的需要来选择:
```
- name: Set Redis Configuration
lineinfile:
path: /etc/redis/redis.conf
regexp: "^port.*"
line: "port {{ redis_port }}"
become: true
```
5. 添加任务,用于启动Redis服务:
```
- name: Start Redis Service
service:
name: redis-server
state: started
enabled: yes
become: true
```
6. 运行playbook,以安装Redis:
```
ansible-playbook install_redis.yml
```