Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding role for Supporting Linux OS installation #145

Open
wants to merge 1 commit into
base: dev-collection
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 98 additions & 0 deletions roles/linux_install/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
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
hosts: localhost
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

Inventory file with detials of pxe server, repository server and HMC server is required while running the playbook
---------
[repo]
repo_server ansible_host=9.4.4.4 ansible_user=abc ansible_password=1234
[pxe]
pxe_server ansible_host=9.3.3.3 ansible_user=abc ansible_password=1234
[hmcs]
hmc_server ansible_host=hmc.com
-----------
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
107 changes: 107 additions & 0 deletions roles/linux_install/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
---

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

- name: Create a kickstart file in Repository server
run_once: true
template:
src: templates/ks.j2
dest: "/var/www/html/linux_ks/{{ ks_file }}"
delegate_to: "{{ groups['repo'][0] }}"

- name: Remove any existing tftp boot folder in PXE server for this VM
run_once: true
shell: rm -rf "{{ dest_dir }}"
delegate_to: "{{ groups['pxe'][0] }}"

- name: Calculate cutdir value
shell: echo "{{ 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)
run_once: true
shell: wget -r --reject="index.html*" --no-parent -nH --cut-dir={{ cut_dir.stdout | int + 1 }} http://{{ hostvars[groups['repo'][0]].ansible_host }}:{{ repo_port }}/{{ repo_dir }}/boot/ -P {{ dest_dir }}
delegate_to: "{{ groups['pxe'][0] }}"

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

- name: Create netboot directory in PXE server under tftp path
run_once: true
shell: grub2-mknetdir --net-directory={{ base_dir }} --subdir={{ mac_address }}/boot/grub/
delegate_to: "{{ groups['pxe'][0] }}"

- name: Create grub.cfg and copy to boot directory in PXE server
run_once: true
template:
src: templates/grub_conf.j2
dest: "{{ dest_dir }}/boot/grub/grub.cfg"
delegate_to: "{{ groups['pxe'][0] }}"

- name: copy to grub.cfg to boot directory in PXE server
run_once: true
shell: cp "{{ dest_dir }}/boot/grub/grub.cfg" "{{ dest_dir }}/boot/grub/powerpc-ieee1275/grub.cfg-01-{{ address }}"
delegate_to: "{{ groups['pxe'][0] }}"

- name: Edit dhcpd.conf with the entry for the target VM and start the DHCP service
run_once: true
shell: cp /etc/dhcp/dhcpd.conf /tmp/dhcpd.conf
delegate_to: "{{ groups['pxe'][0] }}"

- name: DHCP block file to add lpar entry into dhcpd.conf
run_once: true
blockinfile:
dest: /etc/dhcp/dhcpd.conf
marker: "#{mark} Ansible module dhcp entry"
block: "{{ lookup('template', 'dhcpd_conf.j2') }}"
state: present
delegate_to: "{{ groups['pxe'][0] }}"

- name: restart dhcp service
run_once: true
shell: systemctl restart dhcpd.service
delegate_to: "{{ groups['pxe'][0] }}"

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

- name: Revert the DHCP configuration changes in PXE server
run_once: true
shell: cp /etc/dhcp/dhcpd.conf /tmp/dhcpd.conf
delegate_to: "{{ groups['pxe'][0] }}"

- name: block file
run_once: true
blockinfile:
dest: /etc/dhcp/dhcpd.conf
marker: "#{mark} Ansible module dhcp entry"
block: "{{ lookup('template', 'dhcpd_conf.j2') }}"
state: absent
delegate_to: "{{ groups['pxe'][0] }}"

- name: resatart dhcp
run_once: true
shell: systemctl restart dhcpd.service
delegate_to: "{{ groups['pxe'][0] }}"
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 }};
group {
next-server {{ hostvars[groups['pxe'][0]].ansible_host }};
filename "{{ core_file_path }}";
host {{ hostname }} {
hardware ethernet {{ hardware_ethernet }};
fixed-address {{ host_ip }};
option host-name {{ lpar_name }};
option tftp-server-name "{{ hostvars[groups['pxe'][0]].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[groups['pxe'][0]].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[groups['repo'][0]].ansible_host }}:{{ repo_port }}{{ repo_dir }} inst.ks=http://{{ hostvars[groups['repo'][0]].ansible_host }}:{{ repo_port }}/linux_ks/{{ 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[groups['repo'][0]].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
46 changes: 46 additions & 0 deletions roles/linux_install/vars/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---

# Redhat Release Name
distro: 9le

# Repository Port Number
repo_port: 81

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

# 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: abcd1234

# Host Details
host_ip: 9.1.1.10
host_gw: 9.1.1.1
host_subnet: 9.1.1.0
host_netmask: 255.255.255.0
dns_ip: 9.0.0.0
hostname: vm.abc.com
lpar_name: vm-hmc
hardware_ethernet: aa:aa:aa:aa:aa:aa
managed_system: vm-abc