0
votes

I'm trying to restore a MySQL database and this message is shown.

"msg": "Failed to find required executable mysql in paths: /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/sbin"

MySQL is installed in the host (I successfully restored from the command line) but when I try to execute module it doesn't work. Tried to add path as well, but nothing... Any suggestions?

Controller OS (macOS Mojave) Host OS (macOS High Sierra) MySQL 8 ansible 2.7.4

# - name: add 'mysql' to path
#   lineinfile:
#     dest: /etc/paths
#     state: present
#     backrefs: yes
#     regexp: 'PATH=(["]*)((?!.*?/usr/local/mysql/bin/).*?)(["]*)$'
#     line: 'PATH=\1\2:/usr/local/mysql/bin\3'

# - name: add 'mysql' to path
#   shell: export PATH=$PATH:/usr/local/mysql/bin && echo $PATH

- name: Copy database dump file to host
  copy:
    src: dump.sql
    dest: /tmp

- name: Restore database
  mysql_db:
    login_user: root
    login_password: password
    state: import
    name: all
    target: /tmp/dump.sql
2
You could try to add symlinks: ln -s /usr/local/mysql/bin/* /usr/local/sbin/JGK

2 Answers

2
votes

I can't easily test that specific module, but with most ansible modules you can supersede the environment for that module's invocation using the environment: argument:

- mysql_db:
    etc: etc etc
  environment:
    PATH: /the/dir/with/mysql:{{ ansible_facts.env.PATH }}
0
votes

As JGK also commented, the link also works fine!

"You could try to add symlinks: ln -s /usr/local/mysql/bin/* /usr/local/sbin/"