summaryrefslogtreecommitdiffstats
path: root/roles/pve-lxc-ssh/tasks
diff options
context:
space:
mode:
Diffstat (limited to 'roles/pve-lxc-ssh/tasks')
-rw-r--r--roles/pve-lxc-ssh/tasks/main.yml39
1 files changed, 24 insertions, 15 deletions
diff --git a/roles/pve-lxc-ssh/tasks/main.yml b/roles/pve-lxc-ssh/tasks/main.yml
index f5d402bc..8a1dd095 100644
--- a/roles/pve-lxc-ssh/tasks/main.yml
+++ b/roles/pve-lxc-ssh/tasks/main.yml
@@ -16,31 +16,42 @@
tags:
- "molecule-notest"
-- name: "Install openssh and configure openssh"
+- name: "Install openssh"
become: true
tags:
- "molecule-notest"
when: pve_lxc_ssh_check.rc != 0
+ ansible.builtin.command:
+ cmd: >
+ pct exec {{ pve_lxc_id }} -- sh -c '
+ . /etc/os-release;
+ case $ID in
+ alpine) apk add --no-cache openssh ;;
+ debian|ubuntu) apt-get install -y openssh-server ;;
+ *) echo "Unsupported distro: $ID" && exit 1 ;;
+ esac;'
+ changed_when: true
+
+- name: "Configure openssh"
+ become: true
+ tags:
+ - "molecule-notest"
block:
- - name: "Install openssh"
+ - name: "Deploy ssh host private key"
+ no_log: true
ansible.builtin.command:
cmd: >
- pct exec {{ pve_lxc_id }} -- sh -c '
- . /etc/os-release;
- case $ID in
- alpine) apk add --no-cache openssh ;;
- debian|ubuntu) apt-get install -y openssh-server ;;
- *) echo "Unsupported distro: $ID" && exit 1 ;;
- esac;'
+ pct exec {{ pve_lxc_id }} -- sh -c
+ 'umask 077; cat > /etc/ssh/ssh_host_ed25519_key'
+ stdin: "{{ pve_lxc_ssh_private_key | trim }}\n"
changed_when: true
- - name: "Generate ssh host keys"
- become: true
+ - name: "Deploy ssh host public key"
ansible.builtin.command:
cmd: >
pct exec {{ pve_lxc_id }} -- sh -c
- '[ -f /etc/ssh/ssh_host_ed25519_key ] && exit 0;
- ssh-keygen -q -t ed25519 -f /etc/ssh/ssh_host_ed25519_key -C "" -N "";'
+ 'cat > /etc/ssh/ssh_host_ed25519_key.pub; chmod 0644 /etc/ssh/ssh_host_ed25519_key.pub'
+ stdin: "{{ pve_lxc_ssh_public_key | trim }}\n"
changed_when: true
- name: "Render sshd_config"
@@ -50,7 +61,6 @@
mode: "0600"
- name: "Push sshd_config into container"
- become: true
ansible.builtin.command:
cmd: pct push {{ pve_lxc_id }} /tmp/sshd_config_{{ pve_lxc_id }} /etc/ssh/sshd_config --perms 0640
changed_when: true
@@ -61,7 +71,6 @@
state: absent
- name: "Enable and start sshd"
- become: true
ansible.builtin.command:
cmd: >
pct exec {{ pve_lxc_id }} -- sh -c