Created
December 2, 2015 01:43
-
-
Save mynameisrufus/ed79a3ad193e4bd9a7db to your computer and use it in GitHub Desktop.
Migration of Ansible Tower 2.1.2 to 2.4.1 with large database
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
--- | |
# This orchestration will perform a backup of a Tower machine and pull the | |
# backup files down to a bastion server for use with a later restore. | |
# | |
# http://docs.ansible.com/ansible-tower/latest/html/installandreference/upgrade_tower.html | |
# https://support.ansible.com/hc/en-us/articles/203295497-Tower-Manual-Backup-Restore | |
- name: Pull Ansible Tower backup | |
hosts: tower | |
gather_facts: true | |
sudo: true | |
tasks: | |
- command: "service supervisord stop" | |
- command: "service httpd stop" | |
- name: create backup directory | |
sudo: false | |
file: | |
path: "backup" | |
state: directory | |
mode: 0755 | |
- command: "tar -zcf backup/tower_etc.tar.gz /etc/tower/" | |
- command: "tar -zcf backup/tower_var.tar.gz /var/lib/awx/" | |
- name: dump database | |
become: yes | |
become_user: postgres | |
shell: "pg_dumpall > tower_db.dump" | |
args: | |
chdir: "/var/lib/pgsql/9.3" | |
- command: "tar -zcf backup/tower_db.tar.gz /var/lib/pgsql/9.3/tower_db.dump" | |
- command: "rm /var/lib/pgsql/9.3/tower_db.dump" | |
- command: "service supervisord start" | |
- command: "service httpd start" | |
- name: pull down backup files to bastion01 | |
delegate_to: bastion01 | |
sudo: false | |
synchronize: | |
mode: pull | |
src: "backup/" | |
dest: "{{ ansible_hostname }}_backup" |
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
--- | |
# This orchestration will push up the Tower backup files created using the | |
# `ansible-tower-backup-pull` orchestration to re-provisioned Tower machine. | |
# | |
# http://docs.ansible.com/ansible-tower/latest/html/installandreference/upgrade_tower.html | |
# https://support.ansible.com/hc/en-us/articles/203295497-Tower-Manual-Backup-Restore | |
- name: Push Ansible Tower backup | |
hosts: tower | |
gather_facts: true | |
sudo: true | |
tasks: | |
- name: create backup directory | |
sudo: false | |
file: | |
path: "backup" | |
state: directory | |
mode: 0755 | |
- name: push up backup files | |
delegate_to: bastion01 | |
sudo: false | |
synchronize: | |
mode: push | |
src: "{{ ansible_hostname }}_backup/" | |
dest: "backup" | |
- debug: | |
msg: "Remember to remove {{ ansible_hostname }}_backup after restore" |
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
--- | |
- name: download the Tower Installation Program | |
get_url: | |
url: "http://releases.ansible.com/awx/setup/ansible-tower-setup-latest.tar.gz" | |
dest: /tmp/ansible-tower-setup-latest.tar.gz | |
environment: | |
http_proxy: "http://{{ http_proxy_host }}:{{ http_proxy_port }}" | |
https_proxy: "http://{{ http_proxy_host }}:{{ http_proxy_port }}" | |
- name: Unpack Tower | |
command: "tar xvzf ansible-tower-setup-latest.tar.gz" | |
args: | |
chdir: '/tmp' | |
- name: Upload setup conf file | |
template: | |
src: "setup.yml.j2" | |
dest: "/tmp/ansible-tower-setup-{{ tower_version }}/tower_setup_conf.yml" | |
- name: Configure Tower install | |
command: "./configure -o tower_setup_conf.yml" | |
args: | |
chdir: "/tmp/ansible-tower-setup-{{ tower_version }}" | |
- name: Install Tower | |
sudo: true | |
shell: "./setup.sh" | |
args: | |
chdir: "/tmp/ansible-tower-setup-{{ tower_version }}" |
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
--- | |
- name: check if Tower installed | |
stat: | |
path: "/etc/tower" | |
register: tower_installed | |
- name: check if backup present | |
stat: | |
path: "backup" | |
register: backup_present | |
- include: install.yml | |
when: not tower_installed.stat.exists | |
- include: restore.yml | |
when: backup_present.stat.exists | |
- name: remove old jobs, project and inventory updates from the database | |
command: "tower-manage cleanup_jobs --days {{ tower_keep_days }}" | |
- name: remove old jobs, project and inventory updates from the database | |
command: "tower-manage cleanup_deleted --days {{ tower_keep_days }}" | |
- name: remove old activity stream events from the database | |
command: "tower-manage cleanup_activitystream --days {{ tower_keep_days }}" |
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
--- | |
- command: "service supervisord stop" | |
- command: "service httpd stop" | |
- name: create backup directory | |
sudo: false | |
file: | |
path: "tower_files" | |
state: directory | |
mode: 0755 | |
- command: "tar -xvf backup/tower_etc.tar.gz -C tower_files/" | |
- command: "tar -xvf backup/tower_var.tar.gz -C tower_files/" | |
- command: "tar -xvf backup/tower_db.tar.gz -C tower_files/" | |
- command: "rm -rf backup" | |
- shell: "cp -R tower_files/etc/tower/* /etc/tower" | |
- shell: "cp -R tower_files/var/lib/awx/* /var/lib/awx" | |
- command: "mv tower_files/var/lib/pgsql/{{ postgres_previous_version }}/tower_db.dump /var/lib/pgsql/{{ postgres_current_version }}/tower_db.dump" | |
- command: "rm -rf tower_files" | |
- name: drop existing database | |
become_user: postgres | |
shell: "psql -c \"DROP DATABASE IF EXISTS awx;\"" | |
- name: restore database from database dump | |
become: yes | |
become_user: postgres | |
shell: "psql -f tower_db.dump postgres > /dev/null 2>&1" | |
args: | |
chdir: "/var/lib/pgsql/{{ postgres_current_version }}" | |
- command: "rm /var/lib/pgsql/{{ postgres_current_version }}/tower_db.dump" | |
- name: vacuum database | |
become_user: postgres | |
shell: "vacuumdb -a -z" | |
- name: remove stdout text so migrations do not get killed my out of memory killer | |
become_user: postgres | |
command: "psql awx -c \"UPDATE main_unifiedjob SET result_stdout_text = ''\";" | |
- name: create tables haven not already been created except those with migrations | |
command: "tower-manage syncdb" | |
- name: run database migrations | |
command: "tower-manage migrate" | |
- command: "service supervisord start" | |
- command: "service httpd start" |
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
admin_password: {{ ansible_tower_admin_password }} | |
configure_private_vars: {} | |
database: internal | |
munin_password: {{ ansible_tower_munin_password }} | |
pg_password: {{ ansible_tower_pg_password }} | |
primary_machine: localhost | |
redis_password: {{ ansible_tower_redis_password }} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment