Advertisement
Guest User

Untitled

a guest
Jul 12th, 2017
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. [root@ansible-tower ansible-tower-setup-3.1.4]# more restore.yml
  2. ---
  3. - hosts: database
  4. gather_facts: false
  5. tasks:
  6. - name: Temporarily grant createdb role
  7. postgresql_user:
  8. name: awx
  9. role_attr_flags: CREATEDB
  10. become: yes
  11. become_user: postgres
  12.  
  13. - hosts: tower:!tower[0]
  14. gather_facts: false
  15. tasks:
  16. - name: Stop Tower services on all nodes
  17. command: ansible-tower-service stop
  18.  
  19. - hosts: tower[0]
  20. gather_facts: yes
  21. roles:
  22. - role: check_config_static
  23. - role: config_dynamic
  24. - role: restore
  25. restore_database: "{{ config_dynamic_database }}"
  26. restore_pg_database: "{{ pg_database }}"
  27.  
  28. - hosts: tower:!tower[0]
  29. gather_facts: false
  30. tasks:
  31. - name: Start Tower services on all nodes
  32. command: ansible-tower-service start
  33.  
  34. - hosts: database
  35. gather_facts: false
  36. tasks:
  37. - name: Revoke createdb role
  38. postgresql_user:
  39. name: awx
  40. role_attr_flags: NOCREATEDB
  41. become: yes
  42. become_user: postgres
  43.  
  44. [root@ansible-tower restore]# head -20 tower.db
  45. --
  46. -- PostgreSQL database dump
  47. --
  48. DROP DATABASE awx;
  49. CREATE DATABASE awx WITH TEMPLATE = template0 ENCODING = 'UTF8' LC_COLLATE = 'en_US.UTF-8' LC_CTYPE = 'en_US.UTF-8';
  50. ALTER DATABASE awx OWNER TO awx;
  51.  
  52. [root@ansible-tower ansible-tower-setup-3.1.4]# more roles/restore/tasks/postgres.yml
  53. ---
  54. # use dbname 'template1' to connect to the remote database
  55. # Since we drop the database as part of our backup/restore, we can't use the awx
  56. # database for this command.
  57. - name: Perform a PostgreSQL restore (external).
  58. shell: "psql --host='{{ tower_db_settings.default.HOST }}' --port={{ tower_db_settings.default.PORT }} --username='{{ tower_db_settings.default.USER
  59. }}' --dbname='template1' < ./tower.db"
  60. args:
  61. chdir: '{{ backup_dir.rstrip("/") }}/restore/'
  62. environment:
  63. PGPASSWORD: "{{ tower_db_settings.default.PASSWORD }}"
  64. no_log: True
  65. when: "restore_database == 'external'"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement