1 #!/usr/bin/env ansible-playbook
2 # Copyright (C) The Arvados Authors. All rights reserved.
4 # SPDX-License-Identifier: Apache-2.0
6 - name: Load Arvados configuration
9 - name: Load Arvados configuration file
10 delegate_to: localhost
11 ansible.builtin.include_vars:
13 file: "{{ arvados_config_file }}"
14 - name: Load Arvados cluster configuration
15 ansible.builtin.set_fact:
16 arvados_cluster: "{{ arvados_config.Clusters[arvados_cluster_id] }}"
17 failed_when: arvados_cluster is undefined
18 - name: Get Crunch dispatch public key
19 when: arvados_cluster.Containers.DispatchPrivateKey is defined and arvados_cluster.Containers.DispatchPrivateKey is truthy
20 delegate_to: localhost
22 # `ssh-keygen` supports reading stdin for some operations with `-f -`,
23 # but `-y` is not one of those operations as of April 2025.
24 # We MUST have the dispatch private key in a file with correct
25 # permissions for `ssh-keygen -y -f` to read.
26 - name: Prepare tempfile for dispatch private key
27 ansible.builtin.tempfile:
29 register: key_tempfile
31 # Try to parse DispatchPrivateKey as a URL.
32 # If it's recognized as a file: URL, copy that path to the tempfile.
33 # Otherwise, expect it's the private key,
34 # and write that content directly to the tempfile.
35 - name: Save dispatch private key to tempfile
37 key_url: "{{ arvados_cluster.Containers.DispatchPrivateKey | urlsplit }}"
39 src: "{{ key_url.path if key_url.scheme == 'file' else omit }}"
40 content: "{{ arvados_cluster.Containers.DispatchPrivateKey|regex_replace('\\n?$', '\\n') if key_url.scheme != 'file' else omit }}"
41 dest: "{{ key_tempfile.path }}"
44 - name: Derive dispatch public key
45 ansible.builtin.command:
50 - "{{ key_tempfile.path }}"
51 register: compute_dispatch_ssh_keygen
54 - name: Remove dispatch private key tempfile
55 when: key_tempfile is defined
57 path: "{{ key_tempfile.path }}"
60 - name: Set up compute node base distribution
61 # `default` is the name that the Packer Ansible plugin assigns to the
62 # instance used to create the image.
65 - name: Bootstrap packages required for Ansible
67 ansible.builtin.raw: "apt-get -o DPkg::Lock::Timeout=300 -qy {{ item }}"
70 - install gnupg python3-apt python3-debian xz-utils
75 - name: List linux-image packages pre-upgrade
76 ansible.builtin.shell:
78 dpkg-query --list "linux-image-[1-9]*-$(dpkg --print-architecture)" |
79 awk '($1 ~ /^[irp][HUFWti]$/) { print $2; }'
80 register: linux_image_preupgrade
81 - name: Upgrade packages
86 - name: Remove unwanted packages
93 - name: List linux-image packages post-upgrade
94 ansible.builtin.shell:
96 dpkg-query --list "linux-image-[1-9]*-$(dpkg --print-architecture)" |
97 awk '($1 ~ /^[irp][HUFWti]$/) { print $2; }'
98 register: linux_image_postupgrade
99 # Rebooting now accomplishes a few things: it means we can remove the old
100 # linux-image afterward, and the `ansible_kernel` fact will reflect what
101 # the image will boot into when used.
102 - name: Reboot into new kernel
103 when: "linux_image_preupgrade.stdout != linux_image_postupgrade.stdout"
105 ansible.builtin.reboot: {}
106 - name: Remove old kernel(s)
107 when: "linux_image_preupgrade.stdout != linux_image_postupgrade.stdout"
112 name: "{{ linux_image_preupgrade.stdout_lines }}"
115 ansible.builtin.debug:
116 msg: Skipping apt update handler before an apt upgrade
119 - name: Install compute node software
122 - ansible.builtin.include_role:
123 name: compute_encrypt_tmp
124 - ansible.builtin.include_role:
125 name: arvados_compute
126 - ansible.builtin.include_role:
128 when: "arvados_cluster.Containers.RuntimeEngine == 'docker'"
129 - ansible.builtin.include_role:
132 - name: Configure DNS
134 ansible.builtin.lineinfile:
135 path: /etc/dhcp/dhclient.conf
136 regexp: "^[# ]*prepend +domain-name-servers "
137 line: "prepend domain-name-servers {{ dns_resolver }};"
138 when: dns_resolver is defined
140 - name: Clean apt packages