Saturday, February 10, 2024

Ansible Role for Java 17 Installation on Ubuntu - Ansible Role to Install Java on Ubuntu 22.0.4

1. Login to Ansible management server/machine. Create SSH keys in Ansible host machine by executing the below command: (if you already have keys created, please skip this step)

ssh-keygen 

enter three times..now you will see keys successfully created.
2.  Execute the below command on Ansible management node and copy the public key content:
sudo cat ~/.ssh/id_rsa.pub

copy the above output.
3. Now login to target node, execute the below command to open the file
sudo vi /home/ubuntu/.ssh/authorized_keys
type shift A and then enter now 
    and paste the key in the above file. please do not delete any existing values in this file.

4. Now go back to Ansible mgmt node, do changes in /etc/ansible/hosts file to include the node you will be installing software. Make sure you add public IP address of target node as highlighted below in red color:
sudo vi /etc/ansible/hosts
[My_Group]  
xx.xx.xx.xx ansible_ssh_user=ubuntu ansible_ssh_private_key_file=~/.ssh/id_rsa  ansible_python_interpreter=/usr/bin/python3

5. let's make sure Ansible Control node is able to connect to target node

ansible -m ping all

ansible all -a "whoami"



6. make changes in Ansible Role as given below,
cd ~/roles

sudo vi aws-infra-role/tasks/installJava17.yml

---
    - name: Task - 1 Update APT package manager repositories cache
      become: true
      apt:
        update_cache: yes
    - name: Task -2 Install Java using Ansible
      become: yes
      apt:
        name: "{{ packages }}"
        state: present
      vars:
        packages:
           - openjdk-17-jdk

7. Create Ansible main playbook

sudo vi aws-infra-role/setup-jenkins.yml
---
# This Playbook creates infra in aws cloud

- hosts: My_Group
  gather_facts: False
  tags: jenkins creation

  tasks:
  - include: tasks/installJava17.yml

8. Execute Ansible Role
ansible-playbook aws-infra-role/setup-jenkins.yml

now after successfully executing, enter below command to make sure Java is installed in target node:

java -version
openjdk version "17.0.7" 2020-04-14
OpenJDK Runtime Environment (build 11.0.7+10-post-Ubuntu-2ubuntu218.04)
OpenJDK 64-Bit Server VM (build 11.0.7+10-post-Ubuntu-2ubuntu218.04, mixed mode, sharing)

No comments:

Post a Comment

What is GitHub Advanced Security for Azure DevOps | Configure GitHub Advanced Security for Azure DevOps

GitHub Advanced Security for Azure DevOps brings the  secret scanning, dependency scanning  and  CodeQL code scanning  solutions already ava...