Advertisement
Guest User

Ansible get and use MySQL root password

a guest
Aug 18th, 2016
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.08 KB | None | 0 0
  1. # cat /root/.my.cnf
  2. [client]
  3. user=root
  4. password=verySecretPassword
  5.  
  6. ----------
  7.  
  8. # stat /root/.my.cnf
  9.   File: ‘/root/.my.cnf’
  10.   Size: 49              Blocks: 8          IO Block: 4096   regular file
  11. Device: fd01h/64769d    Inode: 9017        Links: 1
  12. Access: (0600/-rw-------)  Uid: (    0/    root)   Gid: (    0/    root)
  13. Access: 2016-08-18 10:45:46.610721444 +0200
  14. Modify: 2016-08-18 09:38:42.165106840 +0200
  15. Change: 2016-08-18 10:45:32.478718044 +0200
  16.  Birth: -
  17.  
  18. ----------
  19.  
  20. # cat /etc/ansible/roles/backup-jobs/tasks/database_backups.yml
  21. [...]
  22.  
  23. - name: Saving MySQL root password to variable
  24.   shell: grep password /root/.my.cnf | cut -d "=" -f 2
  25.   register: mysql_root_password
  26.   no_log: True
  27.  
  28. - name: Setting MySQL root password in automysqlbackup configuration file
  29.   replace: dest={{ item }} regexp=PASSWORD replace={{ mysql_root_password.stdout }}
  30.   with_items:
  31.        - '/etc/automysqlbackup/myserver.conf'
  32.   no_log: True
  33.  
  34. [...]
  35.  
  36. ----------
  37.  
  38. # cat /etc/ansible/playbooks/groups/backups.yml
  39. - hosts: all
  40.   become: yes
  41.   roles:
  42.      - backup-jobs
  43. [...]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement