Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [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'"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement