Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Kogito-2195] Kogito examples with ansible automation #258

Open
wants to merge 41 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
1e07b99
Release of version 0.10.0
cristianonicolai Apr 21, 2020
654af19
Kogito examples with ansible automation
desmax74 May 15, 2020
f3971c0
changes requested by reviewer
desmax74 May 18, 2020
4dee7f9
changes requested by reviewer
desmax74 May 18, 2020
7c027cd
changes requested by reviewer
desmax74 May 25, 2020
73d1f78
changes requested by reviewer
desmax74 May 25, 2020
5eb0cda
versions come from release/tag files
desmax74 May 26, 2020
48847f8
specified exact amount of ram and added pretask to remove hardcoded v…
desmax74 May 26, 2020
85b42af
enabled the tag and ram input
desmax74 May 26, 2020
a0cc19a
Kogito examples with ansible automation
desmax74 May 15, 2020
d78b179
changes requested by reviewer
desmax74 May 18, 2020
b188a30
changes requested by reviewer
desmax74 May 18, 2020
d157a97
changes requested by reviewer
desmax74 May 25, 2020
8eb988a
changes requested by reviewer
desmax74 May 25, 2020
2df8866
versions come from release/tag files
desmax74 May 26, 2020
baba573
specified exact amount of ram and added pretask to remove hardcoded v…
desmax74 May 26, 2020
b77023d
enabled the tag and ram input
desmax74 May 26, 2020
31ac8dd
Merge branch 'kogito-2195' of github.com:desmax74/kogito-examples int…
desmax74 Jun 9, 2020
cd77312
removed ubuntu support until we found a workaround to the loal user f…
desmax74 Jun 9, 2020
cd487d7
update
Jun 16, 2020
2c80cf1
Merge branch 'kogito-2195' of github.com:desmax74/kogito-examples int…
Jun 16, 2020
fa52112
update
Jun 16, 2020
be88c25
Kogito examples with ansible automation
desmax74 May 15, 2020
35f6e3a
changes requested by reviewer
desmax74 May 18, 2020
da2fcb6
changes requested by reviewer
desmax74 May 18, 2020
e76eb8e
changes requested by reviewer
desmax74 May 25, 2020
260aa18
changes requested by reviewer
desmax74 May 25, 2020
5489c7b
versions come from release/tag files
desmax74 May 26, 2020
1fae857
specified exact amount of ram and added pretask to remove hardcoded v…
desmax74 May 26, 2020
78f4018
enabled the tag and ram input
desmax74 May 26, 2020
18c5e10
Kogito examples with ansible automation
desmax74 May 15, 2020
da06eff
update
Jun 16, 2020
bb7c906
changes requested by reviewer
desmax74 May 18, 2020
4df8df3
changes requested by reviewer
desmax74 May 25, 2020
f904f2c
changes requested by reviewer
desmax74 May 25, 2020
0f04340
versions come from release/tag files
desmax74 May 26, 2020
ebd0d10
specified exact amount of ram and added pretask to remove hardcoded v…
desmax74 May 26, 2020
87eb4ff
update
desmax74 Jun 16, 2020
7762734
fix versions
desmax74 Jun 16, 2020
fc05cff
fix versions
desmax74 Jun 16, 2020
7138182
fix poms
desmax74 Jun 16, 2020
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
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,8 @@ shows timers (intermediate and boundary) that allows to introduce delays in proc
Every example has a directory named `operator` including the YAML files to deploy it using the Kogito Operator in an OpenShift cluster.
Please refer to the [Kogito Documentation](https://docs.jboss.org/kogito/release/latest/html_single/#chap_kogito-deploying-on-openshift)
of how to install the operator to your environment in order to try it there.

## Deploying the Kogito example applications on OpenShift CRC using Ansible playbooks
danielezonca marked this conversation as resolved.
Show resolved Hide resolved

In the [Kogito Ansible folder](kogito-ansible/README.md) you find the documentation plus some external videos about how to
setup Openshift locally (CRC) and deploy the kogito examples using ansible, with few commands
90 changes: 90 additions & 0 deletions kogito-ansible/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# Openshift (CRC) Kogito ansible automation

Tested on Fedora 31/32 and Ubuntu 19.10

Ansible scripts to automate creation of CRC cluster and the deploy of one of the Kogito examples with just one command line.

Ansible must be installed.
danielezonca marked this conversation as resolved.
Show resolved Hide resolved
danielezonca marked this conversation as resolved.
Show resolved Hide resolved


### Create an account on cloud.redhat.com
https://cloud.redhat.com/openshift/install and download or copy your Pull secret from the laptop installation https://cloud.redhat.com/openshift/install/crc/installer-provisioned


## Fedora

### Install LibVirt libs
```sh
sudo ansible-playbook ./playbook_libs.yaml
```

### Install CRC
(If you haven't already installed)

Download and copy CRC in the user's path (2GB),
change the app_name (my-kafka-project) in the file if you want different name
```sh
ansible-playbook ./playbook_crc.yaml
```

### Install Kogito on CRC
The create playbook will create from scratch the crc setup, the project namespace, then download and install Kogito Operator and Kogito CLI.
The name of the Project to create and the Pull secret will be asked in the beginning of the run.
To use the default project name (my-kogito-project) just press enter.
```sh
ansible-playbook ./playbook_create.yaml
```

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide setup also for Fedora.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll create two sections in the doc since is all for fedora and only the lib virt installation is the first step on ubuntu

### Deploy Kogito Examples
To deploy one of the kogito examples, enter the name of one of the example,
at the end the browser show you the login page, the output of the deploy with the instructions to see
the logs from cli will be on the ansible output.
```sh
ansible-playbook ./playbook_deploy.yaml
```



## Ubuntu
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this section actually different from the Fedora one?
They are really similar (the same?) from what I can see. Is it possible to create a single Fedora/Ubuntu section and just highlight different steps (if any).
This can reduce maintenance cost of this doc :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously only one section plus the ubuntu lib virt installation was present but at the reviewer seems a document for ubuntu deploy and asked a fedora version, for this reason you see explicit configurations for both systems

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree to have the instructions for Ubuntu and Fedora too but if they are the same just mention that the instructions are tested on both configuration instead of duplicate them :)


### Install LibVirt libs
```sh
sudo ansible-playbook ./playbook_libs.yaml
```

### Install CRC
(If you haven't already installed)
Download and copy CRC in the user's path (2GB),
change the app_name (my-kafka-project) in the file if you want different name
```sh
ansible-playbook ./playbook_crc.yaml
```

### Install Kogito on CRC

The create playbook will create from scratch the crc setup, the project namespace, then download and install Kogito Operator and Kogito CLI.
The name of the Project to create and the Pull secret will be asked in the beginning of the run.
To use the default project name (my-kogito-project) just press enter.
```sh
ansible-playbook ./playbook_create.yaml
```
### Deploy Kogito Examples
To deploy one of the kogito examples, enter the name of one of the example,
at the end the browser show you the login page, the output of the deploy with the instructions to see
the logs from cli will be on the ansible output.
```sh
ansible-playbook ./playbook_deploy.yaml
```



## Videos
Note: The CRC start spent 10 minute on a laptop, cut to few seconds in the video recording

### Setup CRC
Video Duration: 1:39 min.
[![asciicast](https://asciinema.org/a/313700.png)](https://asciinema.org/a/313700)

### Deploy Kpgotp Examples
Video Duration 27:sec
[![asciicast](https://asciinema.org/a/313703.png)](https://asciinema.org/a/313703)
56 changes: 56 additions & 0 deletions kogito-ansible/playbook_crc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
---
- name: Install CRC
hosts: localhost

vars:
crc_version: "1.10.0"
crc_url_file: "https://mirror.openshift.com/pub/openshift-v4/clients/crc/{{crc_version}}/crc-linux-amd64.tar.xz"
crc_tmp_dest: "/tmp/crc-linux-{{crc_version}}-amd64.tar.xz"
crc_package_name: "crc-linux-{{crc_version}}-amd64"
danielezonca marked this conversation as resolved.
Show resolved Hide resolved

tasks:

- name: Create .local/bin/
file:
path: /home/{{ansible_user_id}}/.local/bin/
state: directory

- name: Check if crc exists in /home/{{ansible_user_id}}/.local/bin/
stat:
path: "/home/{{ ansible_user_id }}/.local/bin/crc"
register: stat_result

- name: Check if {{ crc_package_name }}/crc exists in /tmp/
stat:
path: "/tmp/{{ crc_package_name }}/crc"
register: stat_result

- name: "Download crc {{ crc_version }} ~2GB, this takes time and depends on your connection speed"
get_url:
url: "{{ crc_url_file }}"
dest: "{{ crc_tmp_dest }}"
when: stat_result.stat.exists == False

- name: Extract {{ crc_package_name }}.tar.xz into tmp
unarchive:
src: "{{ crc_tmp_dest }}"
dest: /tmp
when: stat_result.stat.exists == False

- name: Check if {{ crc_package_name }}/crc exists in /tmp/
stat:
path: "/tmp/{{ crc_package_name }}/crc"
register: stat_result

- name: Check if crc exists in /home/{{ansible_user_id}}/.local/bin/
stat:
path: "/home/{{ ansible_user_id }}/.local/bin/crc"
register: stat_result
when: stat_result.stat.exists == True

- name: Move crc from /tmp/crc-linux-{{crc_version}}-amd64 to /home/{{ansible_user_id}}/.local/bin
command: "mv /tmp/{{ crc_package_name }}/crc /home/{{ansible_user_id}}/.local/bin/"
when: stat_result.stat.exists == False

- name: crc libvirt group
shell: "crc config set skip-check-user-in-libvirt-group true"
134 changes: 134 additions & 0 deletions kogito-ansible/playbook_create.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
---
- name: Start CRC and deploy Kogito Operator and CLI
hosts: localhost

vars:
kogito_tag: "0.10.0"
danielezonca marked this conversation as resolved.
Show resolved Hide resolved
ram: "16384" #MB
libvirt_version: "4.4.3"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this value hardcoded?

Copy link
Contributor Author

@desmax74 desmax74 May 25, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because is used in the path and you discover the version only when the crc is downloaded and unpacked, or readed from the lates json info

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've writed a version to use the latest kogito tag, but the 0.10.1 doesn't work because the cli and the operator aren't aligned (kogito 0.10.1 - kogito-cloud-operator 0.10.0)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mmm I expect this could happen in the future too so is it possible to add a kogito-operator variable to support also this use case?

ip_on_etc_hosts: 192.168.130.11
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do not use this value which can probably change on different machine etc. It would be much better to use "virt" or "virt_net" modules to obtain info about IP address.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

kube_password: "{{ lookup('file', '/home/{{ ansible_user_id }}/.crc/cache/crc_libvirt_{{ libvirt_version }}/kubeadmin-password') }}"
kogito_url_file: "https://github.com/kiegroup/kogito-cloud-operator/releases/download/{{ kogito_tag }}/kogito-cli-{{ kogito_tag }}-linux-amd64.tar.gz"
kogito_tmp_dest: "/tmp/kogito-{{ kogito_tag }}-linux-amd64.tar.gz"

vars_prompt:
- name: "nameSpace"
default: "my-kogito-project"
prompt: "Insert your Project Name/ NameSpace"
private: "no"
- name: "PullSecret"
prompt: "Insert your Pull secret"

tasks:
- debug: msg="Project Name {{ nameSpace }}"

- name: Check that kogito cli exists in /home/{{ansible_user_id}}/.local/bin/
stat:
path: "/home/{{ ansible_user_id }}/.local/bin/kogito"
register: stat_result

- name: Copy Kogito cli
get_url:
url: "{{kogito_url_file}}"
dest: "{{ kogito_tmp_dest }}"
when: stat_result.stat.exists == False

- name: Extract Kogito cli archive
unarchive:
src: "{{ kogito_tmp_dest }}"
dest: "/tmp/"
when: stat_result.stat.exists == False

- name: Creates user home kogito dir
file:
path: "/home/{{ ansible_user_id}}/.local/bin/"
state: directory
when: stat_result.stat.exists == False

- name: Move kogito from /tmp to /home/{{ansible_user_id}}/.local/bin
command: "mv /tmp/kogito /home/{{ansible_user_id}}/.local/bin/"
when: stat_result.stat.exists == False

- name: CRC setup
shell: "crc setup"
register: crc_result

- debug: msg="{{ crc_result }}"

- name: Write pull secret
copy:
content: "{{ PullSecret }}"
dest: "~/.crc/crc-pull-secret"

- name: Copy Kogito Examples pom
copy:
src: "./../pom.xml"
dest: "/tmp/examples_pom.xml"

- name: "Get Kogito Examples "
shell: xmllint --xpath '/*[local-name()="project"]/*[local-name()="modules"]' /tmp/examples_pom.xml > ~/.crc/quarkus_examples.txt
danielezonca marked this conversation as resolved.
Show resolved Hide resolved

- name: Replace modules tags
replace:
path: ~/.crc/quarkus_examples.txt
regexp: '<modules>'
replace: ''

- name: Replace module tags
replace:
path: ~/.crc/quarkus_examples.txt
regexp: '<module>'
replace: '- '

- name: Replace end module tags
replace:
path: ~/.crc/quarkus_examples.txt
regexp: '</module>'
replace: ''

- name: Replace end modules tags
replace:
path: ~/.crc/quarkus_examples.txt
regexp: '</modules>'
replace: '\n'

- name: Start CRC with {{ ram }}MB (~ 10 minutes)
shell: "crc start -m {{ ram }} -p ~/.crc/crc-pull-secret"

- name: Login crc
shell: "oc login -u kubeadmin -p {{ kube_password }} https://api.crc.testing:6443"

- name: Create {{ nameSpace }}
shell: "oc new-project {{ nameSpace }}"

- name: Use {{ nameSpace }} proect
shell: "oc project {{ nameSpace }}"

- name: Kogito use {{ nameSpace }}
shell: "kogito use-project {{ nameSpace }}"
register: kogito_use_project_result
ignore_errors: yes

- debug: msg="{{ kogito_use_project_result }}"

- name: Kogito install operator on {{ nameSpace }}
shell: "kogito install operator -p {{ nameSpace }}"
register: kogito_install_operator_result

- name: Check AvailableReplica on Kogito operator first on {{ nameSpace }}
shell: "kubectl get pods --selector=name=kogito-operator -o jsonpath='{.items[*].status.phase}'"
register: result_one

- debug: msg="{{ result_one }}"

- name: Check AvailableReplica on Kogito operator first on {{ nameSpace }} wait for up to 120 sec, poll every 10 sec, 12 times
shell: "kubectl get pods --selector=name=kogito-operator -o jsonpath='{.items[*].status.phase}'"
register: result
until: result.stdout.find("Running") != -1
async: 120
poll: 10
retries: 12

- debug: msg="Project Name {{ nameSpace }}"

- debug: msg="Your Kube Password is {{ kube_password }}"
55 changes: 55 additions & 0 deletions kogito-ansible/playbook_deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
- name: Start CRC 1.10.0 and deploy kogito examples
hosts: localhost

vars:
libvirt_version: "4.4.3"
danielezonca marked this conversation as resolved.
Show resolved Hide resolved
ram: "16384" #MB
kube_password: "{{ lookup('file', '/home/{{ ansible_user_id }}/.crc/cache/crc_libvirt_{{ libvirt_version }}/kubeadmin-password') }}"
examples: "{{ lookup('file', '~/.crc/quarkus_examples.txt') }}"
examples_repo: "https://github.com/kiegroup/kogito-examples/"

vars_prompt:
- name: "nameSpace"
prompt: "Insert your Project Name/ NameSpace"
default: "my-kogito-project"
private: "no"

- name: "example"
prompt: "Choose the example to deploy"
default: "\n{{ examples }}"
danielezonca marked this conversation as resolved.
Show resolved Hide resolved
private: "no"

tasks:

- debug: msg="Project Name {{ nameSpace }}"

- name: Start CRC with {{ ram }}MB (~ 10 minutes)
shell: "crc start -m {{ ram }} -p ~/.crc/crc-pull-secret"

- name: Login crc
shell: "oc login -u kubeadmin -p {{ kube_password }} https://api.crc.testing:6443"
ignore_errors: yes

- name: Kogito use {{ nameSpace }}
shell: "kogito use-project {{ nameSpace }}"
register: kogito_use_project_result
ignore_errors: yes

- debug: msg="{{ kogito_use_project_result }}"

- name: Deploy {{ example }}
shell: "kogito deploy-service {{ example }} {{ examples_repo }} --context-dir={{ example }}"
register: install_drools_quarkus_example
ignore_errors: yes

- debug: msg="{{ install_drools_quarkus_example }}"

- debug: msg="Project Name {{ nameSpace }}"

- debug: msg="Your Kube Password is {{ kube_password }}"

- name: Open browser
shell: "crc console"


25 changes: 25 additions & 0 deletions kogito-ansible/playbook_libs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
- name: Install libs on Fedora/Ubuntu
hosts: localhost

tasks:

- name: CheckOS
assert:
that:
- "ansible_os_family == 'Debian' or ansible_os_family == 'RedHat'"

- name: Install Virtualization on Ubuntu
apt:
pkg:
- qemu-kvm
- libvirt-daemon
- libvirt-daemon-system
- network-manager
become: yes
when: ansible_os_family == 'Debian'

- name: Install Virtualization on Fedora
shell: "sudo dnf install @virtualization -y"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use Ansible DNF module instead https://docs.ansible.com/ansible/latest/modules/dnf_module.html#dnf-module

Something like this:
- name: Install Virtualization on Fedora
dnf:
name: "@Virtualization"
become: yes
when: ansible_os_family == 'RedHat'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

become: yes
when: ansible_os_family == 'RedHat'