How do I use Ansible to set a random (32 character alphanumeric) root password for a MariaDB / MySQL database and save it to the ~/.my.cnf file (to allow commands to find this password)? 
It should only configure it once, and not change the password every time if the playbook is run multiple times.
This uses a password from a variable.
If I use this, it changes the password every time that the playbook is run: (and it fails to save the password - if the playbook is interrupted after this task, the password is lost)
- name: "Change database root user password"
  mysql_user:
    name: root
    password: "{{ lookup('password','/dev/null chars=ascii_letters,digits length=32') }}"
    host: "{{ item }}"
    check_implicit_admin: yes
    priv: "*.*:ALL,GRANT"
    state: present
  when: mysql_root_result.stat.exists == False
  with_items:
  - localhost
  - "::1"
  - 127.0.0.1
