on first run: State mysql_user.present found in sls mysql is unavailable

3,868 views
Skip to first unread message

Lucas Torri

unread,
Jun 26, 2013, 5:52:55 AM6/26/13
to salt-...@googlegroups.com
Hi,

I'm new to Salt and was trying to create a small example using Vagrant for creating a VM with a configured MySQL instance. I did manage to do so, but with one small issue. When I run it the first time, it installs mysql-server, mysql-client, and python-mysqldb packages, plus gets the service running. But when it tries to create the database, a user and grant permissions to it, the error down below occurs. What is most weird though, is the fact that if I run it again (sudo salt-call state.highstate) it goes through and everything happens as expected (mysql installed, the db and user created, with the permissions granted).

I added all the files I'm using the following gist, together with the output I receive: https://gist.github.com/lucastorri/5866153

The versions I'm using are:
  • Vagrant: 1.2.2
  • Salty-Vagrant: 0.4.0
  • Ubuntu: precise64
  • Ubuntu's Salt: 0.15.3

I have changed the mysql.sls file in several ways in order to try fixing it: adding the include statement, moving require between different parts and requiring different things, using watch instead of require, etc. All changes behaved the same way.

Am I doing something wrong?


Thank you in advance.


Error:
----------
    State: - mysql_database
    Name:      pcur
    Function:  present
        Result:    False
        Comment:   State mysql_database.present found in sls mysql is unavailable

        Changes:
----------
    State: - mysql_user
    Name:      pcur
    Function:  present
        Result:    False
        Comment:   State mysql_user.present found in sls mysql is unavailable

        Changes:
----------
    State: - mysql_grants
    Name:      mysql-base
    Function:  present
        Result:    False
        Comment:   One or more requisite failed
        Changes:



--
Lucas Torri

Avi Marcus

unread,
Jun 26, 2013, 7:22:33 AM6/26/13
to salt-...@googlegroups.com
Can you show us the mysql install + permissions versions that you tried?

-Avi

--
You received this message because you are subscribed to the Google Groups "Salt-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to salt-users+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Lucas Torri

unread,
Jun 26, 2013, 8:12:47 AM6/26/13
to salt-...@googlegroups.com
Hi, thank for the help.

I can't remember them all since I didn't add those to version control, but a few, besides the one I sent before, might be:

mysql-base:
  mysql_database.present:
    - name: pcur
  mysql_user.present:
    - name: pcur
    - password: pcur
  mysql_grants.present:
    - database: pcur.*
    - grant: ALL PRIVILEGES
    - user: pcur
  require:
    - pkg: python-mysqldb
    - service.running: mysql



mysql-base:
  mysql_database.present:
    - name: pcur
  mysql_user.present:
    - name: pcur
    - password: pcur
  mysql_grants.present:
    - database: pcur.*
    - grant: ALL PRIVILEGES
    - user: pcur
  watch:
    - pkg: python-mysqldb
    - service.running: mysql



mysql-base:
  mysql_database.present:
    - name: pcur
  mysql_user.present:
    - name: pcur
    - password: pcur
  mysql_grants.present:
    - database: pcur.*
    - grant: ALL PRIVILEGES
    - user: pcur
    - require:
      - service.running: mysql
      - mysql_database.present: pcur
      - mysql_user.present: pcur
  require:
    - service.running: mysql
    - pkg: python-mysqldb



mysql-base:
  mysql_database.present:
    - name: pcur
    - watch:
      - service.running: mysql
  mysql_user.present:
    - name: pcur
    - password: pcur
    - watch:
      - service.running: mysql
  mysql_grants.present:
    - database: pcur.*
    - grant: ALL PRIVILEGES
    - user: pcur
    - watch:
      - service.running: mysql
      - mysql_database.present: pcur
      - mysql_user.present: pcur
  watch:
    - pkg: python-mysqldb

Kimbro Staken

unread,
Jun 26, 2013, 2:27:39 PM6/26/13
to salt-...@googlegroups.com
Looks like you have those states depending on the mysql server being
running but not the mysql-client and mysql-python packages being
installed. The mysql module requires those packages to function. On
the second run those packages have been installed so it works.

Kimbro

Lucas Torri

unread,
Jun 26, 2013, 3:06:01 PM6/26/13
to salt-...@googlegroups.com
Thanks Kimbro,

it did work by adding the requirement. My current mysql.sls is displayed below. Is there any improvement I can do to it? For instance, I was hopping that the require right inside the mysql-base would apply for all the command referenced.


Thanks everyone once again.


mysql.sls:

include:
  - salt.modules.mysql

mysql-client-5.5:
  pkg.installed

mysql-server-5.5:
  pkg.installed

python-mysqldb:
  pkg.installed

mysql-service:
  service.running:
    - name: mysql
    - require:
      - pkg: mysql-server-5.5

mysql-base:
  mysql_database.present:
    - name: pcur
    - require:
      - service.running: mysql
      - pkg: python-mysqldb
  mysql_user.present:
    - name: pcur
    - password: pcur
    - require:
      - service.running: mysql
      - pkg: python-mysqldb
  mysql_grants.present:
    - database: pcur.*
    - grant: ALL PRIVILEGES
    - user: pcur
    - require:
      - service.running: mysql
      - mysql_database.present: pcur
      - mysql_user.present: pcur
      - pkg: python-mysqldb
  require:
    - pkg: python-mysqldb

Colton Myers

unread,
Jun 26, 2013, 4:17:59 PM6/26/13
to salt-...@googlegroups.com
Nope, require is specific to each state module function.  There's no way to blanket-require like that, though the overstate could serve that function (though it may be overkill in this instance):  http://docs.saltstack.com/ref/states/overstate.html

--
Colton Myers

Kimbro Staken

unread,
Jun 26, 2013, 4:28:43 PM6/26/13
to salt-...@googlegroups.com
I think in this case I would make the mysql service.running depend on
all the packages being installed first. Then you can just depend on
mysql service.running like you were already doing. That makes sense if
you think of mysql service.running in a logical sense as "everything
required to run mysql" rather than simply as "the mysql daemon is
running". Whether that's really a good practice or not I'm not sure.

Lucas Torri

unread,
Jun 26, 2013, 7:07:45 PM6/26/13
to salt-...@googlegroups.com
Great tips, thanks.

That's how my file looks right now:


mysql-client-5.5:
  pkg.installed

mysql-server-5.5:
  pkg.installed

python-mysqldb:
  pkg.installed

mysql-service:
  service.running:
    - name: mysql
    - require:
      - pkg: mysql-server-5.5
      - pkg: python-mysqldb

mysql-base:
  mysql_database.present:
    - name: pcur
    - require:
      - service.running: mysql
  mysql_user.present:
    - name: pcur
    - password: pcur
    - require:
      - service.running: mysql
  mysql_grants.present:
    - database: pcur.*
    - grant: ALL PRIVILEGES
    - user: pcur
    - require:
      - mysql_database.present: pcur
      - mysql_user.present: pcur

David Boucha

unread,
Jun 27, 2013, 12:54:20 AM6/27/13
to salt users list

It should be:

- require:
  - service: mysql

Colton Myers

unread,
Jun 27, 2013, 12:03:19 PM6/27/13
to salt-...@googlegroups.com
Dave means your original examples -- it's `service: mysql`, not `service.running: mysql`.  Thought I should clarify, since I was originally confused.  =)

Hopefully you got it working to your satisfaction.  =)

--
Colton Myers

Lucas Torri

unread,
Jun 27, 2013, 2:49:20 PM6/27/13
to salt-...@googlegroups.com
Yes, I did :)

Thanks a lot for everybody's help

mick...@gmail.com

unread,
Jul 9, 2013, 10:55:52 AM7/9/13
to salt-...@googlegroups.com
I'm trying to use these module and I can't make it works before getting this example.

I think this a good example to put in the documentation.

石栋良

unread,
Apr 29, 2014, 5:05:23 AM4/29/14
to salt-...@googlegroups.com
salt.modules.mysql: depends:   - MySQLdb Python module

yum install MySQL-python


在 2013年6月26日星期三UTC+8下午5时52分55秒,Lucas Torri写道:
Reply all
Reply to author
Forward
0 new messages