【发布时间】:2015-02-04 16:47:15
【问题描述】:
我正在尝试为 mysql 安装编写一个单页 ansible 脚本,并设置一个新用户并创建一个空数据库。到目前为止我尝试过的 -
hosts文件
[mysql]
webapp ansible_ssh_host=xxx.xxx.xxx.xxx
mysql.yml(所有任务/vars/handelers 的单个文件)(hosts 和 mysql.yml 在同一目录中),我可以使用 ssh 登录远程系统
---
- hosts: mysql
vars:
- system_packages:
- build-essential
- python-dev
- python-pip
- libmysqlclient-dev
- mysql-server
- python-mysqldb
- root_password: root
tasks:
- name: Install MySQL
apt: pkg={{ item }} state=installed update-cache=yes
with_items: system_packages
tags:
- setup
- name: Start MySQL service
action: service name=mysql state=started enabled=yes
- name: Update mysql password for root account
mysql_user: name=root host={{ item }} password={{root_password}}
with_items:
- 127.0.0.1 #In case of distributed system how should I place Ip addr of this system
- localhost
- name: create db 'mydb'
action: mysql_db db=mydb state=present
- name: Creates database user 'eric' with password 'eric' for 'mydb' and grant all priveleges
action: mysql_user state=present name=eric password=eric priv=mydb.*:ALL
handlers:
- name: start mysql
service: name=mysql state=started
当我运行这个脚本时,我得到这个输出(+错误)
failed: [webapp] => (item=127.0.0.1) => {"failed": true, "item": "127.0.0.1"}
msg: unable to connect to database, check login_user and login_password are correct or ~/.my.cnf has the credentials
【问题讨论】:
-
这看起来像是一个没有目标信息的代码转储。读者可能无法确定“您要达到什么目标?”请相应地编辑问题。
标签: mysql mysql-python ansible ansible-playbook