title: Install MySQL with ansible on ubuntu
body: <p>I have a problem installing MySQL with ansible on a vagrant ubuntu,</p>
  
  <p>This is my MySQL part</p>
  
  <pre><code>---
  - name: Install MySQL
    apt:
      name: "{{ item }}"
    with_items:
      - python-mysqldb
      - mysql-server
  
  - name: copy .my.cnf file with root password credentials
    template: 
      src: templates/root/.my.cnf
      dest: ~/.my.cnf
      owner: root
      mode: 0600
  
  - name: Start the MySQL service
    service: 
      name: mysql 
      state: started
      enabled: true
  
    # 'localhost' needs to be the last item for idempotency, see
    # http://ansible.cc/docs/modules.html#mysql-user
  - name: update mysql root password for all root accounts
    mysql_user: 
      name: root 
      host: "{{ item }}" 
      password: "{{ mysql_root_password }}" 
      priv: "*.*:ALL,GRANT"
    with_items:
      - "{{ ansible_hostname }}"
      - 127.0.0.1
      - ::1
      - localhost 
  </code></pre>
  
  <p>And I have this error</p>
  
  <pre><code>failed: [default] =&gt; (item=vagrant-ubuntu-trusty-64) =&gt; {"failed": true, "item": "vagrant-ubuntu-trusty-64"}
  msg: unable to connect to database, check login_user and login_password are correct or ~/.my.cnf has the credentials
  failed: [default] =&gt; (item=127.0.0.1) =&gt; {"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: [default] =&gt; (item=::1) =&gt; {"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: [default] =&gt; (item=localhost) =&gt; {"failed": true, "item": "localhost"}
  msg: unable to connect to database, check login_user and login_password are correct or ~/.my.cnf has the credentials
  </code></pre>
  
  <p>my .my.cnf is</p>
  
  <pre><code>[client]
  user=root
  password={{ mysql_root_password }}
  </code></pre>
  
  <p>and when copied on the server</p>
  
  <pre><code>[client]
  user=root
  password=root
  </code></pre>
  
  <p>I don't understand why, ~/.my.cnf is created</p>
  
  <p>Project <a href="https://github.com/ajouve/vagrant-php">Github</a></p>
  
  <p>Thanks</p>