From 8df370f630efe6290e00abb383efbfe96c54b464 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20Grondek?= Date: Fri, 10 May 2024 20:29:51 +0200 Subject: [PATCH] Add option to use https/ssh git repositories --- localhost.yml | 11 +++++++++++ roles/desktop/tasks/dotfiles.yml | 2 +- roles/desktop/vars/main.yml | 3 --- roles/dwm/tasks/dwm.yml | 2 +- roles/dwm/tasks/polybar.yml | 2 +- roles/dwm/tasks/st-term.yml | 2 +- roles/dwm/vars/main.yml | 9 --------- roles/prepare/tasks/git-repos.yml | 14 ++++++++++++++ roles/prepare/tasks/main.yml | 2 ++ 9 files changed, 31 insertions(+), 16 deletions(-) delete mode 100644 roles/desktop/vars/main.yml delete mode 100644 roles/dwm/vars/main.yml create mode 100644 roles/prepare/tasks/git-repos.yml diff --git a/localhost.yml b/localhost.yml index bda7b9f..7034ac2 100644 --- a/localhost.yml +++ b/localhost.yml @@ -22,3 +22,14 @@ vars: desktop_src_dir: "{{ ansible_user_dir }}/src/desktop" arch_src_dir: "{{ ansible_user_dir }}/src/arch" + git_repos: + ssh: + dwm: ssh://git@git.grondek.dev:2222/pgrondek/dwm.git + dotfiles: ssh://git@git.grondek.dev:2222/pgrondek/dotfiles.git + polybar: ssh://git@git.grondek.dev:2222/pgrondek/polybar-dwm.git + st: ssh://git@git.grondek.dev:2222/pgrondek/stterm.git + https: + dwm: https://git.grondek.dev/pgrondek/dwm.git + dotfiles: https://git.grondek.dev/pgrondek/dotfiles.git + polybar: https://git.grondek.dev/pgrondek/polybar-dwm.git + st: https://git.grondek.dev/pgrondek/stterm.git diff --git a/roles/desktop/tasks/dotfiles.yml b/roles/desktop/tasks/dotfiles.yml index 92bae03..348c5bf 100644 --- a/roles/desktop/tasks/dotfiles.yml +++ b/roles/desktop/tasks/dotfiles.yml @@ -1,7 +1,7 @@ --- - name: checkout dotfiles git: - repo: "{{ dotfiles.repo }}" + repo: "{{ git.dotfiles }}" dest: "{{ desktop_src_dir }}/dotfiles" clone: yes update: yes diff --git a/roles/desktop/vars/main.yml b/roles/desktop/vars/main.yml deleted file mode 100644 index 2c121d7..0000000 --- a/roles/desktop/vars/main.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -dotfiles: - repo: ssh://git@git.grondek.dev:2222/pgrondek/dotfiles.git diff --git a/roles/dwm/tasks/dwm.yml b/roles/dwm/tasks/dwm.yml index e9398d4..f1aa9df 100644 --- a/roles/dwm/tasks/dwm.yml +++ b/roles/dwm/tasks/dwm.yml @@ -29,7 +29,7 @@ - name: checkout dwm git: - repo: "{{ dwm.repo }}" + repo: "{{ git.dwm }}" dest: "{{ desktop_src_dir }}/dwm" clone: yes update: yes diff --git a/roles/dwm/tasks/polybar.yml b/roles/dwm/tasks/polybar.yml index d0d8bd8..03a4b41 100644 --- a/roles/dwm/tasks/polybar.yml +++ b/roles/dwm/tasks/polybar.yml @@ -46,7 +46,7 @@ - name: "polybar: checkout" git: - repo: "{{ polybar.repo }}" + repo: "{{ git.polybar }}" dest: "{{ desktop_src_dir }}/polybar" clone: yes update: yes diff --git a/roles/dwm/tasks/st-term.yml b/roles/dwm/tasks/st-term.yml index d64386d..a2ff183 100644 --- a/roles/dwm/tasks/st-term.yml +++ b/roles/dwm/tasks/st-term.yml @@ -25,7 +25,7 @@ - name: checkout st git: - repo: "{{ st.repo }}" + repo: "{{ git.st }}" dest: "{{ desktop_src_dir }}/stterm" clone: yes update: yes diff --git a/roles/dwm/vars/main.yml b/roles/dwm/vars/main.yml deleted file mode 100644 index fc3278c..0000000 --- a/roles/dwm/vars/main.yml +++ /dev/null @@ -1,9 +0,0 @@ ---- -dwm: - repo: ssh://git@git.grondek.dev:2222/pgrondek/dwm.git -st: - repo: ssh://git@git.grondek.dev:2222/pgrondek/stterm.git -dwmstatus: - repo: https://git.grondek.dev/pgrondek/dwmstatus.git -polybar: - repo: ssh://git@git.grondek.dev:2222/pgrondek/polybar-dwm.git diff --git a/roles/prepare/tasks/git-repos.yml b/roles/prepare/tasks/git-repos.yml new file mode 100644 index 0000000..dcaf1c6 --- /dev/null +++ b/roles/prepare/tasks/git-repos.yml @@ -0,0 +1,14 @@ +- name: Check if ssh keys exists + stat: + path: "{{ ansible_user_dir }}/.ssh/id_rsa" + register: ssh_key + +- name: Use SSH repositories + set_fact: + git: "{{ git_repos.ssh }}" + when: ssh_key.stat.exists + +- name: Use HTTPS repositories + set_fact: + git: "{{ git_repos.https }}" + when: not ssh_key.stat.exists diff --git a/roles/prepare/tasks/main.yml b/roles/prepare/tasks/main.yml index 97284fc..0953fda 100644 --- a/roles/prepare/tasks/main.yml +++ b/roles/prepare/tasks/main.yml @@ -4,3 +4,5 @@ - import_tasks: arch.yml when: ansible_distribution == "Archlinux" + +- import_tasks: git-repos.yml