From bf2ac9d2aeacd6958b26edf5595edbc5edc2b45f Mon Sep 17 00:00:00 2001 From: Max Date: Fri, 15 May 2020 12:47:00 +0200 Subject: [PATCH] doc and ansible scripts to spinup and deploy kogito examples on crc --- doc-content/kogito-ansible-docs/README.md | 57 ++++++++ .../kogito-ansible-docs/playbook_crc.yaml | 55 ++++++++ .../kogito-ansible-docs/playbook_create.yaml | 131 ++++++++++++++++++ .../kogito-ansible-docs/playbook_deploy.yaml | 55 ++++++++ .../playbook_etc_hosts.yaml | 28 ++++ .../kogito-ansible-docs/playbook_libs.yaml | 11 ++ 6 files changed, 337 insertions(+) create mode 100644 doc-content/kogito-ansible-docs/README.md create mode 100644 doc-content/kogito-ansible-docs/playbook_crc.yaml create mode 100644 doc-content/kogito-ansible-docs/playbook_create.yaml create mode 100644 doc-content/kogito-ansible-docs/playbook_deploy.yaml create mode 100644 doc-content/kogito-ansible-docs/playbook_etc_hosts.yaml create mode 100644 doc-content/kogito-ansible-docs/playbook_libs.yaml diff --git a/doc-content/kogito-ansible-docs/README.md b/doc-content/kogito-ansible-docs/README.md new file mode 100644 index 0000000000..352cbdebda --- /dev/null +++ b/doc-content/kogito-ansible-docs/README.md @@ -0,0 +1,57 @@ +# Openshift (CRC) Kogito ansible automation + +Ansible scripts to automate creation of CRC cluster and the deploy of one of the Kogito examples with just one command line. + +CRC 1.10.0, and Ansible must be installed. +No previous CRC setup (no /home/{user}/.crc folder), otherwise the create script will fail, delete .crc if you want run more than once the create playbook + +### Create an account on cloud.redhat.com +https://cloud.redhat.com/openshift/install and download or copy your Pull secret from the the laptop installation https://cloud.redhat.com/openshift/install/crc/installer-provisioned + + +### Install CRC +(If you haven't already installed) + +Pre requisite on Debian/Ubuntu: + +Install libvirt libs on Debian/Ubuntu only: +```sh +sudo ansible-playbook ./playbook_libs.yaml +``` + + +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 +``` + +Configure etc/hosts (default is kafka_cluster_name: "my-cluster-kafka" and app_namespace: "my-kafka-project") +```sh +sudo ansible-playbook ./playbook_etc_hosts.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 +``` +Note: The CRC start spent 10 minute on a laptop, cut to few seconds in the video recording + +Video Duration: 1:39 min. +[![asciicast](https://asciinema.org/a/313700.png)](https://asciinema.org/a/313700) + + +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 +``` +Video Duration 27:sec +[![asciicast](https://asciinema.org/a/313703.png)](https://asciinema.org/a/313703) diff --git a/doc-content/kogito-ansible-docs/playbook_crc.yaml b/doc-content/kogito-ansible-docs/playbook_crc.yaml new file mode 100644 index 0000000000..cbe90aa237 --- /dev/null +++ b/doc-content/kogito-ansible-docs/playbook_crc.yaml @@ -0,0 +1,55 @@ +--- +- name: Install CRC + hosts: localhost + gather_facts: true + + vars: + crc_version: "1.10.0" + + 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-linux-{{crc_version}}-amd64/crc exists in /tmp/ + stat: + path: "/tmp/crc-linux-{{crc_version}}-amd64/crc" + register: stat_result + when: stat_result.stat.exists == False + + - name: "Download crc {{crc_version}} ~2GB, this takes time and depends on your connection speed" + get_url: + url: "https://mirror.openshift.com/pub/openshift-v4/clients/crc/{{crc_version}}/crc-linux-amd64.tar.xz" + dest: "/tmp/crc-linux-{{crc_version}}-amd64.tar.xz" + when: stat_result.stat.exists == False + + - name: Extract crc-linux-{{crc_version}}-amd64.tar.xz into tmp + unarchive: + src: /tmp/crc-linux-{{crc_version}}-amd64.tar.xz + dest: /tmp + when: stat_result.stat.exists == False + + - name: Check if crc-linux-{{crc_version}}-amd64/crc exists in /tmp/ + stat: + path: "/tmp/crc-linux-{{crc_version}}-amd64/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-linux-{{crc_version}}-amd64/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" \ No newline at end of file diff --git a/doc-content/kogito-ansible-docs/playbook_create.yaml b/doc-content/kogito-ansible-docs/playbook_create.yaml new file mode 100644 index 0000000000..218db98691 --- /dev/null +++ b/doc-content/kogito-ansible-docs/playbook_create.yaml @@ -0,0 +1,131 @@ +--- + - name: Start CRC 1.10.0 and deploy Kogito Operator and CLI + hosts: localhost + gather_facts: true + + vars: + kogito_tag: "0.10.0" + ram: "16384" #MB + libvirt_version: "4.4.3" + ip_on_etc_hosts: 192.168.130.11 + kube_password: "{{ lookup('file', '/home/{{ ansible_user_id }}/.crc/cache/crc_libvirt_{{ libvirt_version }}/kubeadmin-password') }}" + + 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: Copy Kogito cli + get_url: + url: "https://github.com/kiegroup/kogito-cloud-operator/releases/download/{{ kogito_tag }}/kogito-cli-{{ kogito_tag }}-linux-amd64.tar.gz" + dest: "/tmp/kogito-{{ kogito_tag }}-linux-amd64.tar.gz" + + - name: Extract Kogito cli archive + unarchive: + src: "/tmp/kogito-{{ kogito_tag }}-linux-amd64.tar.gz" + dest: "/tmp/" + + - name: Check that oc exists in /home/{{ansible_user_id}}/.local/bin/ + stat: + path: "/home/{{ ansible_user_id }}/.local/bin/kogito" + register: stat_result + + - 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: Download Kogito Examples pom + get_url: + url: "https://raw.githubusercontent.com/kiegroup/kogito-examples/stable/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 + + - name: Replace modules tags + replace: + path: ~/.crc/quarkus_examples.txt + regexp: '' + replace: '' + + - name: Replace module tags + replace: + path: ~/.crc/quarkus_examples.txt + regexp: '' + replace: '- ' + + - name: Replace end module tags + replace: + path: ~/.crc/quarkus_examples.txt + regexp: '' + replace: '' + + - name: Replace end modules tags + replace: + path: ~/.crc/quarkus_examples.txt + regexp: '' + 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 }}" \ No newline at end of file diff --git a/doc-content/kogito-ansible-docs/playbook_deploy.yaml b/doc-content/kogito-ansible-docs/playbook_deploy.yaml new file mode 100644 index 0000000000..6867af2934 --- /dev/null +++ b/doc-content/kogito-ansible-docs/playbook_deploy.yaml @@ -0,0 +1,55 @@ +--- + - name: Start CRC 1.10.0 and deploy kogito examples + hosts: localhost + gather_facts: true + + vars: + libvirt_version: "4.4.3" + 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') }}" + + 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 }}" + 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 }} https://github.com/kiegroup/kogito-examples/ --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" + + diff --git a/doc-content/kogito-ansible-docs/playbook_etc_hosts.yaml b/doc-content/kogito-ansible-docs/playbook_etc_hosts.yaml new file mode 100644 index 0000000000..1aab83941f --- /dev/null +++ b/doc-content/kogito-ansible-docs/playbook_etc_hosts.yaml @@ -0,0 +1,28 @@ +--- +- name: Checks etc/hosts config + hosts: localhost + + vars: + kafka_cluster_name: "my-cluster-kafka" + app_namespace: "my-kogito-project" + ip_on_etc_hosts: 192.168.130.11 + + tasks: + + - name: Check api in hosts + lineinfile: + path: /etc/hosts + line: "{{ip_on_etc_hosts}} api.crc.testing" + create: yes + + - name: Check oauth in hosts + lineinfile: + path: /etc/hosts + line: "{{ip_on_etc_hosts}} oauth-openshift.apps-crc.testing" + create: yes + + - name: Check console in hosts + lineinfile: + path: /etc/hosts + line: "{{ip_on_etc_hosts}} console-openshift-console.apps-crc.testing" + create: yes \ No newline at end of file diff --git a/doc-content/kogito-ansible-docs/playbook_libs.yaml b/doc-content/kogito-ansible-docs/playbook_libs.yaml new file mode 100644 index 0000000000..fdae422dae --- /dev/null +++ b/doc-content/kogito-ansible-docs/playbook_libs.yaml @@ -0,0 +1,11 @@ +--- +- name: Install libs on Debian/Ubuntu + hosts: localhost + gather_facts: true + + tasks: + + - name: install + shell: "sudo apt install qemu-kvm libvirt-daemon libvirt-daemon-system network-manager -y" + become: yes + when: ansible_os_family == 'Debian' \ No newline at end of file