22317: Remove compute node image build.sh
[arvados.git] / tools / compute-images / ansible / build-compute-image.yml
1 #!/usr/bin/env ansible-playbook
2 # Copyright (C) The Arvados Authors. All rights reserved.
3 #
4 # SPDX-License-Identifier: Apache-2.0
5
6 - name: Validate build arguments
7   hosts: default
8   tasks:
9     - name: Check compute_authorized_keys is set
10       ansible.builtin.fail:
11         msg: "`compute_authorized_keys` is not set"
12       when: "compute_authorized_keys is not defined"
13       run_once: true
14     - name: Check compute_authorized_keys exists
15       ansible.builtin.fail:
16         msg: "`compute_authorized_keys` file not found: {{ compute_authorized_keys }}"
17       when: "compute_authorized_keys is not exists"
18       run_once: true
19
20 - name: Build compute node
21   # `default` is the name that the Packer Ansible plugin assigns to the
22   # instance used to create the image.
23   hosts: default
24   become: true
25   tasks:
26     - name: Bootstrap packages required for Ansible
27       ansible.builtin.raw: "apt-get -o DPkg::Lock::Timeout=300 -qy {{ item }}"
28       loop:
29         - update
30         - install gnupg python3-apt python3-debian xz-utils
31     - include_role:
32         name: distro_apt
33     - include_role:
34         name: arvados_apt
35     - name: Upgrade packages
36       ansible.builtin.apt:
37         update_cache: true
38         upgrade: true
39     - name: Remove unwanted packages
40       ansible.builtin.apt:
41         state: absent
42         autoremove: true
43         purge: true
44         name:
45           - unattended-upgrades
46
47     - include_role:
48         name: compute_nvidia
49       when: "arvados_compute_nvidia|default(false)|bool"
50     - include_role:
51         name: "compute_{{ arvados_container_engine|default('docker') }}"
52     - include_role:
53         name: compute_encrypt_tmp
54     - include_role:
55         name: compute_user
56
57     - name: Install Arvados FUSE driver
58       ansible.builtin.apt:
59         name: python3-arvados-fuse
60     - name: Configure FUSE
61       ansible.builtin.lineinfile:
62         path: /etc/fuse.conf
63         regexp: "^[# ]*user_allow_other *$"
64         line: user_allow_other
65     - name: Configure locale
66       ansible.builtin.lineinfile:
67         path: /etc/locale.gen
68         regexp: "^[# ]*en_US.UTF-8 +UTF-8 *$"
69         line: en_US.UTF-8 UTF-8
70       notify: locale-gen
71     - name: Configure DNS
72       ansible.builtin.lineinfile:
73         path: /etc/dhcp/dhclient.conf
74         regexp: "^[# ]*prepend +domain-name-servers "
75         line: "prepend domain-name-servers {{ dns_resolver }};"
76       when: dns_resolver is defined
77
78   handlers:
79     - name: apt update
80       ansible.builtin.debug:
81         msg: Skipping apt update handler before an apt upgrade
82         verbosity: 1
83     - name: locale-gen
84       ansible.builtin.command: locale-gen