Michael Beaver 2a70f431cc Update hostname files before multistrap in image-builder
This change adds to the multistrap playbook to ensure that the
hostname files are correct when multistrap installs packages. This
can be an issue when installing packages such as ssmtp. A later step
will override the hosts and hostname files so these changes will be
temporary in the overall build process.

Change-Id: I61124a4e991e4aaedadc9c6ef211b574178fb411
2021-03-23 12:17:28 -05:00

97 lines
3.2 KiB
YAML

- name: "Including any user-defined vars"
include_vars:
file: main.yaml
name: user-vars
- name: "Append any user-defined repos to multistrap list"
set_fact:
repos: "{{ repos + repos_append }}"
when: repos_append is defined
- name: "Append any user-defined pkgs to be installed from default Ubuntu mirrors"
set_fact:
ubuntu_packages: "{{ ubuntu_packages + ubuntu_packages_append }}"
when: ubuntu_packages_append is defined
- name: "ensuring directory {{ rootfs_root }} exists for rootfs"
file:
path: "{{ rootfs_root }}"
state: directory
mode: '0755'
- name: "create temporary directory for multistrap config"
tempfile:
state: directory
suffix: multistrap
register: multistrap_tempdir
- name: "Configure apt with unapproved packages"
template:
src: unapproved-packages.j2
dest: "{{ multistrap_tempdir.path }}/pref.conf"
- name: "write out multistrap config"
template:
src: multistrap.conf.j2
dest: "{{ multistrap_tempdir.path }}/multistrap.conf"
validate: multistrap --simulate -f %s
- name: "install required apt keys manually"
include_tasks: apt-key-install.yaml
loop: "{{ repos }}"
# kdump-tools does not install properly in multistrap environment. This fix allows kdump-tools
# installation to succeed.
- name: "kdump-tools fix - create directory"
shell: |
set -e
mkdir -p "{{ rootfs_root }}/etc/kernel/postinst.d"
- name: "kdump-tools fix - deploy build script"
template:
src: kdump-tools.j2
dest: "{{ rootfs_root }}/etc/kernel/postinst.d/kdump-tools"
mode: '0755'
# kdump-tools deb package will overwrite script without write protection enabled
- name: "kdump-tools fix - lock build script"
shell: |
set -e
chattr +i "{{ rootfs_root }}/etc/kernel/postinst.d/kdump-tools"
# Setting up a dummy hostname required for some packages to properly install
- name: "hostname and hosts | write out hostname file"
shell:
cmd: "echo \"$(hostname)\" > {{rootfs_root}}/etc/hostname"
- name: "hostname and hosts | write out hosts file"
shell:
cmd: "echo \"127.0.0.1 localhost $(hostname)\" > {{rootfs_root}}/etc/hosts"
- name: "Running multistrap"
shell:
cmd: "multistrap -f {{ multistrap_tempdir.path }}/multistrap.conf"
- name: "Set systemd NIC naming"
template:
src: 99-default.link.j2
dest: "{{ rootfs_root }}/etc/systemd/network/99-default.link"
mode: '0644'
- name: "Configure apt with unapproved packages"
template:
src: unapproved-packages.j2
dest: "{{ rootfs_root }}/etc/apt/preferences.d/unapproved-packages.pref"
- name: "Configure apt to remove unapproved packages from update"
ansible.builtin.lineinfile:
path: "{{ rootfs_root }}/etc/apt/apt.conf.d/01autoremove"
insertafter: "multiverse/metapackages"
line: ' "{{ item }}";'
with_items: "{{ unapproved_packages }}"
- name: "Lock sources.list to prevent conflict and duplicates with multistrap repo list"
shell: |
set -e
if [ -f {{ rootfs_root }}/etc/apt/sources.list ] && [ ! -h {{ rootfs_root }}/etc/apt/sources.list ]; then
rm {{ rootfs_root }}/etc/apt/sources.list
ln -s /dev/null {{ rootfs_root }}/etc/apt/sources.list
fi