aboutsummaryrefslogtreecommitdiffstats
path: root/ansible/roles/ansible-vvp-volumes
diff options
context:
space:
mode:
Diffstat (limited to 'ansible/roles/ansible-vvp-volumes')
-rw-r--r--ansible/roles/ansible-vvp-volumes/tasks/main.yml55
-rw-r--r--ansible/roles/ansible-vvp-volumes/tasks/provision_filesystems.yml99
-rw-r--r--ansible/roles/ansible-vvp-volumes/tasks/provision_volumes.yml61
-rw-r--r--ansible/roles/ansible-vvp-volumes/tasks/rollback_volumes.yml39
-rw-r--r--ansible/roles/ansible-vvp-volumes/tasks/snapshot_volumes.yml70
5 files changed, 324 insertions, 0 deletions
diff --git a/ansible/roles/ansible-vvp-volumes/tasks/main.yml b/ansible/roles/ansible-vvp-volumes/tasks/main.yml
new file mode 100644
index 0000000..841ded4
--- /dev/null
+++ b/ansible/roles/ansible-vvp-volumes/tasks/main.yml
@@ -0,0 +1,55 @@
+# -*- encoding: utf-8 -*-
+# ============LICENSE_START=======================================================
+# org.onap.vvp/engagementmgr
+# ===================================================================
+# Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+# ===================================================================
+#
+# Unless otherwise specified, all software contained herein is licensed
+# under the Apache License, Version 2.0 (the “License”);
+# you may not use this software except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+#
+#
+# Unless otherwise specified, all documentation contained herein is licensed
+# under the Creative Commons License, Attribution 4.0 Intl. (the “License”);
+# you may not use this documentation except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# https://creativecommons.org/licenses/by/4.0/
+#
+# Unless required by applicable law or agreed to in writing, documentation
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# ============LICENSE_END============================================
+#
+# ECOMP is a trademark and service mark of AT&T Intellectual Property.
+- include: provision_volumes.yml
+ tags:
+ - provision-volumes
+
+- include: snapshot_volumes.yml pool_name=rbd snap_name=autosnap num_keep_snaps=5 days_keep_snaps=5
+ tags:
+ - snapshot-volumes
+ - deploy
+ with_items:
+ - "{{rbd_volumes| map(attribute='mount')| list}}"
+ loop_control:
+ loop_var: volume_name
+
+- include: rollback_volumes.yml
+ tags:
+ - rollback_volumes
+ when: rollback_volumes != []
diff --git a/ansible/roles/ansible-vvp-volumes/tasks/provision_filesystems.yml b/ansible/roles/ansible-vvp-volumes/tasks/provision_filesystems.yml
new file mode 100644
index 0000000..804f010
--- /dev/null
+++ b/ansible/roles/ansible-vvp-volumes/tasks/provision_filesystems.yml
@@ -0,0 +1,99 @@
+# -*- encoding: utf-8 -*-
+# ============LICENSE_START=======================================================
+# org.onap.vvp/engagementmgr
+# ===================================================================
+# Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+# ===================================================================
+#
+# Unless otherwise specified, all software contained herein is licensed
+# under the Apache License, Version 2.0 (the “License”);
+# you may not use this software except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+#
+#
+# Unless otherwise specified, all documentation contained herein is licensed
+# under the Creative Commons License, Attribution 4.0 Intl. (the “License”);
+# you may not use this documentation except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# https://creativecommons.org/licenses/by/4.0/
+#
+# Unless required by applicable law or agreed to in writing, documentation
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# ============LICENSE_END============================================
+#
+# ECOMP is a trademark and service mark of AT&T Intellectual Property.
+---
+- debug:
+ msg: "{{volume}}"
+
+- name: map RBD | Provision Filesystem
+ shell: rbd map {{volume.mount}}
+ register: result
+
+- set_fact: block_device="{{result.stdout}}"
+
+- name: Get device Format | Provision Filesystems
+ shell: parted {{block_device}} print | grep 'Partition Table:'
+ register: result
+
+- set_fact:
+ is_formatted: false
+ when: result.stdout.find('unknown') != -1
+
+- set_fact:
+ is_formatted: true
+ when: result.stdout.find('loop') != -1
+
+- name: Format block devices | Provision Filesystems
+ shell: mkfs.{{volume.type}} {{block_device}}
+ when: not is_formatted
+
+- name: mount RBD | Provision Filesystems
+ mount:
+ src: "{{block_device}}"
+ # TODO: 2.3 uses "path" instead of "name"
+ name: /tmp/mnt/{{volume.mount}}
+ fstype: xfs
+ state: mounted
+
+- name: create directories | Provision Filesystems
+ file:
+ path: /tmp/mnt/{{volume.mount}}/{{dir.name|default(dir)}}
+ state: directory
+ owner: "{{dir.owner|default('root')}}"
+ group: "{{dir.group|default('root')}}"
+ recurse: yes
+ with_items: "{{volume.directories}}"
+ loop_control:
+ loop_var: dir
+
+- name: unmount RBD | Provision Filesystems
+ mount:
+ src: "{{block_device}}"
+ # TODO: 2.3 uses "path" instead of "name"
+ name: /tmp/mnt/{{volume.mount}}
+ state: unmounted
+
+- name: remove RBD from fstab | Provision Filesystems
+ mount:
+ src: "{{block_device}}"
+ # TODO: 2.3 uses "path" instead of "name"
+ name: /tmp/mnt/{{volume.mount}}
+ state: absent
+
+- name: unmap RBD | Provision Filesystems
+ shell: rbd unmap {{volume.mount}}
diff --git a/ansible/roles/ansible-vvp-volumes/tasks/provision_volumes.yml b/ansible/roles/ansible-vvp-volumes/tasks/provision_volumes.yml
new file mode 100644
index 0000000..ffb0b8e
--- /dev/null
+++ b/ansible/roles/ansible-vvp-volumes/tasks/provision_volumes.yml
@@ -0,0 +1,61 @@
+# -*- encoding: utf-8 -*-
+# ============LICENSE_START=======================================================
+# org.onap.vvp/engagementmgr
+# ===================================================================
+# Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+# ===================================================================
+#
+# Unless otherwise specified, all software contained herein is licensed
+# under the Apache License, Version 2.0 (the “License”);
+# you may not use this software except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+#
+#
+# Unless otherwise specified, all documentation contained herein is licensed
+# under the Creative Commons License, Attribution 4.0 Intl. (the “License”);
+# you may not use this documentation except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# https://creativecommons.org/licenses/by/4.0/
+#
+# Unless required by applicable law or agreed to in writing, documentation
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# ============LICENSE_END============================================
+#
+# ECOMP is a trademark and service mark of AT&T Intellectual Property.
+---
+- name: Register current volumes | Provision Volumes
+ shell: rbd list
+ register: rbd_list
+
+- name: Create block devices | Provision Volumes
+ command: /usr/bin/rbd create {{item.mount}} --image-feature layering --size {{item.size}}
+ register: command_result
+ failed_when: "'File exists' not in command_result.stderr and command_result.stderr != ''"
+ with_items: "{{rbd_volumes}}"
+ when: rbd_list.stdout.find(item.mount) == -1
+
+- name: Format block devices | Provision Volumes
+ shell: rbd map {{item.mount}} | xargs mkfs.{{item.type}}; rbd unmap {{item.mount}}
+ with_items: "{{rbd_volumes}}"
+ when: rbd_list.stdout.find(item.mount) == -1
+
+- name: Create required directories | Provision Volumes
+ include: provision_filesystems.yml volume={{item}}
+ with_items: "{{rbd_volumes}}"
+ when: item.directories is defined or item.permissions is defined
+ tags:
+ - provision-volumes
diff --git a/ansible/roles/ansible-vvp-volumes/tasks/rollback_volumes.yml b/ansible/roles/ansible-vvp-volumes/tasks/rollback_volumes.yml
new file mode 100644
index 0000000..4bd1e2b
--- /dev/null
+++ b/ansible/roles/ansible-vvp-volumes/tasks/rollback_volumes.yml
@@ -0,0 +1,39 @@
+# -*- encoding: utf-8 -*-
+# ============LICENSE_START=======================================================
+# org.onap.vvp/engagementmgr
+# ===================================================================
+# Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+# ===================================================================
+#
+# Unless otherwise specified, all software contained herein is licensed
+# under the Apache License, Version 2.0 (the “License”);
+# you may not use this software except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+#
+#
+# Unless otherwise specified, all documentation contained herein is licensed
+# under the Creative Commons License, Attribution 4.0 Intl. (the “License”);
+# you may not use this documentation except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# https://creativecommons.org/licenses/by/4.0/
+#
+# Unless required by applicable law or agreed to in writing, documentation
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# ============LICENSE_END============================================
+#
+# ECOMP is a trademark and service mark of AT&T Intellectual Property.
+# placeholder
diff --git a/ansible/roles/ansible-vvp-volumes/tasks/snapshot_volumes.yml b/ansible/roles/ansible-vvp-volumes/tasks/snapshot_volumes.yml
new file mode 100644
index 0000000..e0611eb
--- /dev/null
+++ b/ansible/roles/ansible-vvp-volumes/tasks/snapshot_volumes.yml
@@ -0,0 +1,70 @@
+# -*- encoding: utf-8 -*-
+# ============LICENSE_START=======================================================
+# org.onap.vvp/engagementmgr
+# ===================================================================
+# Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+# ===================================================================
+#
+# Unless otherwise specified, all software contained herein is licensed
+# under the Apache License, Version 2.0 (the “License”);
+# you may not use this software except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+#
+#
+# Unless otherwise specified, all documentation contained herein is licensed
+# under the Creative Commons License, Attribution 4.0 Intl. (the “License”);
+# you may not use this documentation except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# https://creativecommons.org/licenses/by/4.0/
+#
+# Unless required by applicable law or agreed to in writing, documentation
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# ============LICENSE_END============================================
+#
+# ECOMP is a trademark and service mark of AT&T Intellectual Property.
+- debug:
+ msg: "{{volume_name}} {{pool_name}} {{snap_name}} {{timestamp}}"
+
+- name: Create a new snapshot
+ shell: rbd snap create {{pool_name}}/{{volume_name}}@{{timestamp}}_{{snap_name}}
+ become: True
+
+- name: Get number of existing snaps
+ shell: rbd snap list --pool {{pool_name}} {{volume_name}} | grep -P "^\s*[0-9]*\s.*{{snap_name}}" | wc -l
+ register: num_of_rbd_snaps
+ become: True
+
+- name: Get oldest snaps list
+ shell: rbd snap list --pool {{pool_name}} {{volume_name}} | grep -P "^\s*[0-9]*\s.*_{{snap_name}}" | awk '{ print $2}' | awk -F"_" '{print $1}' | sort -n -r | tail -n+{{num_keep_snaps|int + 1}}
+ register: list_of_rbds
+ when: num_of_rbd_snaps.stdout|int > num_keep_snaps|int
+ become: True
+
+- debug:
+ msg: "{{list_of_rbds}}"
+
+- debug:
+ msg: "{{num_of_rbd_snaps.stdout}} {{num_keep_snaps}} {{num_keep_snaps|int < num_of_rbd_snaps.stdout|int}}"
+
+- name: Delete oldest snaps
+ shell: rbd --pool {{pool_name}} snap rm --snap {{item}}_{{snap_name}} {{volume_name}}
+ when: list_of_rbds.skipped is not defined and
+ list_of_rbds.stdout_lines != "" and
+ num_of_rbd_snaps.stdout|int > num_keep_snaps|int and
+ (ansible_date_time.epoch|int - item|int) / 86400|int >= days_keep_snaps|int
+ with_items: "{{list_of_rbds.stdout_lines}}"
+ become: True