diff --git a/llm-server/llm/ansible/roles/ai_environment_switch/tasks/main.yml b/llm-server/llm/ansible/roles/ai_environment_switch/tasks/main.yml index d57c5c4..389d610 100644 --- a/llm-server/llm/ansible/roles/ai_environment_switch/tasks/main.yml +++ b/llm-server/llm/ansible/roles/ai_environment_switch/tasks/main.yml @@ -24,24 +24,38 @@ - ai_environment_health_interval | int > 0 fail_msg: AI environment switch declarations are incomplete or ambiguous. -- name: Verify every environment account exists on the host - ansible.builtin.getent: - database: passwd - key: "{{ item.value.account }}" +- name: Read every environment account database entry + ansible.builtin.command: + argv: + - /usr/bin/getent + - passwd + - "{{ item.value.account }}" + register: ai_environment_account_entries + changed_when: false + failed_when: false loop: "{{ ai_environment_definitions | dict2items }}" loop_control: label: "{{ item.value.account }}" -- name: Verify the account UID matches the declaration +- name: Verify the accounts exist with the declared UID ansible.builtin.assert: that: - - getent_passwd[item.value.account][1] | int == item.value.uid | int + - entry.stdout is defined + - entry.stdout | length > 0 + - entry.stdout.split(':')[2] | int == item.value.uid | int fail_msg: >- - UID mismatch for {{ item.value.account }}: declared {{ item.value.uid }}, - host reports {{ getent_passwd[item.value.account][1] }}. + Account {{ item.value.account }} is missing or has UID + {{ entry.stdout.split(':')[2] | default('unset') }} + instead of the declared {{ item.value.uid }}. loop: "{{ ai_environment_definitions | dict2items }}" loop_control: label: "{{ item.value.account }}" + loop_var: item + vars: + entry: >- + {{ ai_environment_account_entries.results + | selectattr('item.value.account', 'equalto', item.value.account) + | first }} - name: Ensure the host configuration directory exists ansible.builtin.file: diff --git a/llm-server/llm/ansible/roles/ai_environment_switch/templates/gnai-environment-switch.sh.j2 b/llm-server/llm/ansible/roles/ai_environment_switch/templates/gnai-environment-switch.sh.j2 index 4c39910..ab687ac 100644 --- a/llm-server/llm/ansible/roles/ai_environment_switch/templates/gnai-environment-switch.sh.j2 +++ b/llm-server/llm/ansible/roles/ai_environment_switch/templates/gnai-environment-switch.sh.j2 @@ -146,7 +146,7 @@ start_active_unit() { switch_to() { # $1 = target environment, $2 = window minutes (optional) - local target="$1" window_minutes="$2" other uid + local target="$1" window_minutes="${2:-}" other uid local active unit refresh_window="" case " $ENVIRONMENTS " in *" $target "*) ;; *)