2
respostas

The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement

Olá,

Estou na aula 6.3 do Ansible Infra como Código e estou recebendo a mensagem "Error establishing a database connection" ao tentar acessar o ip de meu wordpress via browser.

Meu Wordpress está na versão 4.9.1 e o Mysql na 5.6. Sei que o problema é no acesso ao Mysql pois quando tento acessar com ""mysql -u wordpress_user -p recebo a mensagem "ERROR 1045 (28000): Access denied for user", só acessando com o root.

Para "tentar" resolver rodei os comendos:

sudo /etc/init.d/mysql stop sudo mysqld_safe --skip-grant-tables & mysql -u root use mysql; update user set password=PASSWORD("123456") where User='root'; flush privileges; quit sudo /etc/init.d/mysql stop sudo /etc/init.d/mysql start

Após isso o acesso normaliza, entretanto, ao executar o playbook recebo o erro abaixo.

TASK [Cria o usuário do MySQL] ** failed: [10.10.0.102] (item=-'localhost' -'127.0.0.1' -'10.10.0.100' -'10.10.0.102') => {"ansible_loop_var": "item", "changed": false, "item": "-'localhost' -'127.0.0.1' -'10.10.0.100' -'10.10.0.102'", "msg": "(1290, 'The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement')"}

Podem me ajudar nisso?

Segue abaixo os arquivos:

PROVISIONING.YML


  • hosts: database handlers:

    • name: restart mysql service: name: mysql state: restarted become: yes

    tasks:

    • name: 'Instala pacotes de dependencia do SO' apt: update_cache: yes cache_valid_time: 3600 #1 hora name:

      • mysql-server-5.6
      • python-mysqldb state: latest become: yes
    • name: 'Cria o banco do MySQL' mysql_db: name: "{{ wp_db_name }}" login_user: root state: present

    • name: 'Cria o usuário do MySQL' mysql_user: login_user: root name: "{{ wp_username }}" password: '12345' priv: "{{ wp_db_name }}.*:ALL" state: present host: "{{ item }}" with_items: -'localhost' -'127.0.0.1' -'10.10.0.100' -'10.10.0.102'

    • name: 'Configura o MySQL para aceitar conexões remotas' copy: src: '/vagrant/files/my.cnf' dest: '/etc/mysql/my.cnf' become: yes notify:

      • restart mysql
  • hosts: wordpress handlers:

    • name: restart apache service: name: apache2 state: restarted become: yes

    tasks:

    • name: 'Instala pacotes de dependencia do SO' apt: update_cache: yes cache_valid_time: 3600 #1 hora name:

      • php5
      • apache2
      • libapache2-mod-php5
      • php5-gd
      • libssh2-php
      • php5-mcrypt
      • php5-mysql state: latest become: yes
    • name: 'Baixa Instalação do Wordpress' get_url: url: 'https://wordpress.org/wordpress-4.9.1.tar.gz' dest: '/tmp/wordpress.tar.gz' mode: 0440

    • name: 'Descompactar Arquivo' unarchive: src: '/tmp/wordpress.tar.gz' dest: /var/www/ remote_src: yes become: yes

    • name: 'Copiar arquivo Modelo de configuração' copy: src: /var/www/wordpress/wp-config-sample.php dest: /var/www/wordpress/wp-config.php remote_src: yes become: yes

    • name: 'Configura o wp-config com as entradas do banco de dados' replace: path: '/var/www/wordpress/wp-config.php' regexp: "{{ item.regex }}" replace: "{{ item.value }}" backup: yes with_items:

      • { regex: 'database_name_here', value: "{{ wp_db_name }}"}
      • { regex: 'username_here', value: "{{ wp_username }}"}
      • { regex: 'password_here', value: '12345'}
      • { regex: 'localhost', value: '10.10.0.102'} become: yes
    • name: 'Configura Apache para servir Wordpress' copy: src: '/vagrant/files/000-default.conf' dest: '/etc/apache2/sites-available/000-default.conf' notify:

      • restart apache become: yes
2 respostas

VAGRANTFILE

Vagrant.configure("2") do |config| config.vm.box = "ubuntu/trusty64"

config.vm.provider "virtualbox" do |v|
    v.memory = 1024
end

config.vm.define "ansible" do |ansible|
  ansible.vm.network "private_network", ip: "10.10.0.101"

  ansible.vm.provision "shell",
    inline: "sudo apt-get purge ansible && \
             apt-get install -y software-properties-common && \
             apt-add-repository ppa:ansible/ansible && \
             apt-get update && \
             apt-get install -y ansible && \
             echo ------------------------------------ END INSTALL ANSIBLE"

  ansible.vm.provision "shell",
    inline: "cp /vagrant/configs/id_ansible /home/vagrant && \
             cp /vagrant/configs/id_ansible.pub /home/vagrant && \
             cp /vagrant/provisioning.yml /home/vagrant && \
             cp /vagrant/hosts /etc/ansible/ && \
             cp -r /vagrant/group_vars /home/vagrant/ && \
             echo ------------------------------------ END CP id_ansible
             chmod 600 /home/vagrant/id_ansible && \
             chown vagrant:vagrant /home/vagrant/id_ansible
             sudo chown vagrant:vagrant /home/vagrant/provisioning.yml" #Addicionado 28/08

 end

config.vm.define "wordpress" do |wordpress|
    wordpress.vm.network "private_network", ip: "10.10.0.100"

wordpress.vm.provision "shell",
    inline: "cat /vagrant/configs/id_ansible.pub >> .ssh/authorized_keys && \
    echo ------------------------------------ END CAT ID_WORDPRESS"
end
config.vm.define "mysql" do |mysql|
    mysql.vm.network "private_network", ip: "10.10.0.102"

mysql.vm.provision "shell",
    inline: "cat /vagrant/configs/id_ansible.pub >> .ssh/authorized_keys && \
    echo ------------------------------------ END CAT ID_MYSQL"
end

end

Oi, Pedro, tudo bem?

Veja se essa resolução te ajuda: https://cursos.alura.com.br/forum/topico-error-1045-28000-como-resolver-42321