Last active
July 12, 2017 17:12
-
-
Save thisdougb/6b66cadf33432a8126a36fa0d9a975c8 to your computer and use it in GitHub Desktop.
restore code for Tower
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[root@ansible-tower ansible-tower-setup-3.1.4]# more restore.yml | |
--- | |
- hosts: database | |
gather_facts: false | |
tasks: | |
- name: Temporarily grant createdb role | |
postgresql_user: | |
name: awx | |
role_attr_flags: CREATEDB | |
become: yes | |
become_user: postgres | |
- hosts: tower:!tower[0] | |
gather_facts: false | |
tasks: | |
- name: Stop Tower services on all nodes | |
command: ansible-tower-service stop | |
- hosts: tower[0] | |
gather_facts: yes | |
roles: | |
- role: check_config_static | |
- role: config_dynamic | |
- role: restore | |
restore_database: "{{ config_dynamic_database }}" | |
restore_pg_database: "{{ pg_database }}" | |
- hosts: tower:!tower[0] | |
gather_facts: false | |
tasks: | |
- name: Start Tower services on all nodes | |
command: ansible-tower-service start | |
- hosts: database | |
gather_facts: false | |
tasks: | |
- name: Revoke createdb role | |
postgresql_user: | |
name: awx | |
role_attr_flags: NOCREATEDB | |
become: yes | |
become_user: postgres | |
[root@ansible-tower restore]# head -20 tower.db | |
-- | |
-- PostgreSQL database dump | |
-- | |
DROP DATABASE awx; | |
CREATE DATABASE awx WITH TEMPLATE = template0 ENCODING = 'UTF8' LC_COLLATE = 'en_US.UTF-8' LC_CTYPE = 'en_US.UTF-8'; | |
ALTER DATABASE awx OWNER TO awx; | |
[root@ansible-tower ansible-tower-setup-3.1.4]# more roles/restore/tasks/postgres.yml | |
--- | |
# use dbname 'template1' to connect to the remote database | |
# Since we drop the database as part of our backup/restore, we can't use the awx | |
# database for this command. | |
- name: Perform a PostgreSQL restore (external). | |
shell: "psql --host='{{ tower_db_settings.default.HOST }}' --port={{ tower_db_settings.default.PORT }} --username='{{ tower_db_settings.default.USER | |
}}' --dbname='template1' < ./tower.db" | |
args: | |
chdir: '{{ backup_dir.rstrip("/") }}/restore/' | |
environment: | |
PGPASSWORD: "{{ tower_db_settings.default.PASSWORD }}" | |
no_log: True | |
when: "restore_database == 'external'" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment