Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new role for changing engine from local to remote db #145

Open
wants to merge 32 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
a5e9ac7
new role for dumping engine and dwh databases
leistnerova Aug 17, 2017
e24a787
Merge remote-tracking branch 'upstream/master'
leistnerova Aug 22, 2017
19b558e
new role ovirt-engine-local-to-remote-db for changing engine from loc…
leistnerova Aug 24, 2017
556109f
update according to comments
leistnerova Aug 24, 2017
0bedcf8
Merge branch 'master' of https://github.com/rhevm-qe-automation/ovirt…
leistnerova Aug 29, 2017
9500dfa
tests form changine engine from local to remote db added, some fixes
leistnerova Aug 29, 2017
739d1ad
fixing whitespaces
leistnerova Aug 29, 2017
36ddc5e
separate test created
lukas-bednar Aug 30, 2017
3235a69
default value in engine-cleanup fixed
leistnerova Aug 30, 2017
9870d31
removed local to remove db flow from other tests
leistnerova Aug 30, 2017
e5543e0
check of engine status, reset if not running, remove db in the end
leistnerova Oct 11, 2017
a5e1f2a
Merge branch 'master' into local_to_remote_db
leistnerova Oct 11, 2017
bf33241
Update .travis.yml
leistnerova Oct 11, 2017
66b4438
text fixed, example of inventory
leistnerova Oct 11, 2017
8994178
Merge branch 'local_to_remote_db' of github.com:leistnerova/ovirt-ans…
leistnerova Oct 11, 2017
e57c2e3
travis.yml fix
leistnerova Oct 11, 2017
9691c80
Merge remote-tracking branch 'upstream/master'
leistnerova Oct 12, 2017
532616e
fix for test-promote-db-local-to-remote.yml - load all containers facts
leistnerova Oct 12, 2017
1a389c9
fix of become postgres user
leistnerova Oct 12, 2017
e1399a1
changes for ovirt >= 4.2
leistnerova Oct 13, 2017
7f7d264
fix on getting variables from engine settings
leistnerova Oct 13, 2017
12bc29c
condition of dwh db added back to dump db
leistnerova Oct 13, 2017
90e4605
update of README
leistnerova Oct 17, 2017
90aaca1
change of remove db variable, fix ovirt_engine_version
leistnerova Oct 17, 2017
3169b17
fix ovirt_engine_version
leistnerova Oct 17, 2017
29d776e
gix db_dump_local_dir variable use
leistnerova Oct 17, 2017
0c1ad97
Merge remote-tracking branch 'upstream/master'
leistnerova Oct 17, 2017
e8ab3ff
Merge branch 'master' into local_to_remote_db
leistnerova Oct 17, 2017
951141f
test in README added, fix restoring db
leistnerova Oct 17, 2017
064bffb
fixing only reset usage
leistnerova Oct 19, 2017
0df0b0e
Merge branch 'master' into local_to_remote_db
leistnerova May 15, 2018
9a29cbb
Merge branch 'master' into local_to_remote_db
petr-balogh May 30, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ env:
# We don't support older versions here. Also upstream doesn't support 4.1
# when 4.2 is out. https://bugzilla.redhat.com/show_bug.cgi?id=1583222
- TEST_NAME=4.2
- TEST_NAME=promote-db-local-to-remote

# Install python-pip
addons:
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ This host group is meant for virtual machines hosted by oVirt Engine.
* [ovirt-engine-cleanup]
* [ovirt-engine-config]
* [ovirt-engine-db-dump]
* [ovirt-engine-local-to-remote-db]
* [ovirt-engine-remote-db]
* [ovirt-guest-agent]
* [ovirt-iso-uploader-conf]
Expand All @@ -64,6 +65,7 @@ Under ``tests`` directory, there are playbooks for different oVirt versions
* tests/test-4.0.yml (Disabled because of #155)
* tests/test-4.1.yml
* tests/test-4.2.yml
* tests/test-promote-db-local-to-remote.yml

```sh
# Install ansible and docker-py
Expand All @@ -84,6 +86,7 @@ under ``Dockerfiles`` directory.
[ovirt-engine-cleanup]: https://github.com/rhevm-qe-automation/ovirt-ansible/blob/master/roles/ovirt-engine-cleanup/README.md
[ovirt-engine-config]: https://github.com/rhevm-qe-automation/ovirt-ansible/blob/master/roles/ovirt-engine-config/README.md
[ovirt-engine-db-dump]: https://github.com/rhevm-qe-automation/ovirt-ansible/blob/master/roles/ovirt-engine-db-dump/README.md
[ovirt-engine-local-to-remote-db]: https://github.com/rhevm-qe-automation/ovirt-ansible/blob/master/roles/ovirt-engine-local-to-remote-db/README.md
[ovirt-engine-remote-db]: https://github.com/rhevm-qe-automation/ovirt-ansible/blob/master/roles/ovirt-engine-remote-db/README.md
[ovirt-engine-remote-dwh]: https://github.com/rhevm-qe-automation/ovirt-ansible/blob/master/roles/ovirt-engine-remote-dwh/README.md
[ovirt-guest-agent]: https://github.com/rhevm-qe-automation/ovirt-ansible/blob/master/roles/ovirt-guest-agent/README.md
Expand Down
11 changes: 11 additions & 0 deletions examples/inventory/engine_local_to_remote_db.inv
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[engine:vars]

#### Type flag ####
# flag that it is engine machine
ovirt_type=engine

[database:vars]

#### Type flag ####
# flag that it is engine machine
ovirt_type=remote_db
7 changes: 7 additions & 0 deletions examples/playbooks/engine_local_to_remote_db.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
# in inventory file engine has ovirt_type=engine, database has ovirt_type=remote_db
- hosts: engine database
vars:
ovirt_engine_dwh_to_remote_db: True
roles:
- ovirt-engine-local-to-remote-db
1 change: 1 addition & 0 deletions roles/ovirt-engine-db-dump/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Role Variables
---
ovirt_engine_db_dump_dwh: [True, False] Dump also DWH database (default: False)
ovirt_engine_db_dump_start_services: [True, False] Start engine and DWH service after dump (default: True)
ovirt_engine_db_dump_local_dir: directory on local machine where to store files (default: engine_dump in playbook directory)
```

Dependencies
Expand Down
2 changes: 1 addition & 1 deletion roles/ovirt-engine-db-dump/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
ovirt_engine_etc_conf_path: "/etc/ovirt-engine/engine.conf.d/"
ovirt_engine_db_dump_dwh: False
ovirt_engine_db_dump_start_services: True

ovirt_engine_db_dump_local_dir: "{{ playbook_dir }}/engine_dump"
53 changes: 30 additions & 23 deletions roles/ovirt-engine-db-dump/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
{{
ovirt_engine_db_dump_engine_db |
combine(
dict([ item.partition('=')[::2] ])
dict([ [item.partition('=')[0], item.partition('=')[2]|regex_replace('\"', '')] ])
)
}}
with_items: "{{ cmd.stdout_lines|list }}"
Expand All @@ -35,7 +35,7 @@
{{
ovirt_engine_db_dump_dwh_db |
combine(
dict([ item.partition('=')[::2] ])
dict([ [item.partition('=')[0], item.partition('=')[2]|regex_replace('\"', '')] ])
)
}}
with_items: "{{ cmd.stdout_lines|list }}"
Expand All @@ -51,56 +51,63 @@
- ovirt-engine

# get engine and dwh database dumps
- name: enable sudo without tty
lineinfile:
path: /etc/sudoers
state: present
regexp: '^Defaults *requiretty$'
line: 'Defaults !requiretty'

- name: get postgres path
become: yes
become_user: postgres
shell: echo $HOME
register: pgpath
tags:
- skip_ansible_lint

- name: create local dir
local_action:
file path={{ playbook_dir }}/engine_dump state=directory
file path={{ ovirt_engine_db_dump_local_dir }} state=directory

- name: get dump of engine database
become: yes
become_user: postgres
shell: pg_dump -F c {{ ovirt_engine_db_dump_engine_db['ENGINE_DB_DATABASE'] }} -f engine.sql
tags:
- skip_ansible_lint
postgresql_db:
name: "{{ ovirt_engine_db_dump_engine_db['ENGINE_DB_DATABASE'] }}"
target: "{{ pgpath.stdout }}/engine.sql"
state: dump

- name: get dump of dwh database
become: yes
become_user: postgres
shell: pg_dump -F c {{ ovirt_engine_db_dump_dwh_db['DWH_DB_DATABASE'] }} -f dwh.sql
postgresql_db:
name: "{{ ovirt_engine_db_dump_dwh_db['DWH_DB_DATABASE'] }}"
target: "{{ pgpath.stdout }}/dwh.sql"
state: dump
when: ovirt_engine_db_dump_dwh == True
tags:
- skip_ansible_lint

# print variables to file
- name: print engine variables to file
local_action:
copy content="{{ ovirt_engine_db_dump_engine_db }}" dest="{{ playbook_dir }}/engine_dump/engine_variables.json"
copy content="{{ ovirt_engine_db_dump_engine_db }}" dest="{{ ovirt_engine_db_dump_local_dir }}/engine_variables.json"

- name: print DWH variables to file
local_action:
copy content="{{ ovirt_engine_db_dump_dwh_db }}" dest="{{ playbook_dir }}/engine_dump/dwh_variables.json"
copy content="{{ ovirt_engine_db_dump_dwh_db }}" dest="{{ ovirt_engine_db_dump_local_dir }}/dwh_variables.json"
when: ovirt_engine_db_dump_dwh == True

# copy files to localhost
- name: get postgres path
become: yes
become_user: postgres
become_method: su
become_flags: "-"
shell: echo $HOME
register: pgpath
tags:
- skip_ansible_lint

- name: copy engine dump to local
fetch:
src: "{{ pgpath.stdout }}/engine.sql"
dest: "{{ playbook_dir }}/engine_dump/engine.sql"
dest: "{{ ovirt_engine_db_dump_local_dir }}/engine.sql"
flat: yes

- name: copy dwh dump to local
fetch:
src: "{{ pgpath.stdout }}/dwh.sql"
dest: "{{ playbook_dir }}/engine_dump/dwh.sql"
dest: "{{ ovirt_engine_db_dump_local_dir }}/dwh.sql"
flat: yes
when: ovirt_engine_db_dump_dwh == True

Expand Down
74 changes: 74 additions & 0 deletions roles/ovirt-engine-local-to-remote-db/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
oVirt Engine Local DB to Remote
===============================

- dump engine/dwh database on engine
- create databases/users on remote server and import dump files, install postgres if neccessary
- set engine from local db to remote

Target systems
--------------

* engine
* database

Requirements
------------

Preinstalled engine with local DB.
Preinstalled clean el7/linux based operating system on remote server.

Role Variables
--------------

```yaml
---
ovirt_engine_to_remote_db: [True, False] Change from local to remote engine database (default: True)
ovirt_engine_dwh_to_remote_db: [True, False] Change from local to remote DWH database (default: False)

ovirt_engine_reset: [True, False] True - set back engine to local db (default: False)
ovirt_engine_drop_local_db: [True, False] Drop local databases after engine is set to remote db, dump will be stored (default: True)
```

Dependencies
------------

Role ovirt-engine-db-dump
Role ovirt-engine-remote-db

Example Playbook
----------------

```yaml
---
# in inventory file engine has ovirt_type=engine, database has ovirt_type=remote_db
- hosts: engine database
vars:
ovirt_engine_dwh_to_remote_db: True
ovirt_engine_version: "4.2"
# var for ovirt-common, this is not a must for ovirt <= 4.1
ovirt_engine_drop_local_db: False
roles:
- ovirt-engine-local-to-remote-db
```

Example Inventory
----------------

```yaml
---
[engine]
engine1.example.com
[engine:vars]
ovirt_type=engine

[database]
db1.example.com
[database:vars]
ovirt_type=remote_db
```

Author Information
------------------

Lucie Leistnerova
[email protected]
12 changes: 12 additions & 0 deletions roles/ovirt-engine-local-to-remote-db/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
ovirt_engine_version: "4.1"
ovirt_engine_reset: False
ovirt_engine_to_remote_db: True
ovirt_engine_dwh_to_remote_db: False
ovirt_engine_etc_conf_files:
- /etc/ovirt-engine/engine.conf.d/10-setup-database.conf
- /etc/ovirt-engine/engine.conf.d/10-setup-dwh-database.conf
- /etc/ovirt-engine-dwh/ovirt-engine-dwhd.conf.d/10-setup-database.conf
ovirt_engine_etc_conf_files_aaa:
- /etc/ovirt-engine/aaa/internal.properties
ovirt_engine_drop_local_db: True
13 changes: 13 additions & 0 deletions roles/ovirt-engine-local-to-remote-db/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
galaxy_info:
author: "Lucie Leistnerova"
description: "oVirt change engine/dwh local to remote database"
company: "Red Hat"
license: "GPLv3"
min_ansible_version: 2.0
platforms:
- name: EL
versions:
- all
galaxy_tags:
- migration
120 changes: 120 additions & 0 deletions roles/ovirt-engine-local-to-remote-db/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
---
- name: set engine variables
set_fact:
engine_ip: "{{ hostvars[inventory_hostname]['ansible_default_ipv4']['address'] }}"
delegate_to: "{{ item }}"
delegate_facts: True
with_items: "{{ groups['all'] }}"
when: ovirt_type == "engine"

- name: set db variables
set_fact:
remote_db_ip: "{{ hostvars[inventory_hostname]['ansible_default_ipv4']['address'] }}"
delegate_to: "{{ item }}"
delegate_facts: True
with_items: "{{ groups['all'] }}"
when: ovirt_type == "remote_db"

# first dump databases on engine and get connection variables
- name: dump databases
include_role:
name: ovirt-engine-db-dump
vars:
ovirt_engine_db_dump_dwh: "{{ ovirt_engine_dwh_to_remote_db }}"
ovirt_engine_db_dump_start_services: False
ovirt_engine_db_dump_local_dir: "{{ playbook_dir }}/engine_dump"
when:
- ovirt_type == "engine"
- ovirt_engine_reset == False

- name: get engine variables from file
include_vars:
file: "{{ playbook_dir }}/engine_dump/engine_variables.json"
name: ovirt_engine_db_dump_engine_db
when:
- ovirt_engine_to_remote_db == True
- ovirt_engine_reset == False

- name: get DWH variables from file
include_vars:
file: "{{ playbook_dir }}/engine_dump/dwh_variables.json"
name: ovirt_engine_db_dump_dwh_db
when:
- ovirt_engine_dwh_to_remote_db == True
- ovirt_engine_reset == False

# create databases on remote server and import data
- name: create databases and import data
include_role:
name: ovirt-engine-remote-db
vars:
ovirt_engine_remote_db_port: "{{ ovirt_engine_db_dump_engine_db['ENGINE_DB_PORT'] }}"
ovirt_engine_db_name: "{{ ovirt_engine_db_dump_engine_db['ENGINE_DB_DATABASE'] }}"
ovirt_engine_db_user: "{{ ovirt_engine_db_dump_engine_db['ENGINE_DB_USER'] }}"
ovirt_engine_db_password: "{{ ovirt_engine_db_dump_engine_db['ENGINE_DB_PASSWORD'] }}"
ovirt_engine_remote_db: "{{ ovirt_engine_to_remote_db }}"
ovirt_engine_dwh_remote_db: "{{ ovirt_engine_dwh_to_remote_db }}"
ovirt_engine_dwh_db_name: "{{ ovirt_engine_db_dump_dwh_db['DWH_DB_DATABASE'] }}"
ovirt_engine_dwh_db_user: "{{ ovirt_engine_db_dump_dwh_db['DWH_DB_USER'] }}"
ovirt_engine_dwh_db_password: "{{ ovirt_engine_db_dump_dwh_db['DWH_DB_PASSWORD'] }}"
ovirt_engine_remote_db_force: True
ovirt_engine_remote_db_dump: "{{ playbook_dir }}/engine_dump/engine.sql"
ovirt_engine_remote_db_dwh_dump: "{{ playbook_dir }}/engine_dump/dwh.sql"
ovirt_engine_remote_db_access:
-
type: host
address: "{{ engine_ip }}/32"
method: md5
when:
- ovirt_type == "remote_db"
- ovirt_engine_reset == False

# set engine from local to remote db
- include: set-engine.yml
when:
- ovirt_type == "engine"
- ovirt_engine_reset == False

# check engine running
- name: check if ovirt-engine running (health page)
uri:
url: "http://{{ ansible_fqdn }}/ovirt-engine/services/health"
status_code: 200
register: ovirt_engine_status
retries: 2
delay: 5
until: ovirt_engine_status|success
ignore_errors: True
when:
- ovirt_type == "engine"
- ovirt_engine_reset == False

# engine is not running reset engine back to local
- name: engine not running - set back to local
set_fact:
ovirt_engine_drop_local_db: False
ovirt_engine_reset: True
when:
- ovirt_type == "engine"
- ovirt_engine_reset == False
- ovirt_engine_status|failed

# reset engine back to local db
- include: reset-engine.yml
when:
- ovirt_type == "engine"
- ovirt_engine_reset == True

# clean
- name: remove dump files from local
local_action:
file path={{ playbook_dir }}/engine_dump state=absent
when:
- ovirt_engine_reset == False

# drop databases
- include: remove-local-db.yml
when:
- ovirt_type == "engine"
- ovirt_engine_drop_local_db == True
- ovirt_engine_reset == False
Loading