Skip to content

Commit

Permalink
💚 Fixed error 'ansible_user' is undefined.
Browse files Browse the repository at this point in the history
ERROR:

```
The task includes an option with an undefined variable. The error was: 'ansible_user' is undefined
```

- ref. ansible/ansible#23530
- ref. geerlingguy/drupal-vm#1302
  • Loading branch information
r1cep committed Dec 23, 2020
1 parent 5f97cd5 commit 9905223
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion roles/docker/tasks/001_install-docker-ce.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
- name: Add user to docker group.
user:
#name: "{{ lookup('env', 'user') }}"
name: "{{ ansible_user }}"
name: "{{ ansible_env.SUDO_USER }}"
groups: docker
append: yes

Expand Down
2 changes: 1 addition & 1 deletion roles/user/tasks/001_configure-sudo-for-working-users.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
template:
src: sudoers.j2
#dest: "/etc/sudoers.d/{{ lookup('env', 'USER') }}"
dest: "/etc/sudoers.d/{{ ansible_user }}"
dest: "/etc/sudoers.d/{{ ansible_env.SUDO_USER }}"
owner: root
group: root
mode: 0440
6 changes: 3 additions & 3 deletions roles/user/templates/sudoers.j2
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{{ ansible_user }} ALL=(ALL) NOPASSWD: ALL
Defaults:%{{ ansible_user }} !requiretty
Defaults:%{{ ansible_user }} env_keep += SSH_AUTH_SOCK
{{ ansible_env.SUDO_USER }} ALL=(ALL) NOPASSWD: ALL
Defaults:%{{ ansible_env.SUDO_USER }} !requiretty
Defaults:%{{ ansible_env.SUDO_USER }} env_keep += SSH_AUTH_SOCK

0 comments on commit 9905223

Please sign in to comment.