1
0
Fork 0
mirror of https://github.com/roles-ansible/ansible_role_weechat.git synced 2024-08-16 13:09:48 +02:00
ansible_role_weechat/tasks/configure_custom_config.yml

102 lines
3.3 KiB
YAML

---
- name: Create ssh key pair (if needed)
become: true
community.crypto.openssh_keypair:
path: "{{ weechat__home_directory }}/.ssh/id_ed25519"
type: ed25519
owner: "{{ weechat__user }}"
register: ssh_key_pair
when: weechat__custom_gen_ssh_key_pair | bool
- name: Print ssh public key to user
ansible.builtin.pause:
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.
when:
- weechat__custom_gen_ssh_key_pair | bool
- ssh_key_pair.changed
- name: Add git repo to save.directory globally for root
become: true
community.general.git_config:
name: safe.directory
scope: global
value: "{{ weechat__home_directory }}/.weechat"
register: save_directory
- name: "Add git repo to save.directory globally for {{ weechat__user }}"
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 }}"
changed_when: save_user_directory.changed | bool
- name: "Change git repo owner to root"
become: true
ansible.builtin.file:
path: "{{ weechat__home_directory }}/.weechat"
recurse: true
owner: "root"
changed_when: ssh_key_pair.changed | bool or save_directory.changed | bool
when: not weechat__custom_private_repo | bool
- name: Clone or update private git repository
become: true
when: not weechat__custom_private_repo | bool
block:
- name: Try to download/update git repo
ansible.builtin.git:
repo: "{{ weechat__custom_private_repo }}"
dest: "{{ weechat__home_directory }}/.weechat"
version: "{{ weechat__custom_config.version | default('main') }}"
accept_hostkey: true
update: true
ssh_opts: "-i {{ weechat__home_directory }}/.ssh/id_ed25519"
rescue:
- name: Wait until you fixed remote git issues
ansible.builtin.pause:
prompt: "Please fix the issue with your git repository and try again"
- name: Try to download/update git repo again
ansible.builtin.git:
repo: "{{ weechat__custom_private_repo }}"
dest: "{{ weechat__home_directory }}/.weechat"
version: "{{ weechat__custom_config.version | default('main') }}"
accept_hostkey: true
update: true
ssh_opts: "-i {{ weechat__home_directory }}/.ssh/id_ed25519"
- name: "Change git repo owner to {{ weechat__user }}"
become: true
ansible.builtin.file:
path: "{{ weechat__home_directory }}/.weechat"
recurse: true
owner: "{{ weechat__user }}"
changed_when: ssh_key_pair.changed | bool or save_directory.changed | bool
when: not weechat__custom_private_repo | bool