0

This is my yml file which should update system, install mysql-server, change binding and run steps from "mysql_secure_installation".

---
# tasks file for deploy_db
- name: Update repos
  apt:
    name: "*"
    state: latest
    update_cache: yes

- name: Install mysql
  apt:
    name:
    - mysql-server
    - python-pymysql
    - python-apt
    state: latest

- name: Autostart mysql
  service:
    name: mysql
    enabled: yes

- name: Change mysql default binding
  replace:
    path: /etc/mysql/mysql.conf.d/mysqld.cnf
    regexp: '127.0.0.1'
    replace: '0.0.0.0'

- name: Reboot after initial update
  reboot:

- name: Remove the test database
  mysql_db:
    login_unix_socket: /var/run/mysqld/mysqld.sock
    name: test
    state: absent

- name: Remove anonymous user
  mysql_user:
    login_unix_socket: /var/run/mysqld/mysqld.sock
    name: ''
    state: absent

If I play this yml first time - Ansible shows me error:

TASK [deploy_db : Remove the test database] ********************************************************************************************************************
fatal: [db]: FAILED! => {"changed": false, "msg": "The PyMySQL (Python 2.7 and Python 3.X) or MySQL-python (Python 2.X) module is required."}

If I play the same file second time - everything is OK.

What do I do wrong? "python-pymysql" which is required for task "Remove the test database" is installed some steps before and there was a reboot, everything should works but it doesn't!

0

Oh, correct question is a half of answer :-) I've modified task and now everything is OK

  - name: Install mysql
  apt:
    name:
    - mysql-server
    - python-pymysql
    - python3-pymysql
    - python-apt
    - python3-apt
  state: latest

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.