#cloud-config
hostname: haproxyvdu
password: osm2021
chpasswd: { expire: False }
ssh_pwauth: True

runcmd:
 - ip=$(ifconfig | grep -A 1 "ens4" | tail -1 | cut -d ":" -f 2 | cut -d " " -f 1)
 - sudo -S sed -i "s/ipv4@\(.*:9999\)/ipv4@${ip}\:9999/" /etc/haproxy/haproxy.cfg
 - sudo -S sed -i "/option forwardfor/d" /etc/haproxy/haproxy.cfg
 - sudo -S sed -i "/http\-request set\-header X\-Forwarded-Port \%\[dst\_port\]/d" /etc/haproxy/haproxy.cfg
 - sudo -S sed -i "/http\-request add\-header X\-Forwarded-Proto https if { ssl_fc }/d" /etc/haproxy/haproxy.cfg
 - sudo -S sed -i "/option httpchk HEAD/d" /etc/haproxy/haproxy.cfg
 - sudo -S sed -i "/roundrobin/a\    server node0 192.168.28.2:8080 check" /etc/haproxy/haproxy.cfg
 - sleep 60
 - echo "osm2021" | sudo service haproxy restart

