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 {%- set sls_config_file = 'arvados.config.file' %}
13 {# from "arvados/map.jinja" import arvados with context #}
14 {%- from "arvados/map.jinja" import arvados with context %}
15 {%- from "arvados/libtofs.jinja" import files_switch with context %}
16 {%- set tpldir = curr_tpldir %}
18 {%- set virtual_machines = arvados.cluster.resources.virtual_machines | default({}) %}
19 {%- set api_token = arvados.cluster.tokens.system_root | yaml_encode %}
20 {%- set api_host = arvados.cluster.Services.Controller.ExternalURL | regex_replace('^http(s?)://', '', ignorecase=true) %}
25 extra_shell_cron_add_login_sync_add_jq_pkg_installed:
29 {%- for vm, vm_params in virtual_machines.items() %}
30 {%- set vm_name = vm_params.name | default(vm) %}
32 # Check if any of the specified virtual_machines parameters corresponds to this instance
33 # It should be an error if we get more than one occurrence
34 {%- if vm_name in [grains['id'], grains['host'], grains['fqdn'], grains['nodename']] or
35 vm_params.backend in [grains['id'], grains['host'], grains['fqdn'], grains['nodename']] +
36 grains['ipv4'] + grains['ipv6'] %}
38 # We need to query the VM UUID
39 {%- set cmd_query_vm_uuid = 'arv --short virtual_machine list' ~
40 ' --filters \'[["hostname", "=", "' ~ vm_name ~ '"]]\''
43 extra_shell_cron_add_login_sync_add_{{ vm }}_get_vm_uuid_cmd_run:
46 - ARVADOS_API_TOKEN: {{ api_token }}
47 - ARVADOS_API_HOST: {{ api_host }}
48 - ARVADOS_API_HOST_INSECURE: {{ arvados.cluster.tls.insecure | default(false) }}
49 - name: {{ cmd_query_vm_uuid }} | head -1 | tee /tmp/vm_uuid_{{ vm }}
51 - /bin/grep -qE "[a-z0-9]{5}-2x53u-[a-z0-9]{15}" /tmp/vm_uuid_{{ vm }}
53 extra_shell_cron_add_login_sync_add_{{ vm }}_arvados_api_host_cron_env_present:
55 - name: ARVADOS_API_HOST
56 - value: {{ api_host }}
58 - /bin/grep -qE "[a-z0-9]{5}-2x53u-[a-z0-9]{15}" /tmp/vm_uuid_{{ vm }}
60 extra_shell_cron_add_login_sync_add_{{ vm }}_arvados_api_token_cron_env_present:
62 - name: ARVADOS_API_TOKEN
63 - value: {{ api_token }}
65 - /bin/grep -qE "[a-z0-9]{5}-2x53u-[a-z0-9]{15}" /tmp/vm_uuid_{{ vm }}
67 extra_shell_cron_add_login_sync_add_{{ vm }}_arvados_api_host_insecure_cron_env_present:
69 - name: ARVADOS_API_HOST_INSECURE
70 - value: {{ arvados.cluster.tls.insecure | default(false) }}
72 - /bin/grep -qE "[a-z0-9]{5}-2x53u-[a-z0-9]{15}" /tmp/vm_uuid_{{ vm }}
74 extra_shell_cron_add_login_sync_add_{{ vm }}_arvados_virtual_machine_uuid_cron_env_present:
76 - name: ARVADOS_VIRTUAL_MACHINE_UUID
77 - value: __slot__:salt:cmd.run("cat /tmp/vm_uuid_{{ vm }}")
79 - /bin/grep -qE "[a-z0-9]{5}-2x53u-[a-z0-9]{15}" /tmp/vm_uuid_{{ vm }}
81 extra_shell_cron_add_login_sync_add_{{ vm }}_arvados_login_sync_cron_present:
83 - name: arvados-login-sync
86 - /bin/grep -qE "[a-z0-9]{5}-2x53u-[a-z0-9]{15}" /tmp/vm_uuid_{{ vm }}