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
Labels
affects_2.4 This issue/PR affects Ansible v2.4 database Database category feature This issue/PR relates to a feature request. module This issue/PR relates to a module. mysql support:community This issue/PR relates to code supported by the Ansible community. test This PR relates to tests.

Comments

@mohsenSy
Copy link

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 commented Jul 10, 2017

@ansibot ansibot added affects_2.4 This issue/PR affects Ansible v2.4 feature_idea module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. support:community This issue/PR relates to code supported by the Ansible community. labels Jul 10, 2017
@alikins alikins removed the needs_triage Needs a first human triage before being processed. label Jul 10, 2017
@Nemie
Copy link

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.

@ansibot ansibot added feature This issue/PR relates to a feature request. and removed feature_idea labels Mar 2, 2018
@chookhong
Copy link

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

@petarnikolovski
Copy link

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 commented Jun 28, 2018

I would also use this option.

@drzraf
Copy link
Contributor

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 ansibot added support:core This issue/PR relates to code supported by the Ansible Engineering Team. and removed support:community This issue/PR relates to code supported by the Ansible community. labels Sep 18, 2018
@ansibot ansibot added needs_maintainer Ansibot is unable to identify maintainers for this PR. (Check `author` in docs or BOTMETA.yml) support:community This issue/PR relates to code supported by the Ansible community. and removed support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels Oct 4, 2018
@ansibot ansibot removed the needs_maintainer Ansibot is unable to identify maintainers for this PR. (Check `author` in docs or BOTMETA.yml) label Nov 10, 2018
@ansibot ansibot added the test This PR relates to tests. label Feb 3, 2019
@ansibot
Copy link
Contributor

ansibot commented Feb 19, 2019

@ansibot ansibot added the database Database category label Feb 19, 2019
@ansibot
Copy link
Contributor

ansibot commented Feb 27, 2019

@ansibot
Copy link
Contributor

ansibot commented Jun 3, 2019

@ansibot
Copy link
Contributor

ansibot commented Jun 19, 2019

@pantaoran
Copy link

I'm also waiting for this feature.

@ansibot
Copy link
Contributor

ansibot commented Aug 8, 2019

@raatti
Copy link

raatti commented Aug 14, 2019

Also waiting for this...

@ansibot
Copy link
Contributor

ansibot commented Dec 20, 2019

@minhdanh
Copy link

minhdanh commented Jan 8, 2020

Any updates on this?

@CSimpiFoN
Copy link

Seems none cares :(

@bmalynovytch
Copy link
Contributor

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

close_me

@Andersson007
Copy link
Contributor

Andersson007 commented Apr 8, 2020

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

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

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

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

@Andersson007
Copy link
Contributor

merged, thanks all!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.4 This issue/PR affects Ansible v2.4 database Database category feature This issue/PR relates to a feature request. module This issue/PR relates to a module. mysql support:community This issue/PR relates to code supported by the Ansible community. test This PR relates to tests.
Projects
None yet
Development

No branches or pull requests