diff --git a/roles/datastore/frontend/README.md b/roles/datastore/frontend/README.md index 732930a..185d56d 100644 --- a/roles/datastore/frontend/README.md +++ b/roles/datastore/frontend/README.md @@ -33,7 +33,7 @@ Example Playbook # Configure OpenNebula to use "ssh" datastores. # Create symlinks accordingly. # NOTE: In case of HA OpenNebula, image and file datastores - # should be shared among all Frontends. + # should be shared among all Frontends. ds: mode: ssh config: @@ -68,6 +68,11 @@ Example Playbook vars: # Configure OpenNebula to use "shared" image and system datastores. # Create new datastores and symlinks accordingly. + # NOTE: 1. In OpenNebula all user-created datastores start from ID=100. + # 2. If the 'id' attribute refers to an existing datastore, then one-deploy tries to update it. + # 3. If 2. is false, then a new datastore is created using the next available ID. + # 4. Users *MUST* provide the 'id' attribute for each new entry in the 'ds.config' dict + # (starting from 100, then incrementing by 1 further down the line). ds: mode: generic config: diff --git a/roles/datastore/generic/defaults/main.yml b/roles/datastore/generic/defaults/main.yml index 5b1d0bc..b8b55fc 100644 --- a/roles/datastore/generic/defaults/main.yml +++ b/roles/datastore/generic/defaults/main.yml @@ -11,7 +11,7 @@ ds_defaults: enabled: true symlink: groups: [node] - src: /var/lib/one/datastores/ + src: /var/lib/one/datastores/ # this skips symlinking template: TYPE: SYSTEM_DS TM_MAD: ssh @@ -21,7 +21,7 @@ ds_defaults: managed: true symlink: groups: [frontend, node] - src: /var/lib/one/datastores/ + src: /var/lib/one/datastores/ # this skips symlinking template: TYPE: IMAGE_DS DS_MAD: fs @@ -32,7 +32,7 @@ ds_defaults: managed: true symlink: groups: [frontend] - src: /var/lib/one/datastores/ + src: /var/lib/one/datastores/ # this skips symlinking template: TYPE: FILE_DS DS_MAD: fs diff --git a/roles/datastore/generic/tasks/common.yml b/roles/datastore/generic/tasks/common.yml index 488d45b..461d012 100644 --- a/roles/datastore/generic/tasks/common.yml +++ b/roles/datastore/generic/tasks/common.yml @@ -7,14 +7,13 @@ {{ _items | items2dict }} vars: _ds: >- - {{ ds_defaults | combine(ds.config | default({}), recursive=true) }} + {{ ds_defaults | combine(ds.config | d({}), recursive=true) }} _items: >- {{ _ds | dict2items | map(attribute='value') | map('dict2items') | flatten - | selectattr('value.managed', 'true') - | list }} + | rejectattr('value.managed', 'false') }} - name: Ensure /var/lib/one/datastores/ exists ansible.builtin.file: @@ -31,26 +30,43 @@ if [[ -L '{{ _base_path }}' ]]; then exit 0; fi - if [[ -d '{{ _base_path }}/' ]] && ! rmdir '{{ _base_path }}/'; then exit 1; fi + if ! [[ -d '{{ _mount_path }}' ]]; then + echo "Symlink target does not exist or is not a directory." >&2 + exit 1 + fi - if ! ln -s '{{ _mount_path }}/' '{{ _base_path }}'; then exit 1; fi + if [[ -d '{{ _base_path }}' ]] && ! rmdir '{{ _base_path }}'; then exit 1; fi + + if ! ln -s '{{ _mount_path }}' '{{ _base_path }}'; then exit 1; fi exit 78 executable: /bin/bash - when: inventory_hostname in _hosts and _mount_path != '/var/lib/one/datastores' + when: + - inventory_hostname in _hosts + # NOTE: It doesn't really make sense to symlink /var/lib/one/datastores/, + # so we use that as a skip condition. + - _mount_path != '/var/lib/one/datastores' vars: + # This isn't strictly a "mountpoint" (that's completely irrelevant). _mount_path: >- - {{ ds_dict[item].symlink.src | normpath }} + {{ ds_dict[item].symlink.src | d('/var/lib/one/datastores/') | normpath }} + # NOTE: 1. In OpenNebula all user-created datastores start from ID=100. + # 2. If the ds_dict[item].id refers to an existing datastore, then one-deploy tries to update it (later). + # 3. If 2. is false, then a new datastore is created using the next available ID (later). + # 4. If 3. is true, then at this exact point in time one-deploy does *NOT* know the ID. + # 5. The 'generic' mode has been specifically designed in such a way that reduces code complexity. + # Users *MUST* provide the 'id' attribute for each new entry in the 'ds.config' dict + # (starting from 100, then incrementing by 1 further down the line). _base_path: >- /var/lib/one/datastores/{{ ds_dict[item].id }} _hosts: >- - {{ ds_dict[item].symlink.groups | map('extract', groups) + {{ ds_dict[item].symlink.groups | d([]) + | map('extract', groups) | flatten - | unique - | list }} - loop: "{{ ds_names }}" + | unique }} register: shell changed_when: - shell.rc == 78 # EREMCHG "Remote address changed" 8^) failed_when: - shell.rc != 0 and shell.rc != 78 + loop: "{{ ds_names }}" diff --git a/roles/datastore/generic/tasks/frontend.yml b/roles/datastore/generic/tasks/frontend.yml index c8de170..c91ee23 100644 --- a/roles/datastore/generic/tasks/frontend.yml +++ b/roles/datastore/generic/tasks/frontend.yml @@ -25,9 +25,9 @@ _document: >- {{ shell.stdout | from_json }} _datastores: >- - {{ [_document.DATASTORE_POOL.DATASTORE | default([])] | flatten | list }} + {{ [_document.DATASTORE_POOL.DATASTORE | d([])] | flatten }} _names: >- - {{ _datastores | map(attribute='NAME') | default([]) | list }} + {{ _datastores | map(attribute='NAME') | d([]) | list }} - when: inventory_hostname == leader block: diff --git a/roles/datastore/simple/tasks/frontend.yml b/roles/datastore/simple/tasks/frontend.yml index 2ef4a6c..895d9b1 100644 --- a/roles/datastore/simple/tasks/frontend.yml +++ b/roles/datastore/simple/tasks/frontend.yml @@ -9,9 +9,14 @@ if [[ -L '{{ _base_path }}' ]]; then exit 0; fi - if [[ -d '{{ _base_path }}/' ]] && ! rmdir '{{ _base_path }}/'; then exit 1; fi + if ! [[ -d '{{ _mount_path }}' ]]; then + echo "Symlink target does not exist or is not a directory." >&2 + exit 1 + fi - if ! ln -s '{{ _mount_path }}/' '{{ _base_path }}'; then exit 1; fi + if [[ -d '{{ _base_path }}' ]] && ! rmdir '{{ _base_path }}'; then exit 1; fi + + if ! ln -s '{{ _mount_path }}' '{{ _base_path }}'; then exit 1; fi exit 78 executable: /bin/bash diff --git a/roles/datastore/simple/tasks/node.yml b/roles/datastore/simple/tasks/node.yml index 7948d58..fba2d9b 100644 --- a/roles/datastore/simple/tasks/node.yml +++ b/roles/datastore/simple/tasks/node.yml @@ -11,9 +11,14 @@ if [[ -L '{{ _base_path }}' ]]; then exit 0; fi - if [[ -d '{{ _base_path }}/' ]] && ! rmdir '{{ _base_path }}/'; then exit 1; fi + if ! [[ -d '{{ _mount_path }}' ]]; then + echo "Symlink target does not exist or is not a directory." >&2 + exit 1 + fi - if ! ln -s '{{ _mount_path }}/' '{{ _base_path }}'; then exit 1; fi + if [[ -d '{{ _base_path }}' ]] && ! rmdir '{{ _base_path }}'; then exit 1; fi + + if ! ln -s '{{ _mount_path }}' '{{ _base_path }}'; then exit 1; fi exit 78 executable: /bin/bash