2017-02-16 03:41:30 +08:00
|
|
|
---
|
2023-11-07 21:39:17 +08:00
|
|
|
- name: Check if the passphrase inputs match
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- "{{ passphrase == confirm_passphrase }}"
|
|
|
|
fail_msg: "Passphrase inputs do not match"
|
|
|
|
when: passphrase != confirm_passphrase
|
|
|
|
|
2023-11-13 20:39:10 +08:00
|
|
|
- import_tasks: generate_key.yaml
|
2017-02-18 03:24:14 +08:00
|
|
|
when: generate_new_key | default(True)
|
2017-02-16 03:41:30 +08:00
|
|
|
|
2017-02-18 03:24:14 +08:00
|
|
|
- name: Ensure that ssh connection key is defined
|
|
|
|
assert:
|
|
|
|
that: ssh_connection_key is defined
|
2017-02-16 04:02:00 +08:00
|
|
|
|
2017-02-16 03:41:30 +08:00
|
|
|
- name: Set Authorized key(s) to the authorized keys file
|
2023-11-07 21:39:17 +08:00
|
|
|
become: true
|
2017-02-18 03:24:14 +08:00
|
|
|
when: ssh_connection_key is defined
|
2017-02-16 03:41:30 +08:00
|
|
|
authorized_key:
|
|
|
|
exclusive: '{{ is_exclusive }}'
|
2017-02-16 04:02:00 +08:00
|
|
|
user: '{{ ssh_host_user }}'
|
2017-02-16 03:41:30 +08:00
|
|
|
state: present
|
2023-11-07 21:39:17 +08:00
|
|
|
path: '/home/{{ ssh_host_user }}/{{ authorized_keys_path }}'
|
2017-02-16 03:41:30 +08:00
|
|
|
manage_dir: '{{ should_manage_dir }}'
|
2017-02-18 03:24:14 +08:00
|
|
|
key: "{{ ssh_connection_key }}"
|
|
|
|
|
|
|
|
- name: copy
|
|
|
|
when: generate_new_key != true
|
|
|
|
copy:
|
|
|
|
content: "{{ ssh_connection_key }}"
|
|
|
|
dest: "{{ ssh_key_path }}"
|
|
|
|
|
|
|
|
- name: Add deployment key
|
|
|
|
when: ssh_deployment_key is defined
|
|
|
|
become: yes
|
|
|
|
become_user: root
|
|
|
|
authorized_key:
|
|
|
|
user: '{{ ssh_host_user }}'
|
|
|
|
state: present
|
2023-11-07 21:39:17 +08:00
|
|
|
path: '/home/{{ ssh_host_user }}/{{ authorized_keys_path }}'
|
2017-02-18 03:24:14 +08:00
|
|
|
manage_dir: '{{ should_manage_dir }}'
|
|
|
|
key: "{{ ssh_deployment_key }}"
|
2017-02-16 03:41:30 +08:00
|
|
|
|
2023-11-15 03:08:19 +08:00
|
|
|
- name: Set ownership and permissions for SSH private key
|
|
|
|
ansible.builtin.file:
|
|
|
|
path: '/home/{{ ssh_host_user }}/{{ ssh_key_path }}'
|
|
|
|
owner: 1000
|
|
|
|
group: 1000
|
|
|
|
mode: 0600
|
|
|
|
delegate_to: localhost
|