4 # shellcheck disable=SC1091
6 # shellcheck disable=SC1091
9 # Generate user ssh key
10 if [ ! -f "$HOME/.ssh/id_rsa.pub" ]; then
11 ssh-keygen -f ~/.ssh/id_rsa -P ""
14 # root needs a private key to talk to libvirt
15 # See tripleo-quickstart-config/roles/virtbmc/tasks/configure-vbmc.yml
16 if sudo [ ! -f /root/.ssh/id_rsa_virt_power ]; then
17 sudo ssh-keygen -f /root/.ssh/id_rsa_virt_power -P ""
18 sudo cat /root/.ssh/id_rsa_virt_power.pub | sudo tee -a /root/.ssh/authorized_keys
21 ANSIBLE_FORCE_COLOR=true ansible-playbook \
22 -e "working_dir=$WORKING_DIR" \
23 -e "num_masters=$NUM_MASTERS" \
24 -e "num_workers=$NUM_WORKERS" \
25 -e "extradisks=$VM_EXTRADISKS" \
26 -e "virthost=$HOSTNAME" \
27 -e "platform=$NODES_PLATFORM" \
28 -e "manage_baremetal=$MANAGE_BR_BRIDGE" \
29 -i vm-setup/inventory.ini \
30 -b -vvv vm-setup/setup-playbook.yml
32 # Allow local non-root-user access to libvirt
33 # Restart libvirtd service to get the new group membership loaded
34 if ! id "$USER" | grep -q libvirt; then
35 sudo usermod -a -G "libvirt" "$USER"
36 sudo systemctl restart libvirtd
38 # Usually virt-manager/virt-install creates this: https://www.redhat.com/archives/libvir-list/2008-August/msg00179.html
39 if ! virsh pool-uuid default > /dev/null 2>&1 ; then
40 virsh pool-define /dev/stdin <<EOF
44 <path>/var/lib/libvirt/images</path>
48 virsh pool-start default
49 virsh pool-autostart default
52 if [[ $OS == ubuntu ]]; then
53 # source ubuntu_bridge_network_configuration.sh
54 # shellcheck disable=SC1091
55 source ubuntu_bridge_network_configuration.sh
56 # shellcheck disable=SC1091
57 source disable_apparmor_driver_libvirtd.sh
59 if [ "$MANAGE_PRO_BRIDGE" == "y" ]; then
60 # Adding an IP address in the libvirt definition for this network results in
61 # dnsmasq being run, we don't want that as we have our own dnsmasq, so set
63 if [ ! -e /etc/sysconfig/network-scripts/ifcfg-provisioning ] ; then
64 echo -e "DEVICE=provisioning\nTYPE=Bridge\nONBOOT=yes\nNM_CONTROLLED=no\nBOOTPROTO=static\nIPADDR=172.22.0.1\nNETMASK=255.255.255.0" | sudo dd of=/etc/sysconfig/network-scripts/ifcfg-provisioning
66 sudo ifdown provisioning || true
67 sudo ifup provisioning
69 # Need to pass the provision interface for bare metal
70 if [ "$PRO_IF" ]; then
71 echo -e "DEVICE=$PRO_IF\nTYPE=Ethernet\nONBOOT=yes\nNM_CONTROLLED=no\nBRIDGE=provisioning" | sudo dd of="/etc/sysconfig/network-scripts/ifcfg-$PRO_IF"
72 sudo ifdown "$PRO_IF" || true
77 if [ "$MANAGE_INT_BRIDGE" == "y" ]; then
78 # Create the baremetal bridge
79 if [ ! -e /etc/sysconfig/network-scripts/ifcfg-baremetal ] ; then
80 echo -e "DEVICE=baremetal\nTYPE=Bridge\nONBOOT=yes\nNM_CONTROLLED=no" | sudo dd of=/etc/sysconfig/network-scripts/ifcfg-baremetal
82 sudo ifdown baremetal || true
85 # Add the internal interface to it if requests, this may also be the interface providing
86 # external access so we need to make sure we maintain dhcp config if its available
87 if [ "$INT_IF" ]; then
88 echo -e "DEVICE=$INT_IF\nTYPE=Ethernet\nONBOOT=yes\nNM_CONTROLLED=no\nBRIDGE=baremetal" | sudo dd of="/etc/sysconfig/network-scripts/ifcfg-$INT_IF"
89 if sudo nmap --script broadcast-dhcp-discover -e "$INT_IF" | grep "IP Offered" ; then
90 echo -e "\nBOOTPROTO=dhcp\n" | sudo tee -a /etc/sysconfig/network-scripts/ifcfg-baremetal
91 sudo systemctl restart network
93 sudo systemctl restart network
98 # restart the libvirt network so it applies an ip to the bridge
99 if [ "$MANAGE_BR_BRIDGE" == "y" ] ; then
100 sudo virsh net-destroy baremetal
101 sudo virsh net-start baremetal
102 if [ "$INT_IF" ]; then #Need to bring UP the NIC after destroying the libvirt network
108 # Add firewall rules to ensure the IPA ramdisk can reach httpd, Ironic and the Inspector API on the host
109 for port in 80 5050 6385 ; do
110 if ! sudo iptables -C INPUT -i provisioning -p tcp -m tcp --dport $port -j ACCEPT > /dev/null 2>&1; then
111 sudo iptables -I INPUT -i provisioning -p tcp -m tcp --dport $port -j ACCEPT
115 # Allow ipmi to the virtual bmc processes that we just started
116 if ! sudo iptables -C INPUT -i baremetal -p udp -m udp --dport 6230:6235 -j ACCEPT 2>/dev/null ; then
117 sudo iptables -I INPUT -i baremetal -p udp -m udp --dport 6230:6235 -j ACCEPT
120 #Allow access to dhcp and tftp server for pxeboot
121 for port in 67 69 ; do
122 if ! sudo iptables -C INPUT -i provisioning -p udp --dport $port -j ACCEPT 2>/dev/null ; then
123 sudo iptables -I INPUT -i provisioning -p udp --dport $port -j ACCEPT
127 # Need to route traffic from the provisioning host.
128 if [ "$EXT_IF" ]; then
129 sudo iptables -t nat -A POSTROUTING --out-interface "$EXT_IF" -j MASQUERADE
130 sudo iptables -A FORWARD --in-interface baremetal -j ACCEPT
133 # Switch NetworkManager to internal DNS
135 if [[ "$MANAGE_BR_BRIDGE" == "y" && $OS == "centos" ]] ; then
136 sudo mkdir -p /etc/NetworkManager/conf.d/
137 sudo crudini --set /etc/NetworkManager/conf.d/dnsmasq.conf main dns dnsmasq
138 if [ "$ADDN_DNS" ] ; then
139 echo "server=$ADDN_DNS" | sudo tee /etc/NetworkManager/dnsmasq.d/upstream.conf
141 if systemctl is-active --quiet NetworkManager; then
142 sudo systemctl reload NetworkManager
144 sudo systemctl restart NetworkManager
148 mkdir -p "$IRONIC_DATA_DIR/html/images"
149 pushd "$IRONIC_DATA_DIR/html/images"
150 if [ ! -f ironic-python-agent.initramfs ]; then
151 curl --insecure --compressed -L https://images.rdoproject.org/master/rdo_trunk/current-tripleo-rdo/ironic-python-agent.tar | tar -xf -
153 BM_IMAGE=${BM_IMAGE:-"bionic-server-cloudimg-amd64.img"}
154 BM_IMAGE_URL=${BM_IMAGE_URL:-"https://cloud-images.ubuntu.com/bionic/current/bionic-server-cloudimg-amd64.img"}
155 if [ ! -f ${BM_IMAGE} ] ; then
156 curl -o ${BM_IMAGE} --insecure --compressed -O -L ${BM_IMAGE_URL}
157 md5sum ${BM_IMAGE} | awk '{print $1}' > ${BM_IMAGE}.md5sum
161 for IMAGE_VAR in IRONIC_IMAGE IRONIC_INSPECTOR_IMAGE ; do
163 sudo "${CONTAINER_RUNTIME}" pull "$IMAGE"
166 for name in ironic ironic-inspector dnsmasq httpd mariadb; do
167 sudo "${CONTAINER_RUNTIME}" ps | grep -w "$name$" && sudo "${CONTAINER_RUNTIME}" kill $name
168 sudo "${CONTAINER_RUNTIME}" ps --all | grep -w "$name$" && sudo "${CONTAINER_RUNTIME}" rm $name -f
171 # set password for mariadb
172 mariadb_password="$(echo "$(date;hostname)"|sha256sum |cut -c-20)"
175 if [[ "${CONTAINER_RUNTIME}" == "podman" ]]; then
176 # Remove existing pod
177 if sudo "${CONTAINER_RUNTIME}" pod exists ironic-pod ; then
178 sudo "${CONTAINER_RUNTIME}" pod rm ironic-pod -f
181 sudo "${CONTAINER_RUNTIME}" pod create -n ironic-pod
182 POD_NAME="--pod ironic-pod"
187 mkdir -p "$IRONIC_DATA_DIR"
189 # Start dnsmasq, http, mariadb, and ironic containers using same image
190 sudo "${CONTAINER_RUNTIME}" run -d --net host --privileged --name dnsmasq ${POD_NAME} \
191 -v "$IRONIC_DATA_DIR":/shared --entrypoint /bin/rundnsmasq "${IRONIC_IMAGE}"
193 sudo "${CONTAINER_RUNTIME}" run -d --net host --privileged --name httpd ${POD_NAME} \
194 -v "$IRONIC_DATA_DIR":/shared --entrypoint /bin/runhttpd "${IRONIC_IMAGE}"
196 sudo "${CONTAINER_RUNTIME}" run -d --net host --privileged --name mariadb ${POD_NAME} \
197 -v "$IRONIC_DATA_DIR":/shared --entrypoint /bin/runmariadb \
198 --env MARIADB_PASSWORD="$mariadb_password" "${IRONIC_IMAGE}"
200 sudo "${CONTAINER_RUNTIME}" run -d --net host --privileged --name ironic ${POD_NAME} \
201 --env MARIADB_PASSWORD="$mariadb_password" \
202 -v "$IRONIC_DATA_DIR":/shared "${IRONIC_IMAGE}"
204 # Start Ironic Inspector
205 sudo "${CONTAINER_RUNTIME}" run -d --net host --privileged --name ironic-inspector ${POD_NAME} "${IRONIC_INSPECTOR_IMAGE}"