Skip to content

Commit

Permalink
ansible: remove hardcoded username and replace it with jinja var value
Browse files Browse the repository at this point in the history
  • Loading branch information
gelocraft committed Dec 11, 2024
1 parent aba6efc commit d383033
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 17 deletions.
16 changes: 5 additions & 11 deletions ansible/playbook.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
---
- hosts: all
become: yes
vars:
username: gelocraft
pre_tasks:
- name: Update and Upgrade packages
when: ansible_distribution in ["Debian", "Ubuntu"]
Expand All @@ -9,24 +12,15 @@

- name: Create User
ansible.builtin.user:
name: geloman
name: "{{ username }}"
groups: sudo
create_home: true

- name: Clone user dotfiles
ansible.builtin.git:
repo: "https://github.com/gelocraft/dotfiles"
dest: "~/.dotfiles"
become_user: geloman

- name: Change dotfiles remote origin
ansible.builtin.git:
repo: "[email protected]:geloman-likes-rust/dotfiles"
dest: "~/.dotfiles"
remote: origin
clone: no
update: no
become_user: geloman
become_user: "{{ username }}"

roles:
- common
Expand Down
2 changes: 1 addition & 1 deletion ansible/roles/git/tasks/setup.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
src: "~/.dotfiles/.gitconfig"
dest: "~/.gitconfig"
state: link
become_user: geloman
become_user: "{{ username }}"
4 changes: 2 additions & 2 deletions ansible/roles/neovim/tasks/setup.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
path: "~/.config"
state: directory
mode: "0755"
become_user: geloman
become_user: "{{ username }}"

- name: Symlink neovim config
ansible.builtin.file:
src: "~/.dotfiles/nvim"
dest: "~/.config/nvim"
state: link
become_user: geloman
become_user: "{{ username }}"
2 changes: 1 addition & 1 deletion ansible/roles/tmux/tasks/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
src: "~/.dotfiles/tmux/.tmux.conf"
dest: "~/.tmux.conf"
state: link
become_user: geloman
become_user: "{{ username }}"
4 changes: 2 additions & 2 deletions ansible/roles/zsh/tasks/setup.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
src: "~/.dotfiles/zsh/.zshrc"
dest: "~/.zshrc"
state: link
become_user: geloman
become_user: "{{ username }}"

- name: Set ZSH as default shell
ansible.builtin.user:
name: geloman
name: "{{ username }}"
shell: /usr/bin/zsh

0 comments on commit d383033

Please sign in to comment.