2

I am a saltstack newbie and mysql newbie too... :-/ was trying to install my-sql on Ubuntu 14. I am getting following error

enter image description here

I use the following sls file

mysql_package:
  pkg.installed:
    - name: mysql-server

mysql_conf:
  file.managed:
    - name: /etc/my.cnf
    - source: salt://mysql/files/my.cnf
    - user: root
    - group: root
    - mode: 0644
    - require:
      - pkg: mysql_package

mysql_service:
  service:
    - name: mysqld
    - running
    - enable: True
    - require:
      - pkg: mysql_conf
    - watch:
      - pkg: mysql_conf

# required packages start
server_pkgs:
  pkg:
    - installed
    - pkgs:
      - python-dev
    - refresh: True

mysql_python_pkgs:
  pkg.installed:
    - pkgs:
      - libmysqlclient-dev
      - mysql-client
      - python-mysqldb
    - require:
      - pkg: server_pkgs

python-pip:
  pkg:
    - installed
    - refresh: False

mysql:
  pip.installed:
    - require:
      - pkg: python-pip
      - pkg: mysql_python_pkg
# required package end

stg_databases:
  mysql_database.present:
    - name: stagingdb
    - require:
      - pkg: mysql
      - service: mysql_service

first_db_user:
  mysql_user.present:
    - name: stg-admin
    - password: "pass4admin"
    - host: '%'
    - connection_charset: utf8
    - saltenv:
      - LC_ALL: "en_US.utf8"
    - require:
      - mysql_database: stg_databases


create_first_table:
  mysql_query.run:
    - database: stagingdb
    - query: "create table first_table(id INT NOT NULL AUTO_INCREMENT, name VARCHAR(100) NOT NULL, PRIMARY KEY ( id ));"
    - output:   "/tmp/create_first_table.txt"
    - require:
      - mysql_database: stg_databases


first_table_grants:
  mysql_grants.present:
    - grant: all privileges
    - database: stagingdb.*
    - user: stg-admin
    - host: '%'
    - require:
      - mysql_user: first_db_user

And using following conf file

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
symbolic-links=0

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

Came across following link MySQL - ERROR 1045 - Access denied , thats not what i want to do...

Guessing there is a relation between user defined in my.cnf and in sls file, which i am not getting correct ?

Community
  • 1
  • 1
Lav
  • 1,283
  • 5
  • 21
  • 48

2 Answers2

0

Where there any errors when you ran this state?

Also if you run:

salt-call -ldebug state.sls <state file>  

That will give you a lot of useful information as to what salt is exactly running. Is the root user still available? Can you login and see if that user was actually created?

Ch3LL
  • 11
  • 1
0

This is obvious Mysql GRANT issues that you don't need to debug. It means you make some mistake of GRANTING the user. Just check the doc : https://docs.saltstack.com/en/latest/ref/states/all/salt.states.mysql_user.html

mysql_user.present DOES NOT grant a user. you need mysql_grants.present together with mysql_user.present. The confusing part : mysql_grants.present doesn't set password; mysql_user.present set password but doesn't grant DB rights.

first_db_user:
  mysql_user.present:
    - name: stg-admin
    - password: "pass4admin"
    - host: '%'
    - connection_charset: utf8
    - saltenv:
      - LC_ALL: "en_US.utf8"
    - require:
      - mysql_database: stg_databases

grant_my_first_db_user:
  mysql_grants.present:
    - grant: select,insert,update
    - database: stagingdb
    - user: stg-admin
    - host: localhost

And saltstack mysql formula confirm this.

https://github.com/saltstack-formulas/mysql-formula/blob/master/mysql/salt-user.sls

mootmoot
  • 12,845
  • 5
  • 47
  • 44