我正在尝试使用 ansible playbook 在 centos 上安装 mysql 服务器。我的 yml 文件如上所示。
---
- name: Install MySQL database server
hosts: test
become: yes
become_method: sudo
gather_facts: true
tags: [database]
tasks:
- name: Update the software package repository
yum:
update_cache: yes
- name: Install MySQL
package:
name: "{{ item }}"
state: latest
with_items:
- mysql-server
- mysql-client
- python-mysqldb
但它出现错误。
failed: [192.168.94.151] (item=mysql-server) => {"changed": false, "item": "mysql-server", "msg": "No package matching 'mysql-server' found available, installed or updated", "rc": 126, "results": ["No package matching 'mysql-server' found available, installed or updated"]}
我该如何修复此问题?
答案1
我必须下载并添加存储库,然后更新。
- name: Download sources
get_url:
url: http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
dest: /opt/mysql
- name: Install package
yum:
name: /opt/mysql/mysql-community-release-el7-5.noarch.rpm
state: present
- name: Install MySQL
yum: name=mysql-server state=installed