Skip to content

Commit

Permalink
Adding role for Supporting Linux OS installation
Browse files Browse the repository at this point in the history
Role have been added to create,
1. Kickstart file - Drive the automated OS installation
2. DHCP setup - Add the lpar entry in DHCP config file inside DHCP server
3. TFTP setup - Add the tftp/grub related files for OS to be installed in accordence with lpar mac address
4. DHCP remove  - cleanup the DHCP config for the lpar created

Signed-off-by: Spoorthy S<[email protected]>
  • Loading branch information
Spoorthy committed Jan 22, 2025
1 parent ba642e9 commit 75f24ee
Show file tree
Hide file tree
Showing 7 changed files with 314 additions and 0 deletions.
88 changes: 88 additions & 0 deletions roles/linux_install/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
Role Name
=========

There are several ways to perform Linux OS installation on IBM Power servers. One of the methods is network-based install via tftpboot. This article explains how ansible can be used to automate this particular method of OS install.
For the installation process, the following servers need to be setup:
1. Http(Repo) server: It has the http service running. This server can be used as a dedicated
server to have all the distro builds downloaded at one place and the required distro can
be picked up from here during installation. If not, just having a server with the required
distro build downloaded and accessible via http will suffice.
2. DHCP - TFTP(pxe) server: It has the tftp and dhcpd service running
3. Lpar – A logical partition on which we will be doing the installation
• When an installation is triggered, a kickstart file is generated on the HTTP server which contains
the configuration details of the required Linux OS installation. The HTTP server also contains the
various builds available.
• The boot files of the required OS are then downloaded on the DHCP-TFTP server. A grub config
file is also created on this server using the previously generated kickstart file.
• Next, the lpar_netboot command instructs the lpar to network boot, by having the partition
send out a bootp request to the DHCP-TFTP server to fetch the initial boot files. With this the
required OS is installed on the Lpar.

Requirements
------------

PXE server up and running the dhcp and tftp services
Repository server hosting the RHEL repositories


Role Variables
--------------

host_ip/host_gw/host_subnet/host_netmask:
type: str
required: true
description: lpar Network details in format 9.9.9.9
dns_ip:
type: str
required: true
description: Nameserver IP details in format 9.1.1.1
hostname:
type: str
required: true
description: hostname of the lpar in format aaa.abc.com
lpar_name:
type: str
required: true
desription: name of lpar as in the HMC
hardware_ethernet:
type: str
required: true
description: MAC address of the lpar in format ff:ff:ff:ff
managed_system:
type: str
required: true
description: system name in HMC in which lpar is available

Example Playbook
----------------

Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too:

---
- name: Install linux
collections:
- ibm.power_hmc
gather_facts: false
roles:
- role: linux_install
vars:
host_ip: 9.9.9.9
host_gw: 9.9.9.1
host_subnet: 9.9.9.0
host_netmask: 255.255.255.0
dns_ip: 9.1.1.1
hostname: aaa.abc.com
lpar_name: name_in_hmc
hardware_ethernet: ff:ff:ff:ff
managed_system: system_name_in_HMC

License
-------

GPL-3.0-only

Author Information
------------------

Spoorthy S

12 changes: 12 additions & 0 deletions roles/linux_install/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
galaxy_info:
author: Spoorthy S
description: Linux installation using pxe server
license: GPL-3.0-only
min_ansible_version: '>=2.14.0'
galaxy_tags:
- infrastructure
- ibm
- power
- hmc
- linux
- pxe
81 changes: 81 additions & 0 deletions roles/linux_install/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
---

- name: Create Kickstart file name
hosts: repo
set_fact:
ks_file: "{{ distro | regex_replace('\\.', '') }}_{{ hardware_ethernet }}.ks"

- name: Create a kickstart file in Repository server
hosts: repo
template:
src: templates/ks.j2
dest: "/var/www/html/linux_ks/{{ ks_file }}"

- name: Remove any existing tftp boot folder in PXE server for this VM
shell: rm -rf {{ dest_dir }}

- name: Calculate cutdir value
shell: echo "{{ hostvars['repo']['repo_dir'] }}" | tr '/' '\n' | grep -v "^$" | wc -l
register: cut_dir

- name: Download files from /boot and /ppc directory in Repository Server to the PXE server tftp path(hardware address)
hosts: pxe
shell: wget -r --reject="index.html*" --no-parent -nH --cut-dir={{ cut_dir.stdout | int + 1 }} http://{{ hostvars['repo'].ansible_host }}:{{ repo_port }}/{{ hostvars['repo']['repo_dir'] }}/boot/ -P {{ dest_dir }}
shell: wget -r --reject="index.html*" --no-parent -nH --cut-dir={{ cut_dir.stdout | int + 1 }} http://{{ hostvars['repo'].ansible_host }}:{{ repo_port }}/{{ hostvars['repo']['repo_dir'] }}/ppc/ -P {{ dest_dir }}

- name: Create netboot directory in PXE server under tftp path
hosts: pxe
shell: grub2-mknetdir --net-directory={{ base_dir }} --subdir={{ mac_address }}/boot/grub/

- name: Create grub.cfg and copy to boot directory in PXE server
hosts: pxe
template:
src: templates/grub_conf.j2
dest: "{{ dest_dir }}/boot/grub/grub.cfg"
shell: cp "{{ dest_dir }}/boot/grub/grub.cfg" "{{ dest_dir }}/boot/grub/powerpc-ieee1275/grub.cfg-01-{{ address }}"

- name: Edit dhcpd.conf with the entry for the target VM and start the DHCP service
hosts: pxe
shell: cp /etc/dhcp/dhcpd.conf /tmp/dhcpd.conf
blockinfile:
dest: /etc/dhcp/dhcpd.conf
marker: "#{mark} Ansible module dhcp entry"
block: "{{ lookup('template', 'dhcpd_conf.j2') }}"
state: present
shell: systemctl restart dhcpd.service

- name: Lparnetboot operation on target lpar
hosts: hmcs
connection: local
collections:
- ibm.power_hmc
powervm_lpar_instance:
hmc_host: "{{ hmc_host }}"
hmc_auth: "{{ curr_hmc_auth }}"
system_name: "{{ managed_system }}"
vm_name: "{{ lpar_name }}"
install_settings:
vm_ip: "{{ host_ip }}"
nim_ip: "{{ hostvars['pxe'].ansible_host }}"
nim_gateway: "{{ host_gw }}"
nim_subnetmask: "{{ host_netmask }}"
vm_mac: "{{ hostvars['pxe']['mac_address'] }}"
timeout: 20
action: install_os

- name: Revert the DHCP configuration changes in PXE server
hosts: pxe
shell: cp /etc/dhcp/dhcpd.conf /tmp/dhcpd.conf
blockinfile:
dest: /etc/dhcp/dhcpd.conf
marker: "#{mark} Ansible module dhcp entry"
block: "{{ lookup('template', 'dhcpd_conf.j2') }}"
state: absent
shell: systemctl restart dhcpd.service







15 changes: 15 additions & 0 deletions roles/linux_install/templates/dhcpd_conf.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
subnet {{ host_subnet }} netmask {{ host_netmask }} {
allow bootp;
option routers {{ host_gw }};
option domain-name-servers {{ dns_ip }};
option domain-name "aus.stglabs.ibm.com";
group {
next-server {{ hostvars['pxe'].ansible_host }};
filename "{{ core_file_path }}";
host {{ hostname }} {
hardware ethernet {{ hardware_ethernet }};
fixed-address {{ host_ip }};
option tftp-server-name "{{ hostvars['pxe'].ansible_host }}";
}
}
}
9 changes: 9 additions & 0 deletions roles/linux_install/templates/grub_conf.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
set timeout=1
menuentry 'Install OS' {
insmod http
insmod tftp
set root=tftp,{{ hostvars['pxe'].ansible_host }}
echo 'Loading OS Install kernel ...'
linux {{ mac_address }}/ppc/ppc64/vmlinuz ifname=net0:{{ hardware_ethernet }} ip={{ host_ip }}::{{ host_gw }}:{{ host_netmask }}:{{ hostname }}:net0:none nameserver={{ dns_ip }} inst.repo=http://{{ hostvars['repo'].ansible_host }}:{{ repo_port }}{{ hostvars['repo']['repo_dir'] }} inst.ks=http://{{ hostvars['repo'].ansible_host }}:{{ repo_port }}/linux_ks/{{ hostvars['repo']['ks_file'] }}
initrd {{ mac_address }}/ppc/ppc64/initrd.img
}
51 changes: 51 additions & 0 deletions roles/linux_install/templates/ks.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Use text mode install
text
# Reboot after installation
reboot

%post
sed -i 's/#\?PermitRootLogin.*/PermitRootLogin yes/g' /etc/ssh/sshd_config;service sshd restart;multipath -t >/etc/multipath.conf;service multipathd start
%end

%addon com_redhat_kdump --enable --reserve-mb='auto'

%end

# Keyboard layouts
keyboard --vckeymap=us --xlayouts='us'
# System language
lang en_US.UTF-8

# Network information
network --hostname="{{ hostname }}"

# Use network installation
url --url="http://{{ hostvars['repo'].ansible_host }}:{{ repo_port }}{{ repo_dir }}/BaseOS"

%packages
@core
device-mapper-multipath
kexec-tools

%end

# System services
services --enabled="NetworkManager,sshd"
# Do not configure the X Window System
skipx

# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel --drives=sda
# System bootloader configuration
bootloader --append="crashkernel=2G-4G:384M,4G-16G:512M,16G-64G:1G,64G-128G:2G,128G-:4G" --location=mbr --boot-drive=sda
autopart --fstype=ext4
# Generated using Blivet version 3.6.0
ignoredisk --only-use=sda

# System timezone
timezone Asia/Kolkata --utc

# Root password
rootpw --plaintext password
58 changes: 58 additions & 0 deletions roles/linux_install/vars/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
---

# Redhat Release Name
distro: 9.1le

# Repository Port Number
repo_port: 81

# Path to the build files in Repository server
repo_dir: "/crtl/repo/rhel/{{ distro }}/nightly"

# Tftp boot directory path in PXE server
base_dir: /var/lib/tftpboot/

# Remove ':' in hardware ethernet address
mac_address: "{{ hardware_ethernet | regex_replace(':', '') }}"

# Append base directory path with a new directory named by mac address
dest_dir: "{{ base_dir }}{{ mac_address }}"

# Set core elf file path in PXE server
core_file_path: "{{ mac_address }}/boot/grub/powerpc-ieee1275/core.elf"

# Replace ':' in hardware ethernet address wit '-'
address: "{{ hardware_ethernet | regex_replace(':', '-') }}"

# HMC credentials
curr_hmc_auth:
username: abc
password: def

# PXE server credentials
pxe:
ansible_host: abc.com
ansible_user: host
ansible_password: password

#Repo server credntial
repo:
ansible_host: abc.com
ansible_user: host
ansible_password: password

# Host Details
host_ip: 9.9.9.9
host_gw: 9.9.9.1
host_subnet: 9.9.9.0
host_netmask: 255.255.255.0
dns_ip: 9.1.1.1
hostname: aaa.abc.com
lpar_name: name_in_hmc
hardware_ethernet: ff:ff:ff:ff
managed_system: system_name_in_HMC





0 comments on commit 75f24ee

Please sign in to comment.