Skip to main content
Skip table of contents

Automation

Helm install using Ansible Playbook

1. Helm Install

Helm install using Ansible Playbook vi install_helm.yml.

CODE
#update_install_helm.yml
---
- name: Install Helm on 192.168.2.249
  hosts: my_hosts
  become: true

  tasks:
    - name: Update apt cache
      ansible.builtin.apt:
        update_cache: yes

    - name: Install curl
      ansible.builtin.apt:
        name: curl
        state: present

    - name: Download Helm installation script
      ansible.builtin.get_url:
        url: https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3
        dest: /tmp/get_helm.sh
        mode: '0755'

    - name: Run Helm installation script
      ansible.builtin.shell: /tmp/get_helm.sh

    - name: Verify Helm installation
      ansible.builtin.command: helm version
      register: helm_version

    - name: Show Helm version
      ansible.builtin.debug:
        msg: "Helm version installed: {{ helm_version.stdout }}"

2. Enable bash completion for helm

Generate the scripts for help bash completion using Ansible playbook

vi enable_helm_bash_completion.yml file.

CODE
#enable_helm_bash_completion.yml
---
- name: Enable Helm bash completion on 192.168.2.249
  hosts: my_hosts
  become: true

  tasks:
    - name: Ensure bash-completion is installed
      ansible.builtin.apt:
        name: bash-completion
        state: present
        update_cache: yes

    - name: Generate Helm bash completion script
      ansible.builtin.command: helm completion bash
      register: helm_completion_script

    - name: Create bash completion directory for Helm if it doesn't exist
      ansible.builtin.file:
        path: /etc/bash_completion.d
        state: directory
        mode: '0755'

    - name: Save Helm bash completion script to /etc/bash_completion.d/helm
      ansible.builtin.copy:
        content: "{{ helm_completion_script.stdout }}"
        dest: /etc/bash_completion.d/helm
        mode: '0644'

    - name: Enable Helm bash completion in ~/.bashrc
      ansible.builtin.lineinfile:
        path: ~/.bashrc
        line: "source /etc/bash_completion.d/helm"
        create: yes
        state: present

    - name: Reload bash configuration
      ansible.builtin.shell: source ~/.bashrc
      args:
        executable: /bin/bash

3.Clone the Expertflow CX repository

clone git repo using ansible playbook

vi clone_gitlab_repo.yml file.

CODE
#clone_gitlab_repo.yml
---
- name: Clone GitLab repository on 192.168.2.249
  hosts: my_hosts
  become: true

  vars:
    gitlab_repo_url: "https://efcx:RecRpsuH34yqp56YRFUb@gitlab.expertflow.com/cim/cim-solution.git"  # Change this to your GitLab repository URL
    target_directory: "/home/ansible/expertflow/"  # Set the path where the repository should be cloned
    git_branch: "CX-4.6"  # Set the branch you want to clone (optional)

  tasks:
    - name: Ensure git is installed
      ansible.builtin.apt:
        name: git
        state: present
        update_cache: yes

    - name: Clone GitLab repository
      ansible.builtin.git:
        repo: "{{ gitlab_repo_url }}"
        dest: "{{ target_directory }}"
        version: "{{ git_branch }}"
        update: yes  # Set to 'yes' if you want to pull the latest changes if the repo already exists

Deploy Postgresql using Ansible Playbook

vi deploy_postgresql_helm.yml

CODE
#deploy_postgresql_helm.yml
---
- name: Deploy PostgreSQL using Helm on 192.168.2.249
  hosts: my_hosts
  become: true
  vars:
    namespace: "ef-external"  # Namespace to deploy PostgreSQL
    release_name: "ef-postgresql"  # Helm release name
    chart_name: "external/bitnami/postgresql"  # Chart path or name
    values_file: "/path/to/external/bitnami/postgresql/values.yaml"  # Path to the values.yaml file
    kubeconfig_path: "/etc/rancher/rke2/rke2.yaml"  # Path to the kubeconfig file

  tasks:
    - name: Ensure namespace exists
      community.kubernetes.k8s:
        state: present
        kind: Namespace
        name: "{{ namespace }}"
        kubeconfig: "{{ kubeconfig_path }}"

    - name: Deploy or upgrade PostgreSQL with Helm
      community.kubernetes.helm:
        name: "{{ release_name }}"
        chart_ref: "{{ chart_name }}"
        namespace: "{{ namespace }}"
        kubeconfig: "{{ kubeconfig_path }}"
        values_file: "{{ values_file }}"
        wait: true
        timeout: 600  # 10 minutes
        state: present
        debug: true

Deployment Of MongoDB Using Ansible Playbook

Create a File with the name vi mongodb_helm_install.yml.

CODE
# mongodb_rke2_helm_install.yml
---
- name: Install RKE2 and MongoDB with Helm
  hosts: my_hosts
  become: true
  tasks:
    - name: Install dependencies
      apt:
        name: [curl, apt-transport-https]
        state: present
        update_cache: true

    - name: Install RKE2
      shell: |
        curl -sfL https://get.rke2.io | sh -
      args:
        creates: /usr/local/bin/rke2

    - name: Start RKE2 server
      systemd:
        name: rke2-server
        enabled: true
        state: started

    - name: Create symlink for kubectl
      file:
        src: /var/lib/rancher/rke2/bin/kubectl
        dest: /usr/local/bin/kubectl
        state: link

    - name: Copy kubeconfig for kubectl
      copy:
        src: /etc/rancher/rke2/rke2.yaml
        dest: /root/.kube/config
        remote_src: true

    - name: Set permissions on kubeconfig
      file:
        path: /root/.kube/config
        mode: '0600'

    - name: Install Helm
      shell: |
        curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
      args:
        creates: /usr/local/bin/helm

    - name: Add repository for Helm charts
      shell: helm repo add bitnami https://charts.bitnami.com/bitnami
      register: helm_repo_add
      changed_when: "'has been added' in helm_repo_add.stdout"

    - name: Update Helm repositories
      shell: helm repo update

    - name: Create a namespace for MongoDB
      shell: kubectl create namespace mongodb || true

    - name: Install MongoDB using Helm
      command: >
        helm install my-mongodb bitnami/mongodb
        --set architecture=standalone
        --set replicaCount=1
        --set auth.rootPassword="Expertflow123$"
        --namespace mongodb
      args:
        creates: "/var/lib/mongodb"
JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.