Solved Install package to Installation ISO environment?

Hello.
I'm trying to make custom FreeBSD install on VPS from installation ISO.

All installation steps are available in ansible playbook, but it needs python interpreter installed.

That's how I run sshd there:
Bash:
#!/bin/sh

mkdir /tmp/etc
mount_unionfs /tmp/etc /etc
echo 'ifconfig_vtnet0="123.123.123.123/24"' > /etc/rc.conf.d/network
echo 'defaultrouter="123.123.123.1"' > /etc/rc.conf.d/routing
echo 'nameserver 8.8.8.8' > /etc/resolv.conf
echo 'nameserver 8.8.4.4' >> /etc/resolv.conf
service netif restart
service routing restart
echo "UseDNS no" >> /etc/ssh/sshd_config
echo "PasswordAuthentication yes" >> /etc/ssh/sshd_config
echo "PermitRootLogin yes" >> /etc/ssh/sshd_config
echo MySecretPassw0rd | pw mod user root -h 0
service sshd onestart

Is it possible to install python package in this environment, to run my custom ansible FreeBSD installation playbook?
 
Last edited:
I did it.


#!/bin/sh
ansible -m raw -a 'mount -t tmpfs tmpfs /usr/local' provision
ansible -m raw -a 'mkdir /usr/local/tmp' provision
ansible -m raw -a 'mkdir /usr/local/tmp/repos' provision
ansible -m raw -a 'mount -t unionfs /usr/local/tmp /tmp' provision
ansible -m raw -a 'PKG_DBDIR=/tmp/repos ASSUME_ALWAYS_YES=yes pkg update -fq' provision
ansible -m raw -a 'PKG_DBDIR=/tmp/repos ASSUME_ALWAYS_YES=yes pkg install -y python' provision


That's all, folks.
 
Last edited:
I'll post my result here.
My VPS provider gives access to it's console with Web-based VNC-client, but I want to bootstrap FreeBSD installation environment quickly.
Detecting window id through xprop:
xprop | grep NET_WM_USER_TIME_WINDOW
then click onto Web-browser window with VNC-client.
Let it be window_id=0x1601337
At terminal window (same screen with browser) change directory to ansible-playbook's root, and run: WINDOWID=0x1601337 sh -x ./prerequisites/total.sh
Don't touch keyboard and mouse before
xdotool
comands exhausted.
Wait for playbook complete, unmount ISO through VPS-provider interface, then reboot.

So, the script is:
Bash:
#!/bin/sh
# This is to make xdotool work correctly:
setxkbmap us

echo WindowID is: $WINDOWID
sleep 1
xdotool windowactivate $WINDOWID
# X,Y-coordinates of central widget of Web-based VNC-terminal
xdotool mousemove -window $WINDOWID 1000 500
xdotool click 1
xdotool click 1
xdotool key Return
xdotool sleep 1
xdotool type 'mkdir /tmp/etc'
xdotool key Return
xdotool sleep 1
xdotool type 'mount_unionfs /tmp/etc /etc'
xdotool key Return
xdotool sleep 1
xdotool type 'echo ifconfig_vtnet0="123.123.123.123/24" > /etc/rc.conf.d/network'
xdotool key Return
xdotool sleep 1
xdotool type 'echo defaultrouter="123.123.123.1" > /etc/rc.conf.d/routing'
xdotool key Return
xdotool sleep 1
xdotool type 'echo "nameserver 8.8.8.8" > /etc/resolv.conf'
xdotool key Return
xdotool sleep 1
xdotool type 'echo "nameserver 8.8.4.4" >> /etc/resolv.conf'
xdotool key Return
xdotool sleep 1
xdotool type 'service netif restart'
xdotool key Return
xdotool sleep 2
xdotool type 'service routing restart'
xdotool key Return
xdotool sleep 2
xdotool type 'echo "UseDNS no" >> /etc/ssh/sshd_config'
xdotool key Return
xdotool sleep 1
xdotool type 'echo "PasswordAuthentication yes" >> /etc/ssh/sshd_config'
xdotool key Return
xdotool sleep 1
xdotool type 'echo "PermitRootLogin yes" >> /etc/ssh/sshd_config'
xdotool key Return
xdotool sleep 1
xdotool type 'echo YourVerySecretRootLoginPassword | pw mod user root -h 0'
xdotool key Return
xdotool sleep 1
xdotool type 'service sshd onestart'
xdotool key Return
xdotool sleep 3

# Revert xkbmap to original preferences
setxkbmap -layout 'us,ru(winkeys)' -option 'terminate:ctrl_alt_bksp,grp:caps_toggle,grp_led:scroll'

### Ansible python prerequisites for 'provision' host group
export ANSIBLE_HOST_KEY_CHECKING=False
# Remove old host fingerprint
ssh-keygen -R vpsdomainname.org
ansible -m raw -a 'mount -t tmpfs tmpfs /usr/local' provision
ansible -m raw -a 'mkdir -p /usr/local/tmp/repos' provision
ansible -m raw -a 'mount -t unionfs /usr/local/tmp /tmp' provision
ansible -m raw -a 'PKG_DBDIR=/usr/local/tmp/repos ASSUME_ALWAYS_YES=yes pkg update -fq' provision
ansible -m raw -a 'PKG_DBDIR=/usr/local/tmp/repos ASSUME_ALWAYS_YES=yes pkg install -y python gtar' provision
echo YourVerySecretAnsibleVaultPassword > /tmp/vpska.pass
ansible-playbook playbooks/provision.yml
 
Recent update to make use of inventory variables in shell script:
Bash:
#!/bin/sh

filter_value()
{
cat - | grep "${1}" | cut -d ':' -f 2 | sed -e 's/^ *"//' -e 's/".*$//'
}

setxkbmap us
sleep 1
xdotool windowactivate $WINDOWID
xdotool mousemove -window $WINDOWID 1000 500
xdotool click 1
xdotool click 1
xdotool key Return
xdotool sleep 1
xdotool type 'mkdir /tmp/etc'
xdotool key Return
xdotool sleep 1
xdotool type 'mount_unionfs /tmp/etc /etc'
xdotool key Return
xdotool sleep 1
xdotool type 'hostname '$(ansible all -m debug -a 'msg={{ ansible_host }}' | filter_value msg )
xdotool key Return
xdotool sleep 1
xdotool type 'echo ifconfig_'$(ansible all -m debug -a 'msg={{ extif }}' | filter_value msg )'="'$(ansible all -m debug -a 'msg={{lookup("dig", ansible_host )}}' | filter_value msg )'/'$(ansible all -m debug -a 'msg={{ netmaskbits }}' | filter_value msg )'" > /etc/rc.conf.d/network'
xdotool key Return
xdotool sleep 1
xdotool type 'echo defaultrouter="'$(ansible all -m debug -a 'msg={{ defaultrouter }}' | filter_value msg )'" > /etc/rc.conf.d/routing'
xdotool key Return
xdotool sleep 1
xdotool type 'echo "nameserver '$(ansible all -m debug -a 'msg={{ nameserver }}' | filter_value msg )'" > /etc/resolv.conf'
xdotool key Return
xdotool sleep 1
xdotool type 'service netif restart'
xdotool key Return
xdotool sleep 2
xdotool type 'service routing restart'
xdotool key Return
xdotool sleep 2
xdotool type 'echo "UseDNS no" >> /etc/ssh/sshd_config'
xdotool key Return
xdotool sleep 1
xdotool type 'echo "PasswordAuthentication yes" >> /etc/ssh/sshd_config'
xdotool key Return
xdotool sleep 1
xdotool type 'echo "PermitRootLogin yes" >> /etc/ssh/sshd_config'
xdotool key Return
xdotool sleep 1
xdotool type 'echo '$(ansible all -m debug -a 'msg={{ ansible_password }}' | filter_value msg )' | pw mod user root -h 0'
xdotool key Return
xdotool sleep 1
xdotool type 'service sshd onestart'
xdotool key Return
xdotool sleep 3
setxkbmap -layout 'us,ru(winkeys)' -option 'terminate:ctrl_alt_bksp,grp:caps_toggle,grp_led:scroll'

export ANSIBLE_HOST_KEY_CHECKING=False
ssh-keygen -R $(ansible all -m debug -a 'msg={{  ansible_host }}' | filter_value msg )
ansible -m raw -a 'mount -t tmpfs tmpfs /usr/local' provision
ansible -m raw -a 'mkdir -p /usr/local/tmp/repos' provision
ansible -m raw -a 'mount -t unionfs /usr/local/tmp /tmp' provision
ansible -m raw -a 'PKG_DBDIR=/usr/local/tmp/repos ASSUME_ALWAYS_YES=yes pkg update -fq' provision
ansible -m raw -a 'PKG_DBDIR=/usr/local/tmp/repos ASSUME_ALWAYS_YES=yes pkg install -y python gtar' provision
echo YourVerySecretAnsibleVaultPassword > /tmp/vpska.pass
ansible-playbook playbooks/provision.yml
 
Add sysutils/firstboot-pkgs to your images. There are a number of firstboot-* packages that are useful for this.
Thank you for this nice port, it can be very useful, but the question was how to install packages to installation ISO readonly environment, for disk partitioning and FreeBSD install with external ansible playbook. After reboot into just-installed OS we can use this package or do it with ansible playbook - doesn't matter.
 
You could also build your own release(7) images.
It looks like really ideal, but too labor intensive task. I'll be doomed to make my own image for every FreeBSD release, but having ansible playbook, doing the same thing, I will do only minor task updates in worst case.
 
Does it have to be the ISO? Can you boot the VPS with a memstick image? The memstick images are easier to modify, they are just disk images (mdconfig(8)). Modifying the ISO is a bit cumbersome, you have to 'unpack' it, modify, then rebuild the ISO image.
 
Does it have to be the ISO? Can you boot the VPS with a memstick image? The memstick images are easier to modify, they are just disk images (mdconfig(8)). Modifying the ISO is a bit cumbersome, you have to 'unpack' it, modify, then rebuild the ISO image.
It's a pity, but my VPS provider, and most of them, permit booting just from external ISO %(
 
Back
Top