86 lines
3.3 KiB
YAML
86 lines
3.3 KiB
YAML
---
|
|
- name: Bootstrap Ubuntu System
|
|
vars:
|
|
# ubuntu = latest non-LTS, ubuntu-lts = latest LTS
|
|
bootstrap_ubuntu_release_map:
|
|
ubuntu: questing
|
|
ubuntu-lts: resolute
|
|
bootstrap_ubuntu_release: "{{ bootstrap_ubuntu_release_map[os] | default('resolute') }}"
|
|
_config: "{{ lookup('vars', bootstrap_var_key) }}"
|
|
bootstrap_ubuntu_base_csv: "{{ (['ca-certificates'] + _config.base) | unique | join(',') }}"
|
|
bootstrap_ubuntu_extra_args: >-
|
|
{{
|
|
((_config.extra | default([])) + (_config.conditional | default([])))
|
|
| reject('equalto', '')
|
|
| join(' ')
|
|
}}
|
|
block:
|
|
- name: Validate Ubuntu package configuration
|
|
ansible.builtin.assert:
|
|
that:
|
|
- _config is mapping
|
|
- _config.base is sequence
|
|
- _config.extra is sequence
|
|
fail_msg: "{{ bootstrap_var_key }} must be a dict with base/extra/conditional keys."
|
|
quiet: true
|
|
|
|
- name: Check for a debootstrap script for the target release
|
|
ansible.builtin.stat:
|
|
path: "/usr/share/debootstrap/scripts/{{ bootstrap_ubuntu_release }}"
|
|
register: bootstrap_ubuntu_script
|
|
|
|
- name: Symlink a missing debootstrap script to the ubuntu base
|
|
ansible.builtin.file:
|
|
src: gutsy
|
|
dest: "/usr/share/debootstrap/scripts/{{ bootstrap_ubuntu_release }}"
|
|
state: link
|
|
when: not bootstrap_ubuntu_script.stat.exists
|
|
|
|
- name: Install Ubuntu base system
|
|
ansible.builtin.command: >-
|
|
debootstrap
|
|
--keyring=/usr/share/keyrings/ubuntu-archive-keyring.gpg
|
|
--include={{ bootstrap_ubuntu_base_csv }}
|
|
{{ bootstrap_ubuntu_release }} /mnt
|
|
{{ system_cfg.content.url }}
|
|
environment:
|
|
http_proxy: "{{ system_cfg.content.proxy }}"
|
|
https_proxy: "{{ system_cfg.content.proxy }}"
|
|
register: bootstrap_ubuntu_base_result
|
|
changed_when: bootstrap_ubuntu_base_result.rc == 0
|
|
|
|
- name: Write bootstrap sources.list
|
|
ansible.builtin.template:
|
|
src: ubuntu.sources.list.j2
|
|
dest: /mnt/etc/apt/sources.list
|
|
mode: "0644"
|
|
|
|
- name: Configure apt performance tuning
|
|
ansible.builtin.copy:
|
|
dest: /mnt/etc/apt/apt.conf.d/99performance
|
|
content: |
|
|
Acquire::Retries "3";
|
|
Acquire::http::Pipeline-Depth "10";
|
|
APT::Install-Recommends "false";
|
|
{% if system_cfg.content.proxy | length > 0 %}
|
|
Acquire::http::Proxy "{{ system_cfg.content.proxy }}";
|
|
Acquire::https::Proxy "{{ system_cfg.content.proxy }}";
|
|
{% endif %}
|
|
mode: "0644"
|
|
|
|
- name: Update package lists
|
|
ansible.builtin.command: "{{ chroot_command }} apt update"
|
|
register: bootstrap_ubuntu_update_result
|
|
changed_when: bootstrap_ubuntu_update_result.rc == 0
|
|
|
|
- name: Upgrade all packages to latest versions
|
|
ansible.builtin.command: "{{ chroot_command }} apt full-upgrade -y"
|
|
register: bootstrap_ubuntu_upgrade_result
|
|
changed_when: "'0 upgraded' not in bootstrap_ubuntu_upgrade_result.stdout"
|
|
|
|
- name: Install extra packages
|
|
when: bootstrap_ubuntu_extra_args | trim | length > 0
|
|
ansible.builtin.command: "{{ chroot_command }} apt install -y {{ bootstrap_ubuntu_extra_args }}"
|
|
register: bootstrap_ubuntu_extra_result
|
|
changed_when: bootstrap_ubuntu_extra_result.rc == 0
|