Skip to content

Commit

Permalink
Create direct clone of showroom role called nookbag (#6744)
Browse files Browse the repository at this point in the history
* Create direct clone of showroom role called nookbag

* Break up long lines in showroom role

* Implement nookbag flow

---------

Co-authored-by: Aleix Casanovas <[email protected]>
  • Loading branch information
tonykay and aleixhub authored Jul 26, 2023
1 parent 6d038f1 commit 2e33cea
Show file tree
Hide file tree
Showing 30 changed files with 745 additions and 0 deletions.
13 changes: 13 additions & 0 deletions ansible/roles/nookbag/.yamllint
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
extends: default

rules:
comments:
require-starting-space: false
min-spaces-from-content: 1
comments-indentation: disable
indentation:
indent-sequences: consistent
line-length:
max: 120
allow-non-breakable-inline-mappings: true
49 changes: 49 additions & 0 deletions ansible/roles/nookbag/README.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
== Showroom

Showroom is an Ansible role that installs and configures Showroom, a replacement for bookbag.
Showroom provides views (1 or more webpages) onto external web based resouces (e.g. websites, webapps, etc.).
It's primary use case is to provide a 1 stop console for demos, workshops, and labs.

=== Core Concepts

* Views - a view is a webpage that is displayed in the browser, it can include:
** Demo, lab, workshop content - typically created in asciidoc with Antora or similar
** Tabs (iframed) - internal or external http based services e.g.
*** Terminal(s) (tty) e.g. Butterfly, xtermjs etc
*** IDEs such as VSCode/CodeServer, JupyterNotes etc
*** Consoles e.g. OpenShift, ArgoCD, Automation Controller etc

NOTE: Consoles are typically iframed into a view, but can be opened in a new tab/window.
Issues *may* arise with iframing some consoles, e.g. OpenShift, ArgoCD, Automation Controller etc and these are actively being investiagted.


=== Requirements

* Ansible 2.9 or higher

Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required.

=== Role Variables


A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well.

=== Dependencies

A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles.

=== Example Playbook


- hosts: servers
roles:
- showroom

==== License

BSD

===== Author Information

- Tony Kay ([email protected])

38 changes: 38 additions & 0 deletions ansible/roles/nookbag/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
Role Name
=========

A brief description of the role goes here.

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

Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required.

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

A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well.

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

A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles.

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

Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too:

- hosts: servers
roles:
- { role: username.rolename, x: 42 }

License
-------

BSD

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

An optional section for the role authors to include contact information, or a website (HTML is not allowed).
35 changes: 35 additions & 0 deletions ansible/roles/nookbag/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
# TODO: make this repo generic example

# Content repo with *optional* tag
nookbag_git_repo: https://github.com/aleixhub/hello-world-lab.git
showroom_nookbag: https://github.com/rhpds/nookbag/archive/refs/tags/nookbag-v0.0.3.zip
showroom_git_tag: main

showroom_default_playbook: site.yml # Default antora playbook to build from

showroom_user: showroom
showroom_group: showroom
showroom_home_dir: /opt/showroom # Also base dir for all things showroom

showroom_container_compose_template: main_compose_template.j2

showroom_tab_services:
- double_terminal
- codeserver
- docs

showroom_dnf_packages:
- git
- podman

showroom_pip_packages:
- podman-compose

showroom_npm_packages:
- antora
- "@antora/[email protected]"

showroom_work_dirs:
- "{{ showroom_home_dir }}/content" # The showroom repo itself, asciidoc source e.g. Antora
- "{{ showroom_home_dir }}/orchestration" # compose, kube files etc
53 changes: 53 additions & 0 deletions ansible/roles/nookbag/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
galaxy_info:
author: your name
description: your role description
company: your company (optional)

# If the issue tracker for your role is not on github, uncomment the
# next line and provide a value
# issue_tracker_url: http://example.com/issue/tracker

# Choose a valid license ID from https://spdx.org - some suggested licenses:
# - BSD-3-Clause (default)
# - MIT
# - GPL-2.0-or-later
# - GPL-3.0-only
# - Apache-2.0
# - CC-BY-4.0
license: license (GPL-2.0-or-later, MIT, etc)

min_ansible_version: 2.1

# If this a Container Enabled role, provide the minimum Ansible Container version.
# min_ansible_container_version:

#
# Provide a list of supported platforms, and for each platform a list of versions.
# If you don't wish to enumerate all versions for a particular platform, use 'all'.
# To view available platforms and versions (or releases), visit:
# https://galaxy.ansible.com/api/v1/platforms/
#
# platforms:
# - name: Fedora
# versions:
# - all
# - 25
# - name: SomePlatform
# versions:
# - all
# - 1.0
# - 7
# - 99.99

galaxy_tags: []
# List tags for your role here, one per line. A tag is a keyword that describes
# and categorizes the role. Users find roles by searching for tags. Be sure to
# remove the '[]' above, if you add tags to this list.
#
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
# Maximum 20 tags per role.

dependencies: []
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
# if you add dependencies to this list.
31 changes: 31 additions & 0 deletions ansible/roles/nookbag/tasks/10-showroom-user-setup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---

#
# Create the showroom user and working directories
#

- name: "Create showroom user {{ showroom_user }}"
ansible.builtin.user:
name: "{{ showroom_user | default('showroom') }}"
home: "{{ showroom_home_dir }}"

- name: Setup persistent working directory
ansible.builtin.file:
path: "{{ __showroom_work_dir }}"
state: directory
owner: "{{ showroom_user | default('showroom') }}"
group: "{{ showroom_group | default('showroom') }}"
loop: "{{ showroom_work_dirs }}"
loop_control:
loop_var: __showroom_work_dir

- name: Add passwordless sudo for {{ showroom_user }}
ansible.builtin.lineinfile:
path: /etc/sudoers
regexp: "^{{ showroom_user }}"
line: "{{ showroom_user }} ALL=(ALL) NOPASSWD: ALL"

#
# TODO: (post PoC)
# ssh configuration for showroom_user
#
33 changes: 33 additions & 0 deletions ansible/roles/nookbag/tasks/20-showroom-dependencies.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
- name: Ensure Linux Package depedencies
ansible.builtin.dnf:
name: "{{ __showroom_dnf_packages }}"
state: present
loop: "{{ showroom_dnf_packages }}"
loop_control:
loop_var: __showroom_dnf_packages

- name: Ensure Linux Python depedencies
ansible.builtin.pip:
name: "{{ __showroom_pip_packages }}"
state: present
loop: "{{ showroom_pip_packages }}"
loop_control:
loop_var: __showroom_pip_packages

#
# TODO: Probably remove the npm code
# far better to do this via an antora image than locally installed npm
# however useful during debug for showroom developers

- name: Install antora
when: showroom_debug | default(false) | bool
community.general.npm:
name: "{{ __showroom_npm_packages }}"
global: true
state: present
loop: "{{ showroom_npm_packages }}"
loop_control:
loop_var: __showroom_npm_packages
tags:
- showroom-npm
36 changes: 36 additions & 0 deletions ansible/roles/nookbag/tasks/30-showroom-clone-and-inject.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
- name: Clone and Inject Showroom Tasks
block:

- name: Clone showroom primary repo - lab content in adoc
ansible.builtin.git:
repo: "{{ showroom_git_repo }}"
dest: "{{ showroom_home_dir }}/content"
force: true
version: "{{ showroom_git_tag | default('main') }}"
become_user: "{{ showroom_user }}"

- name: Setup and inject userdata
block:

- name: Load AgnosticD User Data
ansible.builtin.set_fact:
f_user_data: >-
{{ lookup('file', hostvars.localhost.output_dir ~ '/user-data.yaml', errors='ignore') | from_yaml }}
- name: Fallback for AgnosticD User Data
when: f_user_data | default({}) | length == 0
ansible.builtin.set_fact:
f_user_data: []

- name: Create KV file
ansible.builtin.template:
src: include_vars.adoc.j2
dest: "{{ showroom_home_dir }}/content/documentation/modules/ROOT/pages/include_vars.adoc"
owner: "{{ showroom_user }}"
group: "{{ showroom_group }}"
mode: '0644'
tags:
- showroom-var-injection
tags:
- showroom-clone-and-inject
40 changes: 40 additions & 0 deletions ansible/roles/nookbag/tasks/40-showroom-render.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---

- name: Render asciidoc via antora container
containers.podman.podman_container:
name: container
image: docker.io/antora/antora
command: site.yml
volumes:
- "{{ showroom_home_dir }}/content:/antora:Z"
become_user: "{{ showroom_user }}"
register: r_podman_run_antora
tags:
- showroom-render

- name: Debug Render asciidoc via antora container
ansible.builtin.debug:
var: "{{ r_podman_run_antora }}"
verbosity: 2

# TODO: Insert index.html and css injection
# clunky and hardcoded for now, make dynamic

- name: Insert nookbag
ansible.builtin.unarchive:
src: "{{ showroom_nookbag }}"
dest: "{{ showroom_home_dir }}/content"
remote_src: True
owner: "{{ showroom_user }}"
group: "{{ showroom_group }}"
mode: "u=rw,g=r,o=r"

- name: Insert lab-config.yml file
ansible.builtin.template:
src: lab-config.yml.j2
dest: "{{ showroom_home_dir }}/content/lab-config.yml"
owner: "{{ showroom_user }}"
group: "{{ showroom_group }}"
mode: "u=rw,g=r,o=r"
tags:
- showroom-config-file
29 changes: 29 additions & 0 deletions ansible/roles/nookbag/tasks/50-showroom-service.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
#
# Orchestrate showroom containers
#

- name: Insert showroom orchestration files, compose and systemd
ansible.builtin.template:
src: "{{ __orchestration.src }}"
dest: "{{ __orchestration.dest }}"
owner: "{{ __orchestration.owner | default(showroom_user) }}"
group: "{{ __orchestration.group | default(showroom_group) }}"
mode: "u=rw,g=r,o=r"
loop:
- src: "{{ showroom_container_compose_template | default('container-compose.yml.j2') }}"
dest: "{{ showroom_home_dir }}/orchestration/container-compose.yml"
- src: nginx.conf.j2
dest: "{{ showroom_home_dir }}/orchestration/nginx.conf"
- src: "{{ showroom_systemd_service_template | default('showroom.service.j2') }}"
dest: "/etc/systemd/system/showroom.service"
owner: root
group: root
loop_control:
loop_var: __orchestration

- name: Enable and Start showroom service
ansible.builtin.service:
name: showroom.service
enabled: true
state: started
15 changes: 15 additions & 0 deletions ansible/roles/nookbag/tasks/60-showroom-verify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
#
# TODO: Basic verification of the showroom service
# - does it run
# - all of it?

- name: Output showroom view(s) URLs as userinfo and userdata
agnosticd_user_info:
msg: >-
showroom_primary_view_url: http://{{ groups['bastions'][0] |
regex_replace('\\..*$') }}.{{ guid }}{{ subdomain_base_suffix }}:8000
data:
showroom_primary_view_url: >-
http://{{ groups['bastions'][0] |
regex_replace('\\..*$') }}.{{ guid }}{{ subdomain_base_suffix }}:8000
Loading

0 comments on commit 2e33cea

Please sign in to comment.