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"} |
Dennis Dmitriev | 8fa33f9 | 2018-10-10 01:13:48 +0300 | [diff] [blame] | 11 | export APTLY_MINION_ID=${APTLY_MINION_ID:-"apt01.deploy-name.local"} |
azvyagintsev | 829bfd8 | 2018-12-19 12:58:17 +0200 | [diff] [blame] | 12 | |
Ivan Berezovskiy | 1d48e48 | 2018-09-21 19:08:31 +0400 | [diff] [blame] | 13 | mirror_config: |
| 14 | - &mirror_config | |
| 15 | function docker_ca_wa(){ |
| 16 | crt="/var/lib/docker/swarm/certificates/swarm-node.crt" |
Denis Egorenko | 3535d2a | 2020-02-12 15:20:46 +0400 | [diff] [blame] | 17 | if openssl x509 -checkend 86400 -noout -in ${crt}; then |
azvyagintsev | 829bfd8 | 2018-12-19 12:58:17 +0200 | [diff] [blame] | 18 | echo "WARNING: swarm CA not expired yet.Something other wrong with docker" |
Ivan Berezovskiy | 1d48e48 | 2018-09-21 19:08:31 +0400 | [diff] [blame] | 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 | |
Ivan Berezovskiy | 1d48e48 | 2018-09-21 19:08:31 +0400 | [diff] [blame] | 55 | echo "Configuring salt" |
| 56 | rm -f /etc/salt/pki/minion/minion_master.pub |
| 57 | envsubst < /root/minion.conf > /etc/salt/minion.d/minion.conf |
| 58 | service salt-minion restart |
| 59 | |
| 60 | # Check for failed docker-start. |
| 61 | # WA PROD-21676 |
| 62 | if [[ ! $(docker stack ls) ]] ; then |
| 63 | docker_ca_wa |
| 64 | fi |
| 65 | |
| 66 | # Set bootstrap-done flag for future |
| 67 | mkdir -p /var/log/mcp/ |
| 68 | touch /var/log/mcp/.bootstrap_done |
| 69 | runcmd: |
| 70 | - [bash, -cex, *mirror_config] |