Skip to content

Fix ansible_user undefined error in GKE and AKS Terraform tasks#189

Open
ssimpson89 wants to merge 1 commit intoctrliq:mainfrom
ssimpson89:fix/gke-aks-ansible-user-undefined
Open

Fix ansible_user undefined error in GKE and AKS Terraform tasks#189
ssimpson89 wants to merge 1 commit intoctrliq:mainfrom
ssimpson89:fix/gke-aks-ansible-user-undefined

Conversation

@ssimpson89
Copy link
Copy Markdown
Contributor

When ansible_connection=local is used, ansible_user is never set and referencing it causes an immediate failure. Replace /home/{{ ansible_user }} with {{ ansible_env.HOME }} which resolves correctly in local connections.

When ansible_connection=local is used, ansible_user is never set and
referencing it causes an immediate failure. Replace /home/{{ ansible_user }}
with {{ ansible_env.HOME }} which resolves correctly in local connections.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings April 1, 2026 14:27
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes failures in the k8s setup role when running Terraform provisioning with ansible_connection=local by avoiding a hard dependency on ansible_user for computing a home directory path.

Changes:

  • Update GKE Terraform variables to set home_dir from ansible_env.HOME instead of /home/{{ ansible_user }}.
  • Update AKS Terraform variables to set home_dir from ansible_env.HOME instead of /home/{{ ansible_user }}.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
playbooks/roles/k8s_setup/tasks/k8s_setup_gke.yml Changes Terraform home_dir variable to use ansible_env.HOME.
playbooks/roles/k8s_setup/tasks/k8s_setup_aks.yml Changes Terraform home_dir variable to use ansible_env.HOME.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

state: present
variables:
home_dir: "/home/{{ ansible_user}}"
home_dir: "{{ ansible_env.HOME }}"
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ansible_env.HOME will be undefined here unless the env fact subset is gathered. This role/play disables full fact gathering (playbooks/kubernetes_setup.yml sets gather_facts: no), and the only setup call in this task file gathers date_time only, so this change can still fail with an undefined-variable error. Consider using lookup('env', 'HOME') (works without facts for local connections) or expand the ansible.builtin.setup gather_subset to include env before referencing ansible_env.HOME.

Suggested change
home_dir: "{{ ansible_env.HOME }}"
home_dir: "{{ lookup('env', 'HOME') }}"

Copilot uses AI. Check for mistakes.
state: present
variables:
home_dir: "/home/{{ ansible_user}}"
home_dir: "{{ ansible_env.HOME }}"
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ansible_env.HOME is only available when environment facts are gathered. This play/role disables normal fact gathering and the setup task in this file only gathers date_time, so ansible_env.HOME may be undefined and cause the same immediate failure you’re trying to avoid. Use lookup('env', 'HOME') or adjust the setup/fact gathering to include the env subset before using ansible_env.HOME.

Suggested change
home_dir: "{{ ansible_env.HOME }}"
home_dir: "{{ lookup('env', 'HOME') }}"

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants