ANXS / mysql

Ansible role for MySQL
MIT License
94 stars 70 forks source link

Root password tasks not working well on localhost #20

Open ktaragorn opened 10 years ago

ktaragorn commented 10 years ago

This is on LXLE which is based on ubuntu 14.04.1 The first time I run the task, I get

TASK: [ANXS.mysql | MySQL | Set the root password.] *************************** 
failed: [localhost] => (item=KarthikT-OptiPlex-GX620) => {"failed": true, "item": "KarthikT-OptiPlex-GX620", "parsed": false}
invalid output was: SUDO-SUCCESS-qhgbcpxzorscvhhvhgbmobqdlkyxzxvq
Traceback (most recent call last):
  File "/home/karthikt/.ansible/tmp/ansible-tmp-1412493609.88-146177631411431/mysql_user", line 1562, in <module>
    main()
  File "/home/karthikt/.ansible/tmp/ansible-tmp-1412493609.88-146177631411431/mysql_user", line 459, in main
    changed = user_add(cursor, user, host, password, priv)
  File "/home/karthikt/.ansible/tmp/ansible-tmp-1412493609.88-146177631411431/mysql_user", line 158, in user_add
    cursor.execute("CREATE USER %s@%s IDENTIFIED BY %s", (user,host,password))
  File "/usr/lib/python2.7/dist-packages/MySQLdb/cursors.py", line 174, in execute
    self.errorhandler(self, exc, value)
  File "/usr/lib/python2.7/dist-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler
    raise errorclass, errorvalue
_mysql_exceptions.OperationalError: (1396, "Operation CREATE USER failed for 'root'@'karthikt-optiplex-gx620'")

changed: [localhost] => (item=127.0.0.1)
changed: [localhost] => (item=::1)
changed: [localhost] => (item=localhost)

FATAL: all hosts have already failed -- aborting

Which means the second time I get

TASK: [ANXS.mysql | MySQL | Set the root password.] *************************** 
failed: [localhost] => (item=KarthikT-OptiPlex-GX620) => {"failed": true, "item": "KarthikT-OptiPlex-GX620"}
msg: unable to connect to database, check login_user and login_password are correct or ~/.my.cnf has the credentials
failed: [localhost] => (item=127.0.0.1) => {"failed": true, "item": "127.0.0.1"}
msg: unable to connect to database, check login_user and login_password are correct or ~/.my.cnf has the credentials
failed: [localhost] => (item=::1) => {"failed": true, "item": "::1"}
msg: unable to connect to database, check login_user and login_password are correct or ~/.my.cnf has the credentials
failed: [localhost] => (item=localhost) => {"failed": true, "item": "localhost"}
msg: unable to connect to database, check login_user and login_password are correct or ~/.my.cnf has the credentials

FATAL: all hosts have already failed -- aborting

This works fine on a remote system.

As I write this (:P), I notice that the first Item is "item": "KarthikT-OptiPlex-GX620 which I believe was the name set by the ubuntu/lxle installer.. This would mean that it is picking the wrong task of the two tasks Set the root password. in tasks/secure.yml. First fix would be to name them differently based on their use (localhost vs remote perhaps). And perhaps a better check is needed rather than when: ansible_hostname != 'localhost' ?

This was repeatedly encountered, after purging mysql as shown in http://stackoverflow.com/questions/10853004/removing-mysql-5-5-completely. It is running the ansible galaxy version of the role.

ktaragorn commented 10 years ago

my hosts file is

[dev]
localhost ansible_connection=local 
ktaragorn commented 10 years ago

Setting ansible_hostname=localhost as a host var doesnt seem to be helping :(

ktaragorn commented 10 years ago

Trying to find a better way @ http://stackoverflow.com/questions/26200653/force-ansible-hostname-value-or-check-ansible-target-is-localhost

ktaragorn commented 10 years ago

seems inventory_hostname is what you specify in the hosts file, perhaps that is a better choice to compare against localhost? might need to check 127.0.0.1..

ajsalminen commented 10 years ago

Yeah, inventory_hostname looks like the way to go with the condition to me.

rstormsf commented 9 years ago

I have the same problem, what would be the solution? just add in hosts like this:

[web]
example.com inventory_hostname=localhost

I've tried it and it didn't help :-(

ktaragorn commented 9 years ago

HI @rstormsf this is a change for the role itself, setting in the host file isnt it. I have the role downloaded into my repository, so I ended up changing the condition above to a boolean variable and i set that variable in the host file.. Not pretty but atleast it works and is explicit. Ideally the role should fix this

rstormsf commented 9 years ago

Still not quite understand how to fix it.

diogoviannaaraujo commented 9 years ago

Anything on this, im getting this when trying to run inside a container

ktaragorn commented 9 years ago

Another discovery... I can ping my ansible_fqdn which is "ansible_fqdn": "Karthiks-MacBook-Pro.local" But I cannot ping my ansible_hostname which is just "Karthiks-MacBook-Pro". This might be mac specific though..

ktaragorn commented 9 years ago

For those looking for a fix, what I did was add a db_local variable in my hosts file, which was true or false as needed, and actually modified the code in tasks/secure.yml to replace cases of when: ansible_hostname != 'localhost' with when: db_local. This only works for me because I store the role within my repository and thus can modify and commit to my repository.

diogoviannaaraujo commented 9 years ago

I think the problem really is with ansible_hostname

https://github.com/ansible/ansible/issues/9971

ktaragorn commented 9 years ago

Good find, perhaps the role should start using that, might even negate the need to do different things on local...

diogoviannaaraujo commented 9 years ago

Ive changed to inventory_hostname and it reacts better now, but im still getting an error:

ansible_1 | TASK: [ANXS.mysql | MySQL | Changing the root password (local hostname).] ***** 
ansible_1 | failed: [localhost] => (item=127.0.0.1) => {"failed": true, "item": "127.0.0.1"}
ansible_1 | msg: unable to connect to database, check login_user and login_password are correct or ~/.my.cnf has the credentials
ansible_1 | failed: [localhost] => (item=::1) => {"failed": true, "item": "::1"}
ansible_1 | msg: unable to connect to database, check login_user and login_password are correct or ~/.my.cnf has the credentials
ansible_1 | failed: [localhost] => (item=localhost) => {"failed": true, "item": "localhost"}
ansible_1 | msg: unable to connect to database, check login_user and login_password are correct or ~/.my.cnf has the credentials
ansible_1 | 
ansible_1 | FATAL: all hosts have already failed -- aborting
ansible_1 | 
ansible_1 | PLAY RECAP ******************************************************************** 
ansible_1 |            to retry, use: --limit @/root/playbook.retry
ansible_1 | 
ansible_1 | localhost                  : ok=11   changed=4    unreachable=0    failed=1   
adgwytc commented 6 years ago

I've got the same problem where MariaDB has already been installed. Will this create an issue and if so should I remove MariaDB and re-install ./rd-installer?

By the way, I cannot remove MariaDB as I get the following error: [root@rad01thn /]# yum remove mariadb mariadb-server Loaded plugins: fastestmirror No Match for argument: mariadb No Match for argument: mariadb-server No Packages marked for removal

I'm on Centos 7.3, so I also tried: [root@rad01thn /]# yum remove MariaDB-server MariaDB-client Loaded plugins: fastestmirror No Match for argument: MariaDB-server No Match for argument: MariaDB-client No Packages marked for removal

My .cnf file looks like this: [root@rad01thn etc]# more my.cnf [mysqld] bind-address=127.0.0.1 datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock

Disabling symbolic-links is recommended to prevent assorted security risks

symbolic-links=0

Settings user and group are ignored when systemd is used.

If you need to run mysqld under a different user or group,

customize your systemd unit file for mariadb according to the

instructions in http://fedoraproject.org/wiki/Systemd

[mysqld_safe] log-error=/var/log/mysql.err pid-file=/var/run/mariadb/mariadb.pid

#

include all files from the config directory

# !includedir /etc/my.cnf.d

sql_mode=IGNORE_SPACE,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION Any help please