Skip to Content
Technical Articles
Author's profile photo Shankar Gomare

Automate ABAP for HANA deployment using Ansible

In this article you will learn to deploy multiple A4H containers using Ansible.

Ansible is an open-source software provisioning, configuration management, and application-deployment tool enabling infrastructure as code.

An Ansible playbook is a blueprint of automation tasks—which are complex IT actions executed with limited or no human involvement. Ansible playbooks are executed on a set, group, or classification of hosts, which together make up an Ansible inventory.

The following is our Ansible playbook which will install Docker-CE and ABAP Trial 1909 in just one command.

This playbook is also available on my GitHub repo here to clone. I highly recommend to clone GitHub repo instead copy pest.

---
- name: Deploy ABAP 1909
  hosts: 127.0.0.1
  remote_user: root
  become: 'yes'
  become_method: sudo  
  vars:
    DOCKER_PACKAGES:
      - apt-transport-https
      - ca-certificates
      - curl
      - gnupg-agent
      - software-properties-common

  tasks:
  - name: Update apt packages
    apt:
      update_cache: "yes"
      force_apt_get: "yes"

  - name: Run whoami without become.
    command: whoami
    changed_when: false
    become: false
    register: whoami

  - name: Install packages needed for Docker
    apt:
      name: "{{ DOCKER_PACKAGES }}"
      state: present
      force_apt_get: "yes"

  - name : Find distro
    shell: "echo $(awk '/^ID=/' /etc/*-release | sed 's/ID=//' | tr '[:upper:]' '[:lower:]')"
    register: dist

  - name: Add Docker GPG apt Key
    apt_key:
      url: https://download.docker.com/linux/{{dist.stdout}}/gpg
      state: present

  - name: Save the current Ubuntu release version into a variable
    shell: lsb_release -cs
    register: dist_version

  - name: Add Docker Repository
    apt_repository:
      repo: "deb [arch=amd64] https://download.docker.com/linux/{{dist.stdout}} {{ dist_version.stdout }} stable"
      state: present

  - name: Update apt packages
    apt:
      update_cache: "yes"
      force_apt_get: "yes"

  - name: Install Docker
    apt:
      name: "docker-ce"
      state: present
      force_apt_get: "yes"

  - name: Test Docker with hello world example
    shell: "docker run hello-world"
    ignore_errors: yes
    register: hello_world_output

  - name: Show output of hello word example
    debug:
      msg: "Container Output: {{hello_world_output.stdout}}"

  - name: Create docker group
    group:
      name: "docker"
      state: present

  - name: Adding user {{ whoami.stdout }} to docker group  
    user:
      name: "{{ whoami.stdout }}"
      groups: "docker"
      append: "yes"

  - name: Log into Dockerhub
    shell: "docker login -u {{ docker_user }} -p {{ docker_password }}"
    register: docker_login_output

  - name: Show output of dockerLogin
    debug:
      msg: "Docker Login: {{docker_login_output.stdout}}"

  - name : Verify existing container
    shell: "docker ps -aqf \"name=a4h\""
    register: valid

  - name: Output container IDs
    debug:
      msg: "Container IDs: {{valid}}"

  - name: Deploy Developer Editon 1909
    shell: >
      docker run
      --stop-timeout 3600
      --sysctl kernel.shmmax=21474836480 
      --sysctl kernel.shmmni=32768 
      --sysctl kernel.shmall=5242880 
      --sysctl kernel.msgmni=1024 
      --sysctl kernel.sem="1250 256000 100 8192" 
      --ulimit nofile=1048576:1048576
      -di --name a4h -h vhcala4hci
      -p 3200:3200 
      -p 3300:3300 
      -p 8443:8443 
      -p 30213:30213 
      -p 50000:50000 
      -p 50001:50001 store/saplabs/abaptrial:1909
      -agree-to-sap-license
    register: deploy_ABAP
    when: valid.stdout == ""

  - name: Show output of 1909 deploy
    debug:
      msg: "Container Output: {{deploy_ABAP}}"
    when: valid.stdout == ""

  - name: Start existing container
    shell: "docker start a4h"
    when: valid.stdout != ""

The following command installs Ansible in Debian based Linux distros.

sudo apt install ansible -y

 

We need to get playbook either from GitHub or copy pest from above code section.

# Get Ansible Playbook from GitHub
git clone https://github.com/sgomare/sapnetweaverabaptrial1909.git

# Change directory 
cd sapnetweaverabaptrial1909/

Next, replace “hubuser” and “hubpassword” for Docker Hub account in the below command before running Ansible playbook.

# Runs in background, disconnection from remote system does not stop installation process 
# Recommended for remote systems
nohup ansible-playbook deployABAP1909.yml --extra-vars "docker_user=hubuser docker_password=hubpassword" &

# Runs in forground, disconnection from remote system will kill processs 
# Recommanded for local systems
ansible-playbook deployABAP1909.yml --extra-vars "docker_user=hubuser docker_password=hubpassword"

That’s it, at the end of execution you will see a summary of completed tasks, this command also deploys ABAP Trial 1909 container(container name a4h).

PLAY RECAP *********************************************************************
127.0.0.1                  : ok=22   changed=9    unreachable=0    failed=0   

To access container deployment log docker logs command can be used as follows.

The docker log will not be available for docker image pull, which takes most of the time in the overall process.

docker logs a4h --follow

The following two commands can be used to stop and start a4h container on demand.

docker stop a4h
docker start a4h

 

If you prefer manual step by step installation, here is my blog for Ubuntu:

https://blogs.sap.com/2021/03/01/sap-abap-platform-1909-developer-edition-on-ubuntu/

 

If you like this article, feel free to share, tweet, like or follow me for new articles.

Assigned Tags

      Be the first to leave a comment
      You must be Logged on to comment or reply to a post.