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