]> git.arvados.org - arvados.git/blob - tools/ansible/build-compute-image.yml
22127: Merge branch 'main' into 22127-wb2-optimization
[arvados.git] / tools / 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: Load Arvados configuration
7   hosts: default
8   tasks:
9     - name: Load Arvados configuration file
10       delegate_to: localhost
11       ansible.builtin.include_vars:
12         name: arvados_config
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
21       vars:
22         # Try to parse DispatchPrivateKey as a URL.
23         # If it's recognized as a file: URL, pass the path to `ssh-keygen -f`.
24         # Otherwise, expect it's private key content,
25         # and pass it through `ssh-keygen` stdin.
26         key_url: "{{ arvados_cluster.Containers.DispatchPrivateKey | urlsplit }}"
27       ansible.builtin.command:
28         argv: "{{ ['ssh-keygen', '-y'] + (['-f', key_url.path] if key_url.scheme == 'file' else []) }}"
29         stdin: "{{ arvados_cluster.Containers.DispatchPrivateKey if key_url.scheme != 'file' else '' }}"
30       register: compute_dispatch_ssh_keygen
31
32 - name: Build compute node
33   # `default` is the name that the Packer Ansible plugin assigns to the
34   # instance used to create the image.
35   hosts: default
36   become: true
37   tasks:
38     - name: Bootstrap packages required for Ansible
39       ansible.builtin.raw: "apt-get -o DPkg::Lock::Timeout=300 -qy {{ item }}"
40       loop:
41         - update
42         - install gnupg python3-apt python3-debian xz-utils
43     - include_role:
44         name: distro_apt
45     - include_role:
46         name: arvados_apt
47     - name: Upgrade packages
48       ansible.builtin.apt:
49         update_cache: true
50         upgrade: true
51     - name: Remove unwanted packages
52       ansible.builtin.apt:
53         state: absent
54         autoremove: true
55         purge: true
56         name:
57           - unattended-upgrades
58
59     - ansible.builtin.include_role:
60         name: compute_encrypt_tmp
61     - ansible.builtin.include_role:
62         name: arvados_compute
63     - ansible.builtin.include_role:
64         name: compute_docker
65       when: "arvados_cluster.Containers.RuntimeEngine == 'docker'"
66     - ansible.builtin.include_role:
67         name: compute_user
68
69     - name: Configure DNS
70       ansible.builtin.lineinfile:
71         path: /etc/dhcp/dhclient.conf
72         regexp: "^[# ]*prepend +domain-name-servers "
73         line: "prepend domain-name-servers {{ dns_resolver }};"
74       when: dns_resolver is defined
75
76   handlers:
77     - name: apt update
78       ansible.builtin.debug:
79         msg: Skipping apt update handler before an apt upgrade
80         verbosity: 1