基于ansible部署open stack数据库服务器
时间: 2024-03-20 07:40:34 浏览: 66
openstack-ansible:Ansible手册,用于部署OpenStack。 在opendev.org上维护的代码镜像
好的,下面是部署OpenStack数据库服务器的ansible playbook,可以根据实际情况进行修改:
```yaml
---
- hosts: db_servers
become: true
vars:
# 数据库管理员用户名和密码
db_user: openstack
db_pass: openstack
# 数据库名称
keystone_db_name: keystone
glance_db_name: glance
nova_db_name: nova
neutron_db_name: neutron
cinder_db_name: cinder
manila_db_name: manila
octavia_db_name: octavia
# 数据库主机IP地址
db_host: "{{ inventory_hostname }}"
tasks:
- name: Install MariaDB server
apt:
name: mariadb-server
state: present
- name: Start MariaDB service
service:
name: mariadb
state: started
- name: Secure MariaDB installation
mysql_user:
name: root
password: "{{ db_root_password }}"
login_password: ""
state: present
register: mysql_root_user
- name: Create OpenStack database
mysql_db:
name: "{{ item }}"
login_user: root
login_password: "{{ db_root_password }}"
state: present
target: "{{ db_host }}"
loop:
- "{{ keystone_db_name }}"
- "{{ glance_db_name }}"
- "{{ nova_db_name }}"
- "{{ neutron_db_name }}"
- "{{ cinder_db_name }}"
- "{{ manila_db_name }}"
- "{{ octavia_db_name }}"
- name: Create openstack user and grant privileges
mysql_user:
name: "{{ db_user }}"
password: "{{ db_pass }}"
login_user: root
login_password: "{{ db_root_password }}"
priv: "{{ item }}.*:ALL"
host: "{{ db_host }}"
state: present
loop:
- "{{ keystone_db_name }}"
- "{{ glance_db_name }}"
- "{{ nova_db_name }}"
- "{{ neutron_db_name }}"
- "{{ cinder_db_name }}"
- "{{ manila_db_name }}"
- "{{ octavia_db_name }}"
- name: Flush privileges
mysql_db:
name: "*.*"
login_user: root
login_password: "{{ db_root_password }}"
state: flush_privs
target: "{{ db_host }}"
```
其中,`db_servers`是数据库服务器的主机组,`db_root_password`是数据库管理员的密码,需要在调用playbook时传入。此外,需要根据实际情况修改各个数据库的名称和用户密码等信息。
阅读全文