1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: Apache-2.0
5 # This state tries to query the controller using the parameters set in
6 # the `arvados.cluster.resources.virtual_machines` pillar, to get the
7 # ARVADOS_VIRTUAL_MACHINE_UUID for the host and configure the arvados login-sync cron
8 # as described in https://doc.arvados.org/main/install/install-shell-server.html
10 {%- set curr_tpldir = tpldir %}
11 {%- set tpldir = 'arvados' %}
12 {%- from "arvados/map.jinja" import arvados with context %}
13 {%- from "arvados/libtofs.jinja" import files_switch with context %}
14 {%- set tpldir = curr_tpldir %}
16 {%- set virtual_machines = arvados.cluster.resources.virtual_machines | default({}) %}
17 {%- set api_token = arvados.cluster.tokens.system_root | yaml_encode %}
18 {%- set api_host = arvados.cluster.Services.Controller.ExternalURL | regex_replace('^http(s?)://', '', ignorecase=true) %}
20 extra_shell_cron_add_login_sync_add_jq_pkg_installed:
24 {%- for vm, vm_params in virtual_machines.items() %}
25 {%- set vm_name = vm_params.name | default(vm) %}
27 # Check if any of the specified virtual_machines parameters corresponds to this instance
28 # It should be an error if we get more than one occurrence
29 {%- if vm_name in [grains['id'], grains['host'], grains['fqdn'], grains['nodename']] or
30 vm_params.backend in [grains['id'], grains['host'], grains['fqdn'], grains['nodename']] +
31 grains['ipv4'] + grains['ipv6'] %}
33 # We need to query the VM UUID
34 {%- set cmd_query_vm_uuid = 'arv --short virtual_machine list' ~
35 ' --filters \'[["hostname", "=", "' ~ vm_name ~ '"]]\''
38 extra_shell_cron_add_login_sync_add_{{ vm }}_get_vm_uuid_cmd_run:
41 - ARVADOS_API_TOKEN: {{ api_token }}
42 - ARVADOS_API_HOST: {{ api_host }}
43 - ARVADOS_API_HOST_INSECURE: {{ arvados.cluster.tls.insecure | default(false) }}
44 - name: {{ cmd_query_vm_uuid }} | head -1 | tee /tmp/vm_uuid_{{ vm }}
46 - /bin/grep -qE "[a-z0-9]{5}-2x53u-[a-z0-9]{15}" /tmp/vm_uuid_{{ vm }}
48 - gem: arvados-shell-package-install-gem-arvados-cli-installed
50 extra_shell_cron_add_login_sync_add_{{ vm }}_arvados_api_host_cron_env_present:
52 - name: ARVADOS_API_HOST
53 - value: {{ api_host }}
55 - /bin/grep -qE "[a-z0-9]{5}-2x53u-[a-z0-9]{15}" /tmp/vm_uuid_{{ vm }}
57 extra_shell_cron_add_login_sync_add_{{ vm }}_arvados_api_token_cron_env_present:
59 - name: ARVADOS_API_TOKEN
60 - value: {{ api_token }}
62 - /bin/grep -qE "[a-z0-9]{5}-2x53u-[a-z0-9]{15}" /tmp/vm_uuid_{{ vm }}
64 extra_shell_cron_add_login_sync_add_{{ vm }}_arvados_api_host_insecure_cron_env_present:
66 - name: ARVADOS_API_HOST_INSECURE
67 - value: {{ arvados.cluster.tls.insecure | default(false) }}
69 - /bin/grep -qE "[a-z0-9]{5}-2x53u-[a-z0-9]{15}" /tmp/vm_uuid_{{ vm }}
71 extra_shell_cron_add_login_sync_add_{{ vm }}_arvados_virtual_machine_uuid_cron_env_present:
73 - name: ARVADOS_VIRTUAL_MACHINE_UUID
74 - value: __slot__:salt:cmd.run("cat /tmp/vm_uuid_{{ vm }}")
76 - /bin/grep -qE "[a-z0-9]{5}-2x53u-[a-z0-9]{15}" /tmp/vm_uuid_{{ vm }}
78 extra_shell_cron_add_login_sync_add_{{ vm }}_arvados_login_sync_cron_present:
80 - name: /usr/local/bin/arvados-login-sync
83 - /bin/grep -qE "[a-z0-9]{5}-2x53u-[a-z0-9]{15}" /tmp/vm_uuid_{{ vm }}