Parth6288

DB_createyaml

Sep 26th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. --- # this file is for instlaling DB
  2. - hosts: rancher
  3. remote_user: ansible
  4. become: yes
  5. become_method: sudo
  6. connection: ssh
  7. vars:
  8. my_sql_root_pass: P@ssw0rd.1.123
  9. tasks:
  10. - name: Install Mysql
  11. apt: name={{item}} state=installed update_cache=true
  12. with_items:
  13. - mysql-server
  14. - python-mysqldb
  15. - build-essential
  16. - python-pip
  17. - libmysqlclient-dev
  18. - python-dev
  19. - name: install mysql-python using pip
  20. pip: name={{item}} state=present
  21. with_items:
  22. - pip
  23. - MySQL-python
  24. - name: Start mysql service
  25. service: name=mysql.service state=started enabled=true
  26. - name: copy the root credentials as .my.cnf file
  27. template: src=root.cnf.j2 dest=/root/.my.cnf mode=0600
  28. - name: update mysql root password
  29. mysql_user: name=root host={{ item }} password={{ my_sql_root_pass }} priv=*.*:ALL,GRANT
  30. with_items:
  31. - "{{ ansible_hostname }}"
  32. - 127.0.0.1
  33. - ::1
  34. - localhost
  35. - name: create a new DB
  36. mysql_db: name=cattle
  37. collation=utf8_general_ci
  38. encoding=utf8
  39. state=present
  40. - name: create a new DB user
  41. mysql_user: name=cattle
  42. password=P@ssw0rd.1.123
  43. priv="cattle.*:ALL,GRANT"
  44. host=localhost
  45. state=present
  46. - name: restart mysql
  47. service: name=mysqld state=restarted
Add Comment
Please, Sign In to add comment