diff --git a/roles/configure_ansible_user/tasks/main.yaml b/roles/configure_ansible_user/tasks/main.yaml index 95322f6..db7c2d1 100644 --- a/roles/configure_ansible_user/tasks/main.yaml +++ b/roles/configure_ansible_user/tasks/main.yaml @@ -21,13 +21,22 @@ become: true # The same commands for Alpine -- name: Update and install packages on Alpine +- name: Install sudo on Alpine when: (ansible_facts['distribution'] == "Alpine") community.general.apk: name: sudo update_cache: true remote_user: ansible +- name: Enable sudo for root and human_admin_user + when: (ansible_facts['distribution'] == "Alpine") + ansible.builtin.copy: + dest: /etc/sudoers.d/80-ansible-created-users + content: | + root ALL=(ALL) ALL:ALL + {{ human_admin_user }} ALL=(ALL) ALL:ALL + remote_user: ansible + ## Creating and setting up the ansible user ## First, create sshusers group to grant ssh access diff --git a/roles/human_admin_user/files/install_omz.sh b/roles/human_admin_user/files/install_omz.sh index e0e5f8d..8a95cff 100644 --- a/roles/human_admin_user/files/install_omz.sh +++ b/roles/human_admin_user/files/install_omz.sh @@ -1,15 +1,17 @@ #!/bin/sh -FILE=/home/$USER/.oh-my-zsh/oh-my-zsh.sh +TARGET_USER=$1 + +FILE=/home/$TARGET_USER/.oh-my-zsh/oh-my-zsh.sh if [ -f "$FILE" ]; then echo "$FILE exists and we not installing ohmyzsh" exit 0 else echo "$FILE does not exist and we install ohmyzsh" - cd /home/max - wget https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh - chmod +x /home/max/install.sh - timeout -s 15 -k 30s 20s /home/max/install.sh --unattendend --keep-zshrc || exit 0 + cd /home/$TARGET_USER + sudo -u $TARGET_USER wget https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh + chmod +x /home/$TARGET_USER/install.sh + sudo -u $TARGET_USER timeout -s 15 -k 30s 20s /home/$TARGET_USER/install.sh --unattendend --keep-zshrc || exit 0 exit 0 fi diff --git a/roles/human_admin_user/tasks/main.yaml b/roles/human_admin_user/tasks/main.yaml index 1608b22..1d15bdb 100644 --- a/roles/human_admin_user/tasks/main.yaml +++ b/roles/human_admin_user/tasks/main.yaml @@ -25,10 +25,9 @@ # WARNING: UNPRIVILEGED USER (not ansible) COMMANDS - name: Install oh my zsh - remote_user: "{{ human_admin_user }}" - ansible.builtin.command: "/home/{{ human_admin_user }}/install_omz.sh" + remote_user: ansible + ansible.builtin.command: "/home/{{ human_admin_user }}/install_omz.sh {{ human_admin_user }}" changed_when: true - vars: - name: Configure oh my zsh, by pushing the config file remote_user: ansible