Skip to content

Commit

Permalink
Remove default user, use more reliable fact name
Browse files Browse the repository at this point in the history
  • Loading branch information
Encephala committed Dec 19, 2023
1 parent 0aae8fd commit 8b47e14
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 14 deletions.
1 change: 0 additions & 1 deletion ansible.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
[defaults]
inventory = hosts
remote_user = jonathan
roles_path = ./roles/dependencies:./roles/services:~/.ansible/roles
vault_password_file = vault_pass.py

Expand Down
4 changes: 2 additions & 2 deletions roles/provision/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

- name: Update `username` if not root
ansible.builtin.set_fact:
username: "{{ ansible_user }}"
when: ansible_user != "root"
username: "{{ ansible_user_id }}"
when: ansible_user_id != "root"
tags:
- always

Expand Down
2 changes: 1 addition & 1 deletion roles/provision/tasks/ssh_setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

- name: Authorise SSH key
ansible.posix.authorized_key:
user: "{{ ansible_user }}"
user: "{{ ansible_user_id }}"
key: "{{ lookup('ansible.builtin.file', 'ssh/{{ ssh_key_pub }}') }}"

# authorized_key ensures the directory is created
Expand Down
2 changes: 1 addition & 1 deletion roles/services/dockerhost/meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ galaxy_info:
dependencies:
- role: geerlingguy.docker
vars:
docker_users: "{{ ansible_user }}"
docker_users: "{{ ansible_user_id }}"
docker_install_compose: false
8 changes: 4 additions & 4 deletions roles/services/dockerhost/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@
path: "{{ ansible_env.HOME }}/{{ item }}"
state: directory
mode: "0755"
owner: "{{ ansible_user }}"
group: "{{ ansible_user }}"
owner: "{{ ansible_user_id }}"
group: "{{ ansible_user_id }}"
loop: "{{ services }}"

- name: Provide docker-compose files
ansible.builtin.template:
src: "{{ item }}-docker-compose.yml.j2"
dest: "{{ ansible_env.HOME }}/{{ item }}/docker-compose.yml"
owner: "{{ ansible_user }}"
group: "{{ ansible_user }}"
owner: "{{ ansible_user_id }}"
group: "{{ ansible_user_id }}"
mode: "0744"
loop: "{{ services }}"

Expand Down
2 changes: 1 addition & 1 deletion roles/services/npm/meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ galaxy_info:
dependencies:
- role: geerlingguy.docker
vars:
docker_users: "{{ ansible_user }}"
docker_users: "{{ ansible_user_id }}"
docker_install_compose: false
8 changes: 4 additions & 4 deletions roles/services/npm/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
path: "{{ npm_docker_path }}"
state: directory
mode: "0755"
owner: "{{ ansible_user }}"
group: "{{ ansible_user }}"
owner: "{{ ansible_user_id }}"
group: "{{ ansible_user_id }}"

- name: Provide docker-compose file
ansible.builtin.template:
src: docker-compose.j2
dest: "{{ npm_docker_path }}/docker-compose.yml"
owner: "{{ ansible_user }}"
group: "{{ ansible_user }}"
owner: "{{ ansible_user_id }}"
group: "{{ ansible_user_id }}"
mode: "0744"

- name: Ensure container is started
Expand Down

0 comments on commit 8b47e14

Please sign in to comment.