Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automate MySQL install on Ubuntu 14.04 using Ansible

I'm trying to setup a Vagrant environment involving a few Ubuntu machines with Ansible and am having trouble writing an Ansible Playbook to automate the process. Primarily, I'm following the instructions from this answer - https://stackoverflow.com/a/26598887

Here is the snippet of the error I'm getting from running the playbook;

PLAY [web] ******************************************************************** 

GATHERING FACTS *************************************************************** 
ok: [business-web1]

TASK: [Install MySQL] ********************************************************* 
failed: [business-web1] => (item=mysql-server) => {"failed": true, "item": "mysql-server"}
stderr: start: Job failed to start
invoke-rc.d: initscript mysql, action "start" failed.
dpkg: error processing package mysql-server-5.5 (--configure):
 subprocess installed post-installation script returned error exit status 1
dpkg: dependency problems prevent configuration of mysql-server:
 mysql-server depends on mysql-server-5.5; however:
  Package mysql-server-5.5 is not configured yet.

dpkg: error processing package mysql-server (--configure):
 dependency problems - leaving unconfigured
No apport report written because the error message indicates its a followup error from a previous failure.
Errors were encountered while processing:
 mysql-server-5.5
 mysql-server
E: Sub-process /usr/bin/dpkg returned an error code (1)

stdout: Reading package lists...
Building dependency tree...
Reading state information...
mysql-server is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 52 not upgraded.
2 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Setting up mysql-server-5.5 (5.5.44-0ubuntu0.14.04.1) ...

msg: '/usr/bin/apt-get -y -o "Dpkg::Options::=--force-confdef" -o "Dpkg::Options::=--force-confold"   install 'mysql-server'' failed: start: Job failed to start
invoke-rc.d: initscript mysql, action "start" failed.
dpkg: error processing package mysql-server-5.5 (--configure):
 subprocess installed post-installation script returned error exit status 1
dpkg: dependency problems prevent configuration of mysql-server:
 mysql-server depends on mysql-server-5.5; however:
  Package mysql-server-5.5 is not configured yet.

dpkg: error processing package mysql-server (--configure):
 dependency problems - leaving unconfigured
No apport report written because the error message indicates its a followup error from a previous failure.
Errors were encountered while processing:
 mysql-server-5.5
 mysql-server
E: Sub-process /usr/bin/dpkg returned an error code (1)


FATAL: all hosts have already failed -- aborting

PLAY RECAP ******************************************************************** 
           to retry, use: --limit @/home/vagrant/provision-business-mysql.retry

business-web1              : ok=1    changed=0    unreachable=0    failed=1   

To the best of my understanding, it looks like the first 'install mysql' step isn't being run. To verify this, I managed to recreate the problem by running the ansible module directly from command line;

vagrant@mgmt:~$ ansible web -m apt -a "name=mysql-server update_cache=yes cache_valid_time=3600 state=latest" --sudo
business-web1 | FAILED >> {
    "failed": true,
    "msg": "'/usr/bin/apt-get -y -o \"Dpkg::Options::=--force-confdef\" -o \"Dpkg::Options::=--force-confold\"   install 'mysql-server'' failed: start: Job failed to start\ninvoke-rc.d: initscript mysql, action \"start\" failed.\ndpkg: error processing package mysql-server-5.5 (--configure):\n subprocess installed post-installation script returned error exit status 1\ndpkg: dependency problems prevent configuration of mysql-server:\n mysql-server depends on mysql-server-5.5; however:\n  Package mysql-server-5.5 is not configured yet.\n\ndpkg: error processing package mysql-server (--configure):\n dependency problems - leaving unconfigured\nNo apport report written because the error message indicates its a followup error from a previous failure.\nErrors were encountered while processing:\n mysql-server-5.5\n mysql-server\nE: Sub-process /usr/bin/dpkg returned an error code (1)\n",
    "stderr": "start: Job failed to start\ninvoke-rc.d: initscript mysql, action \"start\" failed.\ndpkg: error processing package mysql-server-5.5 (--configure):\n subprocess installed post-installation script returned error exit status 1\ndpkg: dependency problems prevent configuration of mysql-server:\n mysql-server depends on mysql-server-5.5; however:\n  Package mysql-server-5.5 is not configured yet.\n\ndpkg: error processing package mysql-server (--configure):\n dependency problems - leaving unconfigured\nNo apport report written because the error message indicates its a followup error from a previous failure.\nErrors were encountered while processing:\n mysql-server-5.5\n mysql-server\nE: Sub-process /usr/bin/dpkg returned an error code (1)\n",
    "stdout": "Reading package lists...\nBuilding dependency tree...\nReading state information...\nmysql-server is already the newest version.\n0 upgraded, 0 newly installed, 0 to remove and 52 not upgraded.\n2 not fully installed or removed.\nAfter this operation, 0 B of additional disk space will be used.\nSetting up mysql-server-5.5 (5.5.44-0ubuntu0.14.04.1) ...\n"
}

vagrant@mgmt:~$ 

Any idea how I can get mysql installed and a DB setup using Ansible?

like image 286
chronodekar Avatar asked Jul 24 '15 12:07

chronodekar


1 Answers

I had this same error occurring trying to install mysql on a fresh ubuntu/trusty64 box. Crazily enough it turned out to be due to the VM instance having less than 512MB of memory. Make sure your Vagrantfile allots your VM enough memory.

config.vm.provider "virtualbox" do |vb|
  vb.memory = "512"
end
like image 160
bbeecher Avatar answered Sep 17 '22 15:09

bbeecher