Skip to content

Commit

Permalink
Updated dnf bootstrap as per the latest changes in AIX Toolbox (#45)
Browse files Browse the repository at this point in the history
Signed-off-by: Nitish K Mishra <[email protected]>
  • Loading branch information
nitismis authored Nov 24, 2023
1 parent 1368299 commit 7f71bf5
Show file tree
Hide file tree
Showing 10 changed files with 352 additions and 254 deletions.
16 changes: 0 additions & 16 deletions playbooks/demo_bootstrap_dnf.yml

This file was deleted.

17 changes: 17 additions & 0 deletions playbooks/demo_dnf_bootstrap.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
- name: "Bootstrap dnf on VIOS"
hosts: all
gather_facts: no
user: root
collections:
- ibm.power_vios
tasks:

# CHECK for dnf on inventory host
- import_role:
name: power_aix_bootstrap
vars:
pkgtype: "dnf"
download_dir: "~"
target_dir: "/tmp/.ansible.cpdir"
ansible_user: root
19 changes: 7 additions & 12 deletions roles/power_vios_bootstrap/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Ansible Role: power_vios_bootstrap
The [IBM Power Systems VIOS](../../README.md) collection provides an [Ansible role](https://docs.ansible.com/ansible/latest/user_guide/playbooks_reuse_roles.html), referred to as `power_vios_bootstrap`, which automatically loads and executes commands to install and update dnf and dependent softwares.In addition it installs python3 and dependencies as well.
The [IBM Power Systems VIOS](../../README.md) collection provides an [Ansible role](https://docs.ansible.com/ansible/latest/user_guide/playbooks_reuse_roles.html), referred to as `power_vios_bootstrap`, which automatically loads and executes commands to install dependent software.

For guides and reference, see the [Docs Site](https://ibm.github.io/ansible-power-vios/roles.html).
For guides and reference, see the [Docs Site](https://ibm.github.io/ansible-power-aix/roles.html).

## Requirements

Expand All @@ -15,17 +15,11 @@ Available variables are listed below, along with if they are required, type and

Specifies the package service requiring bootstrap installation.
pkgtype: [dnf]
Bootstrap for dnf is supported for VIOS 3.X.
Bootstrap for dnf is supported for all VIOS versions.
yum is not supported now on any VIOS version.

-- pkgtype arguments
- dnf
Uses the AIX toolsbox to install dnf and dependencies on AIX 7.3 and above.

opt_free_size (optional, str, 900)

Specifies the free space in megabytes needed in the /opt folder. It is used by dnf, wget and pycurl bootstraps.

var_free_size (optional, str, 200)

Specifies the free space in megabytes needed in the /var folder.

Expand All @@ -46,9 +40,10 @@ None.
- hosts: vios
gather_facts: no
include_role:
name: power_vios_bootstrap
name: power_aix_bootstrap
vars:
pkgtype: dnf
pkgtype: dnf


## Copyright
© Copyright IBM Corporation 2021
4 changes: 2 additions & 2 deletions roles/power_vios_bootstrap/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ rpm_repo_src: "ftp://ftp.software.ibm.com/aix/freeSoftware/aixtoolbox/INSTALLP/p
rpm_src: "rpm.rte"
yum_repo_src: "ftp://ftp.software.ibm.com/aix/freeSoftware/aixtoolbox/ezinstall/ppc"
dnf_src_71_72: "dnf_bundle_aix_71_72.tar"
dnf_src_73: "dnf_bundle_aix_73.tar"
dnf_install_script: "dnf_installer.sh"
opt_free_size: 900
var_free_size: 200
proxy: None
199 changes: 147 additions & 52 deletions roles/power_vios_bootstrap/files/dnf_installer.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#!/bin/sh
#!/bin/ksh
# This scripts downloads the rpm.rte & dnf_bundle.tar
# rpm.rte-4.13.0.x which is a prequisite for dnf.
# dnf_bundle.tar contains dnf and its dependent packages.
# This script checks if any of the package from dnf_bundle is
# already installed and then installs the packages accordingly.

tmppath="/tmp/.ansible.cpdir"
arg="-y"
tmppath=${2:-$(pwd)}
arg=$1

if [[ -e /usr/opt/rpm/bin/rpm ]]
then
Expand All @@ -16,18 +16,18 @@ else
fi

# Check if we are running this as the root user.
if [[ "$(id -u)" != "0" ]]
if [[ "$(/usr/bin/id -u)" != "0" ]]
then
echo "This script must be run as root."
exit 1
fi

# First check the AIX version.
oslvl=$(/usr/bin/oslevel)
oslvl=`/usr/bin/oslevel`
aix_ver=$(/usr/bin/lslpp -qLc bos.rte | /usr/bin/awk -F':' '{print $3}')
af1=$(echo "$aix_ver" | /usr/bin/cut -d"." -f1)
af2=$(echo "$aix_ver" | /usr/bin/cut -d"." -f2)
af3=$(echo "$aix_ver" | /usr/bin/cut -d"." -f3)
af1=$(echo $aix_ver | /usr/bin/cut -d"." -f1)
af2=$(echo $aix_ver | /usr/bin/cut -d"." -f2)
af3=$(echo $aix_ver | /usr/bin/cut -d"." -f3)
if [[ "$oslvl" = "7.1.0.0" ]]
then
if [[ ( ! $af1 -ge 7 ) || ( ! $af2 -ge 1 ) || ( ! $af3 -ge 3 ) ]]
Expand All @@ -45,90 +45,100 @@ fi

# Check if yum3 is installed.
yum3_instd=0
$RPM_CMD -qa | grep yum-3.4.3 > /dev/null 2>&1
$RPM_CMD -qa | /usr/bin/grep yum-3.4.3 > /dev/null 2>&1
if [[ $? -eq 0 ]]
then
yum3_instd=1
fi

prog=${0##*/}
yum4=0

if [ "$arg" == "-y" ]
arg=`echo $1 | /usr/bin/cut -c1-3`
if [[ "$arg" = "-d" ]]
then
echo "YUM is already installed in the machine."
echo "This is script will update to YUM4(dnf)"
yum4=2 # Update existing YUM3 to YUM4
yum4=1 # Install only dnf if no YUM is installed.
if [[ $yum3_instd -eq 1 ]]
then
echo "YUM is already installed in the machine."
echo "Please use the option -y to update to YUM4(dnf)."
exit 1
fi
elif [[ "$arg" = "-y" ]]
then
yum4=2 # Update existing YUM3 to YUM4.
elif [[ "$arg" = "-n" ]]
then
yum4=3 # Have both YUM and dnf at the same time.
else
usage
fi


# Check openssl version.
function print_openssl_err {
echo "Please install openssl 1.0.2.2001 and higher version and try again."
echo "Please install openssl 1.1.x and higher version."
echo "You can download and install latest openssl from AIX web download site"
echo "https://www-01.ibm.com/marketing/iwm/platform/mrs/assets?source=aixbp"
exit 1
}
ssl_ver=$(lslpp -Lc openssl.base | /usr/bin/awk 'FNR==2' | /usr/bin/awk -F':' '{print $3}')
f1=$(echo "$ssl_ver" | /usr/bin/cut -d"." -f1)
f2=$(echo "$ssl_ver" | /usr/bin/cut -d"." -f2)
f3=$(echo "$ssl_ver" | /usr/bin/cut -d"." -f3)
f4=$(echo "$ssl_ver" | /usr/bin/cut -d"." -f4)
if [[ ( ! $f1 -ge 1 ) || ( ! $f2 -ge 0 ) || ( ! $f3 -ge 0) ]]
then
print_openssl_err
elif [[ ( $f2 -eq 0 ) && ( $f3 -eq 1) ]]
f1=$(echo $ssl_ver | /usr/bin/cut -d"." -f1)
f2=$(echo $ssl_ver | /usr/bin/cut -d"." -f2)
f3=$(echo $ssl_ver | /usr/bin/cut -d"." -f3)
f4=$(echo $ssl_ver | /usr/bin/cut -d"." -f4)
if [[ ( ! $f1 -ge 1 ) ]] || [[ ( $f1 -eq 1 ) && ( ! $f2 -ge 1 ) ]]
then
print_openssl_err
else
if [[ ( $f1 -eq 1 ) && ($f2 -eq 0 ) && ( $f3 -eq 2 ) ]]
then
if [[ ( ! $f4 -ge 2001 ) ]]
then
print_openssl_err
fi
fi
fi

oslvl=$(/usr/bin/oslevel)
oslvl=`/usr/bin/oslevel`
aix_730_plus=0
os_f1=$(echo "$oslvl" | /usr/bin/cut -d"." -f1)
os_f2=$(echo "$oslvl" | /usr/bin/cut -d"." -f2)
os_f3=$(echo "$oslvl" | /usr/bin/cut -d"." -f3)
os_f4=$(echo "$oslvl" | /usr/bin/cut -d"." -f4)
os_f1=$(echo $oslvl | /usr/bin/cut -d"." -f1)
os_f2=$(echo $oslvl | /usr/bin/cut -d"." -f2)
os_f3=$(echo $oslvl | /usr/bin/cut -d"." -f3)
os_f4=$(echo $oslvl | /usr/bin/cut -d"." -f4)
if [[ ( $os_f1 -ge 7 ) && ( $os_f2 -ge 3 ) && ( $os_f3 -ge 0 ) && ( $os_f4 -ge 0 ) ]]
then
aix_730_plus=1
fi

aix_715_prior=0
oslvl_tl=`/usr/bin/lslpp -qLc bos.rte | /usr/bin/cut -d: -f3`
os_f1=$(echo $oslvl_tl | /usr/bin/cut -d"." -f1)
os_f2=$(echo $oslvl_tl | /usr/bin/cut -d"." -f2)
os_f3=$(echo $oslvl_tl | /usr/bin/cut -d"." -f3)
if [[ ( $os_f1 -eq 7 ) && ( $os_f2 -eq 1 ) && ( $os_f3 -lt 5 ) ]]
then
aix_715_prior=1
fi

# Check if /tmp has enough space to download rpm.rte & dnf_bundle
# and size for extracting rpm packages.
# For 71_72 bundle it requires around 340 MB of free space.
# 170M for bundle which includes rpm.rte (40M) and rpm packages (130M).
# rpm packages extracted.

if [[ $aix_730_plus -eq 1 ]]
then
typeset -i total_req=$(echo "(270)" | bc)
echo "this is the tmppath: $tmppath"
tmp_free=$(/usr/bin/df -m "$tmppath" | sed -e /Filesystem/d | awk '{print $3}' | bc)
typeset -i total_req=$(echo "(512)" | bc)
tmp_free=$(/usr/bin/df -m "$tmppath" | /usr/bin/sed -e /Filesystem/d | /usr/bin/awk '{print $3}')
if [[ $tmp_free -le $total_req ]]
then
chfs -a size=+$(( total_req - tmp_free ))M "$tmppath"
if [[ $? -ne 0 ]];
then
echo "Please make sure $tmppath has around 270MB of free space to download and"
echo "Please make sure $tmppath has around 512MB of free space to download and"
echo "extract files from dnf_bundle."
exit 1
fi
fi
else
typeset -i total_req=$(echo "(340)" | bc)
tmp_free=$(/usr/bin/df -m "$tmppath" | sed -e /Filesystem/d | awk '{print $3}')
typeset -i total_req=`echo "(512)" | bc`
tmp_free=`/usr/bin/df -m "$tmppath" | /usr/bin/sed -e /Filesystem/d | /usr/bin/awk '{print $3}'`
if [[ $tmp_free -le $total_req ]]
then
chfs -a size=+$(( total_req - tmp_free ))M "$tmppath"
if [[ $? -ne 0 ]];
then
echo "Please make sure $tmppath has around 340MB of free space to download and"
echo "Please make sure $tmppath has around 512MB of free space to download and"
echo "extract files from dnf_bundle."
exit 1
fi
Expand All @@ -137,8 +147,8 @@ fi

# Check if /opt is having enough space to install the packages from dnf_bundle.
# Currently we need around 457MB of free space in /opt filesystem.
typeset -i total_opt=$(echo "(512)" | bc)
opt_free=$(/usr/bin/df -m /opt | sed -e /Filesystem/d | head -1 | awk '{print $3}')
typeset -i total_opt=`echo "(512)" | bc`
opt_free=`/usr/bin/df -m /opt | /usr/bin/sed -e /Filesystem/d | /usr/bin/head -1 | /usr/bin/awk '{print $3}'`
if [[ $opt_free -le $total_opt ]]
then
chfs -a size=+$(( total_opt - opt_free ))M /opt
Expand All @@ -151,23 +161,108 @@ then
fi
fi

# Create a temporary directroy where all downloads should go.
curr_time=`date +%Y%m%d%H%M%S`
mkdir -p $tmppath/dnf-$curr_time
tmppath=`echo $tmppath/dnf-$curr_time`
cd $tmppath



if [[ $aix_715_prior -eq 1 ]]
then
echo "Attempting download of dnf_bundle_aix_71_72.tar ..."
username="anonymous"
userpassword="anonymous"

/usr/bin/expect <<DNFEOF
log_user 0
set timeout -1
spawn ftp -s public.dhe.ibm.com
expect "Name (public.dhe.ibm.com:*): "
send "$username\r"
expect "Password:"
send "$userpassword\r"
expect "ftp>"
send "lcd $tmppath\r"
expect "ftp>"
send "bin\r"
expect "ftp>"
send "passive\r"
expect "ftp>"
send "cd aix/freeSoftware/aixtoolbox/ezinstall/ppc\r"
expect "ftp>"
send "get dnf_bundle_aix_71_72.tar\r"
expect "ftp>"
send "bye\r"
expect eof
DNFEOF
if [[ ! -e dnf_bundle_aix_71_72.tar ]]
then
echo "Failed to download dnf_bundle_aix_71_72.tar."
cd - >/dev/null 2>&1
rm -rf $tmppath
exit 1
fi
elif [[ $aix_730_plus -eq 1 ]]
then
echo "Attempting download of dnf_bundle_aix_73.tar ..."
export PERL_LWP_SSL_VERIFY_HOSTNAME=0
LDR_CNTRL=MAXDATA=0x80000000@DSA /usr/opt/perl5/bin/lwp-download https://public.dhe.ibm.com/aix/freeSoftware/aixtoolbox/ezinstall/ppc/dnf_bundle_aix_73.tar
if [[ $? -ne 0 ]]
then
echo "Failed to download dnf_bundle_aix_73.tar"
cd - >/dev/null 2>&1
rm -rf $tmppath
exit 1
fi

# Do this once rpm.rte for 730 is available on AIX Toolbox.
#/usr/opt/perl5/bin/lwp-download http://public.dhe.ibm.com/aix/freeSoftware/aixtoolbox/INSTALLP/ppc/rpm.rte
#if [[ $? -ne 0 ]]
#then
# echo "Failed to download rpm.rte"
# exit 1
#fi
else
echo "Attempting download of dnf_bundle_aix_71_72.tar ..."
LDR_CNTRL=MAXDATA=0x80000000@DSA /usr/opt/perl5/bin/lwp-download https://public.dhe.ibm.com/aix/freeSoftware/aixtoolbox/ezinstall/ppc/dnf_bundle_aix_71_72.tar
if [[ $? -ne 0 ]]
then
echo "Failed to download dnf_bundle_aix_71_72.tar"
cd - >/dev/null 2>&1
rm -rf $tmppath
exit 1
fi
#/usr/opt/perl5/bin/lwp-download http://public.dhe.ibm.com/aix/freeSoftware/aixtoolbox/INSTALLP/ppc/rpm.rte
# if [[ $? -ne 0 ]]
# then
# echo "Failed to download rpm.rte"
# exit 1
# elif [[ -e rpm.rte.txt ]]
# then
# /usr/bin/mv rpm.rte.txt rpm.rte
# fi
fi
#end of perl download

if [[ $aix_730_plus -eq 1 ]]
then
printf "\nExtracting dnf_bundle_aix_73.tar ..."
tar -xvf dnf_bundle_aix_73.tar
echo "\nExtracting dnf_bundle_aix_73.tar ..."
/usr/bin/tar -xvf dnf_bundle_aix_73.tar
else
printf "\nExtracting dnf_bundle_aix_71_72.tar ..."
tar -xvf dnf_bundle_aix_71_72.tar
echo "\nExtracting dnf_bundle_aix_71_72.tar ..."
/usr/bin/tar -xvf dnf_bundle_aix_71_72.tar
fi

./install_dnf.sh "$arg" $yum4 $yum3_instd 2
if [[ $? -eq 0 ]]
then
cd - >/dev/null 2>&1
rm -rf $tmppath
exit 0
else
elif [[ $? -ne 0 ]]
then
echo "You can try installing the downloaded dnf packages from $tmppath manually."
exit 1
fi
Loading

0 comments on commit 7f71bf5

Please sign in to comment.