Ivan Berezovskiy | 1d48e48 | 2018-09-21 19:08:31 +0400 | [diff] [blame] | 1 | #cloud-config |
| 2 | output: |
| 3 | all: '| tee -a /var/log/cloud-init-output.log /dev/tty0' |
| 4 | write_files: |
| 5 | - owner: root:root |
| 6 | path: /etc/cloud/mirror_environment |
| 7 | permissions: '0644' |
| 8 | content: | |
Dennis Dmitriev | 8fa33f9 | 2018-10-10 01:13:48 +0300 | [diff] [blame^] | 9 | [ -f /etc/cloud/mirror_environment_override ] && . /etc/cloud/mirror_environment_override |
| 10 | export SALT_MASTER_DEPLOY_IP=${SALT_MASTER_DEPLOY_IP:-"10.1.0.14"} |
| 11 | export APTLY_DEPLOY_IP=${APTLY_DEPLOY_IP:-"10.1.0.14"} |
| 12 | export APTLY_DEPLOY_NETMASK=${APTLY_DEPLOY_NETMASK:-"255.255.0.0"} |
| 13 | export APTLY_MINION_ID=${APTLY_MINION_ID:-"apt01.deploy-name.local"} |
Ivan Berezovskiy | 1d48e48 | 2018-09-21 19:08:31 +0400 | [diff] [blame] | 14 | mirror_config: |
| 15 | - &mirror_config | |
| 16 | function docker_ca_wa(){ |
| 17 | crt="/var/lib/docker/swarm/certificates/swarm-node.crt" |
| 18 | if ! $(openssl x509 -checkend 86400 -noout -in ${crt}); then |
| 19 | echo "WARNING: swarm CA not expired yet.Something wrong with docker" |
| 20 | echo "WARNING: docker CA WA not applied" |
| 21 | exit 1 |
| 22 | fi |
| 23 | echo 'WARNING: re-creating docker stack services!' |
| 24 | |
| 25 | systemctl stop docker || true |
| 26 | rm -rf /var/lib/docker/swarm/* |
| 27 | systemctl restart docker |
| 28 | sleep 5 |
| 29 | docker swarm init --advertise-addr 127.0.0.1 |
| 30 | sleep 5 |
| 31 | for c in docker aptly; do |
| 32 | pushd /etc/docker/compose/${c}/ |
| 33 | retry=5 |
| 34 | i=1 |
| 35 | while [[ $i -lt $retry ]]; do |
| 36 | docker stack deploy --compose-file docker-compose.yml ${c}; |
| 37 | ret=$?; |
| 38 | if [[ $ret -eq 0 ]]; then |
| 39 | echo 'Stack created'; break; |
| 40 | else |
| 41 | echo "Stack creation failed, retrying in 3 seconds.." >&2; |
| 42 | sleep 3; |
| 43 | i=$(( i + 1 )); |
| 44 | fi |
| 45 | if [[ $i -ge $retry ]]; then |
| 46 | echo "Stack creation failed!"; exit 1; |
| 47 | fi |
| 48 | done |
| 49 | popd |
| 50 | sleep 1 |
| 51 | done |
| 52 | } |
| 53 | |
| 54 | . /etc/cloud/mirror_environment |
| 55 | |
| 56 | echo "Configuring network interfaces" |
| 57 | find /etc/network/interfaces.d/ -type f -delete |
| 58 | kill $(pidof /sbin/dhclient) || /bin/true |
| 59 | envsubst < /root/interfaces > /etc/network/interfaces |
| 60 | ip a flush dev ens3 |
| 61 | rm -f /var/run/network/ifstate.ens3 |
| 62 | if [[ $(grep -E '^\ *gateway\ ' /etc/network/interfaces) ]]; then |
| 63 | (ip r s | grep ^default) && ip r d default || /bin/true |
| 64 | fi; |
| 65 | ifup ens3 |
| 66 | |
| 67 | echo "Configuring salt" |
| 68 | rm -f /etc/salt/pki/minion/minion_master.pub |
| 69 | envsubst < /root/minion.conf > /etc/salt/minion.d/minion.conf |
| 70 | service salt-minion restart |
| 71 | |
| 72 | # Check for failed docker-start. |
| 73 | # WA PROD-21676 |
| 74 | if [[ ! $(docker stack ls) ]] ; then |
| 75 | docker_ca_wa |
| 76 | fi |
| 77 | |
| 78 | # Set bootstrap-done flag for future |
| 79 | mkdir -p /var/log/mcp/ |
| 80 | touch /var/log/mcp/.bootstrap_done |
| 81 | runcmd: |
| 82 | - [bash, -cex, *mirror_config] |