openstack-ansible-nspawn_hosts/templates/prep-scripts/nspawn_ubuntu_prep.sh.j2

59 lines
1.7 KiB
Django/Jinja

#!/usr/bin/env bash
# Copyright 2018, Rackspace US, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# {{ ansible_managed }}
set -e
{{ nspawn_cache_prep_pre_commands }}
mkdir -p /etc/ansible/facts.d
mkdir -p /var/backup
if [ -a "/etc/resolv.conf" ]; then
mv /etc/resolv.conf /etc/resolv.conf.org
fi
{% for resolver in nspawn_cache_prep_dns %}
echo "nameserver {{ resolver }}" >> /etc/resolv.conf
{% endfor %}
# Update base distribution
export DEBIAN_FRONTEND=noninteractive
apt-get remove -y --purge snap* nspawn* lxd* || true
apt-get update
apt-get install -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" --force-yes {{ nspawn_container_distro_packages | join(' ') }}
apt-get upgrade -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" --force-yes
rm -f /usr/bin/python || true
ln -s /usr/bin/python2.7 /usr/bin/python
mkdir -p /root/.ssh
chmod 700 /root/.ssh
userdel --force --remove ubuntu || true
chage -I -1 -d -1 -m 0 -M 99999 -E -1 root
if [ -a /etc/resolv.conf.org ]; then
mv /etc/resolv.conf.org /etc/resolv.conf
else
rm -f /etc/resolv.conf
fi
systemctl enable systemd-networkd.service
{{ nspawn_cache_prep_post_commands }}