2020-03-12 04:01:23 +01:00
|
|
|
---
|
2023-10-30 00:21:01 +01:00
|
|
|
- name: Create ssh key pair (if needed) # noqa: H1901
|
2020-03-12 04:37:54 +01:00
|
|
|
become: true
|
2021-05-27 16:03:41 +02:00
|
|
|
community.crypto.openssh_keypair:
|
2021-05-27 16:18:04 +02:00
|
|
|
path: "{{ weechat__home_directory }}/.ssh/id_ed25519"
|
2023-10-30 00:21:01 +01:00
|
|
|
type: 'ed25519'
|
2021-05-27 16:18:04 +02:00
|
|
|
owner: "{{ weechat__user }}"
|
2020-03-12 04:01:23 +01:00
|
|
|
register: ssh_key_pair
|
2021-05-27 16:18:04 +02:00
|
|
|
when: weechat__custom_gen_ssh_key_pair | bool
|
2020-03-12 04:01:23 +01:00
|
|
|
|
2023-03-01 21:27:09 +01:00
|
|
|
- name: Print ssh public key to user
|
2021-05-27 14:14:13 +02:00
|
|
|
ansible.builtin.pause:
|
2020-03-12 04:37:54 +01:00
|
|
|
prompt: |
|
|
|
|
We generated a new ssh key pair for you.
|
|
|
|
Please use the following public key as deployment key
|
|
|
|
to your private git repository with your own weechat config.
|
|
|
|
|
|
|
|
Private git repositorys are not public available and
|
|
|
|
you need some sort of authorisation method to verify
|
|
|
|
that you are allowed to clone your private repo.
|
|
|
|
|
|
|
|
Your ssh public key come here...
|
|
|
|
|
|
|
|
|
|
|
|
{{ ssh_key_pair.public_key }}
|
|
|
|
|
|
|
|
|
|
|
|
Please be aware, that this role do not commit or
|
|
|
|
push any local changes and you have to do this
|
|
|
|
manually by yourself.
|
2020-03-12 04:01:23 +01:00
|
|
|
when:
|
2021-06-03 15:03:44 +02:00
|
|
|
- weechat__custom_gen_ssh_key_pair | bool
|
2020-03-12 04:01:23 +01:00
|
|
|
- ssh_key_pair.changed
|
2020-03-12 22:44:15 +01:00
|
|
|
|
2023-10-30 00:21:01 +01:00
|
|
|
- name: Add git repo to save.directory globally for root # noqa: H1901
|
2023-08-01 00:12:01 +02:00
|
|
|
become: true
|
|
|
|
community.general.git_config:
|
|
|
|
name: safe.directory
|
|
|
|
scope: global
|
|
|
|
value: "{{ weechat__home_directory }}/.weechat"
|
|
|
|
register: save_directory
|
|
|
|
|
2023-10-30 00:21:01 +01:00
|
|
|
- name: "Add git repo to save.directory globally for {{ weechat__user }}" # noqa: H1901
|
2023-08-01 00:12:01 +02:00
|
|
|
become: true
|
|
|
|
community.general.git_config:
|
|
|
|
file: "{{ weechat__home_directory }}/.gitconfig"
|
|
|
|
name: safe.directory
|
|
|
|
scope: file
|
|
|
|
value: "{{ weechat__home_directory }}/.weechat"
|
|
|
|
register: save_user_directory
|
|
|
|
|
|
|
|
- name: "Change git repo owner to {{ weechat__user }}"
|
|
|
|
become: true
|
|
|
|
ansible.builtin.file:
|
|
|
|
path: "{{ weechat__home_directory }}/.gitconfig"
|
|
|
|
recurse: false
|
|
|
|
owner: "{{ weechat__user }}"
|
2023-10-30 00:21:01 +01:00
|
|
|
mode: 'u=rwX,g=rX,o='
|
2023-08-01 00:12:01 +02:00
|
|
|
changed_when: save_user_directory.changed | bool
|
|
|
|
|
2023-03-01 21:27:09 +01:00
|
|
|
- name: "Change git repo owner to root"
|
2020-03-12 22:44:15 +01:00
|
|
|
become: true
|
2023-03-01 21:27:09 +01:00
|
|
|
ansible.builtin.file:
|
|
|
|
path: "{{ weechat__home_directory }}/.weechat"
|
|
|
|
recurse: true
|
|
|
|
owner: "root"
|
2023-10-30 00:21:01 +01:00
|
|
|
group: 'root'
|
|
|
|
mode: 'u=rwX,g=rX,o='
|
2023-08-01 00:12:01 +02:00
|
|
|
changed_when: ssh_key_pair.changed | bool or save_directory.changed | bool
|
2023-03-01 21:27:09 +01:00
|
|
|
when: not weechat__custom_private_repo | bool
|
|
|
|
|
|
|
|
- name: Clone or update private git repository
|
|
|
|
become: true
|
|
|
|
when: not weechat__custom_private_repo | bool
|
2020-03-14 16:24:59 +01:00
|
|
|
block:
|
2023-03-01 21:27:09 +01:00
|
|
|
- name: Try to download/update git repo
|
2021-05-27 14:14:13 +02:00
|
|
|
ansible.builtin.git:
|
2021-05-27 16:18:04 +02:00
|
|
|
repo: "{{ weechat__custom_private_repo }}"
|
|
|
|
dest: "{{ weechat__home_directory }}/.weechat"
|
2023-03-01 21:27:09 +01:00
|
|
|
version: "{{ weechat__custom_config.version | default('main') }}"
|
2021-05-27 14:14:13 +02:00
|
|
|
accept_hostkey: true
|
|
|
|
update: true
|
2021-05-27 16:18:04 +02:00
|
|
|
ssh_opts: "-i {{ weechat__home_directory }}/.ssh/id_ed25519"
|
2020-03-14 16:24:59 +01:00
|
|
|
rescue:
|
2023-03-01 21:27:09 +01:00
|
|
|
- name: Wait until you fixed remote git issues
|
2022-04-06 00:15:06 +02:00
|
|
|
ansible.builtin.pause:
|
2020-03-14 16:24:59 +01:00
|
|
|
prompt: "Please fix the issue with your git repository and try again"
|
|
|
|
|
2023-03-01 21:27:09 +01:00
|
|
|
- name: Try to download/update git repo again
|
2021-05-27 14:14:13 +02:00
|
|
|
ansible.builtin.git:
|
2021-05-27 16:18:04 +02:00
|
|
|
repo: "{{ weechat__custom_private_repo }}"
|
|
|
|
dest: "{{ weechat__home_directory }}/.weechat"
|
2023-03-01 21:27:09 +01:00
|
|
|
version: "{{ weechat__custom_config.version | default('main') }}"
|
2021-05-27 14:14:13 +02:00
|
|
|
accept_hostkey: true
|
|
|
|
update: true
|
2021-05-27 16:18:04 +02:00
|
|
|
ssh_opts: "-i {{ weechat__home_directory }}/.ssh/id_ed25519"
|
2021-05-27 16:03:41 +02:00
|
|
|
|
2023-03-01 21:27:09 +01:00
|
|
|
- name: "Change git repo owner to {{ weechat__user }}"
|
2021-05-27 16:03:41 +02:00
|
|
|
become: true
|
|
|
|
ansible.builtin.file:
|
2021-05-27 16:18:04 +02:00
|
|
|
path: "{{ weechat__home_directory }}/.weechat"
|
2021-05-27 16:03:41 +02:00
|
|
|
recurse: true
|
2021-05-27 16:18:04 +02:00
|
|
|
owner: "{{ weechat__user }}"
|
2023-10-30 00:21:01 +01:00
|
|
|
group: 'root'
|
|
|
|
mode: 'u=rwX,g=rX,o='
|
2023-08-01 00:12:01 +02:00
|
|
|
changed_when: ssh_key_pair.changed | bool or save_directory.changed | bool
|
2021-05-27 16:18:04 +02:00
|
|
|
when: not weechat__custom_private_repo | bool
|