Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add mysql options to mysql_user module #26581

Closed
mohsenSy opened this issue Jul 10, 2017 · 23 comments
Closed

add mysql options to mysql_user module #26581

mohsenSy opened this issue Jul 10, 2017 · 23 comments

Comments

@mohsenSy
Copy link

@mohsenSy mohsenSy commented Jul 10, 2017

ISSUE TYPE
  • Feature Idea
COMPONENT NAME

mysql_user

ANSIBLE VERSION
ansible 2.4.0 (devel 2420bca0b5) last updated 2017/07/10 11:06:47 (GMT +300)
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/mohsen/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /home/mohsen/SourceCode/ansible/lib/ansible
  executable location = /home/mohsen/SourceCode/ansible/bin/ansible
  python version = 2.7.12 (default, Nov 19 2016, 06:48:10) [GCC 5.4.0 20160609]
OS / ENVIRONMENT

Ubuntu16.04 managing Ubuntu14.04

SUMMARY

When creating a new user using mysql_user module I cannot add extra options to user created such as MAX_USER_CONNECTIONS,MAX_CONNECTIONS_PER_HOUR etc...

STEPS TO REPRODUCE

This can be used to setup resource limits for new users as described in this web page: https://dev.mysql.com/doc/refman/5.7/en/user-resources.html

   mysql_user:
      name: mohsen
      password: mohsen_pass
      state: present
      options:
         - MAX_USER_CONNECTIONS: 50
EXPECTED RESULTS

A new user called mohsen should be created and it must be limited to 50 total connections

@ansibot
Copy link
Contributor

@ansibot ansibot commented Jul 10, 2017

@Nemie
Copy link

@Nemie Nemie commented Nov 29, 2017

Hi, any updates on this?
We are building our mysqld_exporter role for prometheus and we are stuck on trying to set MAX_USER_CONNECTIONS with mysql_user plugin. For now we have a workaround, but would be nice to do everything in the same task instead of needing subset of tasks to complement the user privileges.

@chookhong
Copy link

@chookhong chookhong commented Mar 28, 2018

I'm having the same issue in my mysqld_exporter role. Unable to set the MAX_USER_CONNECTIONS.

@petarnikolovski
Copy link

@petarnikolovski petarnikolovski commented Jun 8, 2018

I'm also building mysqld_exporter role, it would be great to have this feature. Something like this could be a workaround:

- name: Check if mysqld_exporter user exists
  command: "mysql -u mysqld_exporter -p{{ mysqld_exporter_password }}"
  register: mysqld_exporter_user
  ignore_errors: true
  no_log: true
  changed_when: false

- name: Create mysqld_exporter user
  command: mysql -u root -e "CREATE USER 'mysqld_exporter'@'localhost' IDENTIFIED BY '{{ password }}' WITH MAX_USER_CONNECTIONS 3;"
  when: mysqld_exporter_user.rc != 0

- name: Copy .my.cnf file
  template:
    src: .my.cnf.j2
    dest: /etc/mysqld_exporter/.my.cnf
    owner: mysqld_exporter
    group: mysqld_exporter
    mode: 0600

- name: Make sure mysqld_exporter user has correct privileges on databases
  mysql_user:
    name: mysqld_exporter
    host: localhost
    state: present
    priv: *.*:PROCESS,REPLICATION CLIENT

@fraff
Copy link
Contributor

@fraff fraff commented Jun 28, 2018

I would also use this option.

@drzraf
Copy link
Contributor

@drzraf drzraf commented Aug 17, 2018

Another aspect is that IDENTIFIED VIA/WITH should be supported (eg unix_socket)
See https://dev.mysql.com/doc/refman/5.5/en/create-user.html , https://wiki.debian.org/MySql
About Prometheus, see also: prometheus/mysqld_exporter#233

@ansibot
Copy link
Contributor

@ansibot ansibot commented Feb 19, 2019

@ansibot
Copy link
Contributor

@ansibot ansibot commented Feb 27, 2019

@ansibot
Copy link
Contributor

@ansibot ansibot commented Jun 3, 2019

@ansibot
Copy link
Contributor

@ansibot ansibot commented Jun 19, 2019

@pantaoran
Copy link

@pantaoran pantaoran commented Jul 29, 2019

I'm also waiting for this feature.

@ansibot
Copy link
Contributor

@ansibot ansibot commented Aug 8, 2019

@raatti
Copy link

@raatti raatti commented Aug 14, 2019

Also waiting for this...

@ansibot
Copy link
Contributor

@ansibot ansibot commented Dec 20, 2019

@minhdanh
Copy link

@minhdanh minhdanh commented Jan 8, 2020

Any updates on this?

@CSimpiFoN
Copy link

@CSimpiFoN CSimpiFoN commented Jan 16, 2020

Seems none cares :(

@bmalynovytch
Copy link
Contributor

@bmalynovytch bmalynovytch commented Jan 16, 2020

People do care, but we don't always have enough time to address all the issues.
The changes you request shouldn't be hard to implement, which could be a good time for new contributors to step in !
Feel free to give it a try, we'll be glad to help you and review your work.

@p-le
Copy link

@p-le p-le commented Mar 11, 2020

My current workaround
using mysql_db to import sql file.

CREATE USER '{{ mysql_users.exporter.name }}'@'localhost' IDENTIFIED BY '{{ mysql_users.exporter.password }}' WITH MAX_USER_CONNECTIONS 2;
GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO '{{ mysql_users.exporter.name }}'@'localhost';
FLUSH PRIVILEGES;
- name: Copy expoter sql
  template:
    src: "sql/exporter.sql.j2"
    dest: "/tmp/exporter.sql"
  tags:
    - prometheus

- name: "Add '{{ mysql_users.exporter.name }}' user"
  mysql_db:
    state: import
    name: aladdin
    target: /tmp/exporter.sql
    login_user: root
    login_password: "{{ mysql_users.root.password }}"
  tags:
    - prometheus

@Andersson007
Copy link
Contributor

@Andersson007 Andersson007 commented Apr 8, 2020

close_me

@Andersson007
Copy link
Contributor

@Andersson007 Andersson007 commented Apr 8, 2020

was copied to community.general repo ansible-collections/community.general#133

@ansibot ansibot closed this Apr 8, 2020
@Andersson007
Copy link
Contributor

@Andersson007 Andersson007 commented Apr 9, 2020

hey, folks!
Who are interested in a new parameter for this, i've implemented it via ansible-collections/community.general#142
Would be nice to get a couple of reviews

@Andersson007
Copy link
Contributor

@Andersson007 Andersson007 commented Apr 9, 2020

if the changes are ok, please put shipit in the PR

@Andersson007
Copy link
Contributor

@Andersson007 Andersson007 commented Apr 13, 2020

merged, thanks all!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet