Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ __pycache__/
/ansible_collections/*
!/ansible_collections/opennebula/deploy
/inventory/.one-deploy/
/inventory/views/
/inventory/*.yml
!/inventory/example.yml
!/inventory/local.yml
Expand Down
13 changes: 13 additions & 0 deletions roles/gui/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
4 changes: 4 additions & 0 deletions roles/gui/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
65 changes: 65 additions & 0 deletions roles/gui/tasks/sunstone_views.yml
Original file line number Diff line number Diff line change
@@ -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 }}"