Mysql – How to install thesql server using ansible playbook

ansibleansible-playbookMySQL

I am trying to install mysql server on centos using ansible playbook. My yml file looks like above.

---
- 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

But it getting error.

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"]}

How can i fix this issue?

Best Answer

I had to download and add the repository and then update.

   - 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