diff --git a/.gitignore b/.gitignore index f996d492..4f74143a 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ __pycache__/ /ansible_collections/* !/ansible_collections/opennebula/deploy /inventory/.one-deploy/ +/inventory/views/ /inventory/*.yml !/inventory/example.yml !/inventory/local.yml diff --git a/roles/gui/defaults/main.yml b/roles/gui/defaults/main.yml index 80c061c6..cb5849fe 100644 --- a/roles/gui/defaults/main.yml +++ b/roles/gui/defaults/main.yml @@ -5,3 +5,16 @@ ssl_defaults: web_server: apache # could be nginx key: /etc/ssl/private/opennebula-key.pem certchain: /etc/ssl/certs/opennebula-certchain.pem + +sunstone_views: [] +# Example: +# sunstone_views: +# - name: example_view +# label: "Custom view" +# description: "A custom view for users" +# groups: +# - oneadmin +# - users +# source_folder: one-deploy/views/example_view +sunstone_views_base_dir: /etc/one/fireedge/sunstone/views/ +sunstone_views_config_file: "{{ sunstone_views_base_dir }}/sunstone-views.yaml" diff --git a/roles/gui/tasks/main.yml b/roles/gui/tasks/main.yml index 4ae4a8cb..1fb840f5 100644 --- a/roles/gui/tasks/main.yml +++ b/roles/gui/tasks/main.yml @@ -52,3 +52,7 @@ ansible.builtin.include_tasks: file: "{{ role_path }}/tasks/{{ ssl.web_server }}.yml" when: ssl is defined + +- name: Deploy Sunstone Views + ansible.builtin.include_tasks: + file: "{{ role_path }}/tasks/sunstone_views.yml" diff --git a/roles/gui/tasks/sunstone_views.yml b/roles/gui/tasks/sunstone_views.yml new file mode 100644 index 00000000..a6080d59 --- /dev/null +++ b/roles/gui/tasks/sunstone_views.yml @@ -0,0 +1,65 @@ +--- +- when: _input | count > 0 + vars: + _input: >- + {{ sunstone_views | d([]) }} + _values_loaded: >- + {{ cfgtool_groups_and_views['values'] }} + _groups_loaded: >- + {{ _values_loaded.0.0 }} + _views_loaded: >- + {{ _values_loaded.1.0 }} + _groups_updated: >- + {%- set output = _groups_loaded -%} + {%- for v in _input -%} + {%- for g in v.groups -%} + {{- + output.update({ g: (output[g] | d([]) + [v.name]) | unique }) + -}} + {%- endfor -%} + {%- endfor -%} + {{- output -}} + _views_updated: >- + {%- set output = _views_loaded -%} + {%- for v in _input -%} + {{- + output.update({ v.name: { "name": v.label, "description": v.description } }) + -}} + {%- endfor -%} + {{- output -}} + block: + - name: Copy custom Sunstone views from inventory + ansible.builtin.copy: + dest: "{{ _dest | normpath }}/" # / is strictly required here + src: "{{ _src | normpath }}/" # / is strictly required here + mode: u=rw,go=r + vars: + _dest: >- + {{ sunstone_views_base_dir }}/{{ item.name }} + _src: >- + {{ inventory_dir }}/views/{{ item.source_folder }} + loop: "{{ _input }}" + loop_control: { label: "{{ item.name }}" } + + - name: Read 'groups' and 'views' from sunstone-views.yaml + opennebula.deploy.cfgtool: + dest: "{{ sunstone_views_config_file }}" + parser: Yaml + actions: + - get: + path: [groups] + - get: + path: [views] + register: cfgtool_groups_and_views + + - name: Write updated 'groups' and 'views' into sunstone-views.yaml + opennebula.deploy.cfgtool: + dest: "{{ sunstone_views_config_file }}" + parser: Yaml + actions: + - put: + path: [groups] + value: "{{ _groups_updated }}" + - put: + path: [views] + value: "{{ _views_updated }}"