From 05c20a67e9ece28a7b7e15a187cb72eb2f7b44ad Mon Sep 17 00:00:00 2001 From: Noah Knegt Date: Fri, 31 Mar 2023 10:12:29 +0200 Subject: [PATCH 1/7] Fix and test ssh key Signed-off-by: Noah Knegt --- .drone.yml | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/.drone.yml b/.drone.yml index f20f31b..37bf7a8 100644 --- a/.drone.yml +++ b/.drone.yml @@ -17,12 +17,17 @@ steps: - name: setup ssh key image: alpine:latest commands: - - mkdir -p /drone/src/.ssh - - echo "$SSH_KEY" > /drone/src/.ssh/id_ed25519 - - chmod 600 /drone/src/.ssh/id_ed25519 + - mkdir -p $HOME/.ssh + - echo "$SSH_KEY" > $HOME/.ssh/id_ed25519 + - chmod 600 $HOME/.ssh/id_ed25519 + - ssh-keyscan -p 4422 vps.noahknegt.com > $HOME/.ssh/known_hosts + - ssh -p 4422 vps.noahknegt.com "echo 'SSH connection established'" environment: SSH_KEY: from_secret: ssh_key + volumes: + - name: ssh_key + path: $HOME/.ssh when: event: - push @@ -32,9 +37,16 @@ steps: - name: ansible apply image: cytopia/ansible:latest-tools commands: - - ansible-playbook -i inventory/hosts.yml site.yml --private-key /drone/src/.ssh/id_ed25519 + - ansible-playbook -i inventory/hosts.yml site.yml + volumes: + - name: ssh_key + path: $HOME/.ssh when: event: - push branch: - master + +volumes: + - name: ssh_key + temp: {} -- 2.49.1 From eabd5b39a7ab2190bc8e8e9a4ec7fe6a21ccc752 Mon Sep 17 00:00:00 2001 From: Noah Knegt Date: Fri, 31 Mar 2023 10:12:48 +0200 Subject: [PATCH 2/7] Remove the need for master branch only Signed-off-by: Noah Knegt --- .drone.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.drone.yml b/.drone.yml index 37bf7a8..bb9ea3a 100644 --- a/.drone.yml +++ b/.drone.yml @@ -28,11 +28,6 @@ steps: volumes: - name: ssh_key path: $HOME/.ssh - when: - event: - - push - branch: - - master - name: ansible apply image: cytopia/ansible:latest-tools -- 2.49.1 From f9d25cd0f4afcd2a121f952a8431a84ef7f799be Mon Sep 17 00:00:00 2001 From: Noah Knegt Date: Fri, 31 Mar 2023 10:22:57 +0200 Subject: [PATCH 3/7] Fix the volume mounts Signed-off-by: Noah Knegt --- .drone.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.drone.yml b/.drone.yml index bb9ea3a..3027653 100644 --- a/.drone.yml +++ b/.drone.yml @@ -17,17 +17,17 @@ steps: - name: setup ssh key image: alpine:latest commands: - - mkdir -p $HOME/.ssh - - echo "$SSH_KEY" > $HOME/.ssh/id_ed25519 - - chmod 600 $HOME/.ssh/id_ed25519 - - ssh-keyscan -p 4422 vps.noahknegt.com > $HOME/.ssh/known_hosts + - mkdir -p /root/.ssh + - echo "$SSH_KEY" > /root/.ssh/id_ed25519 + - chmod 600 /root/.ssh/id_ed25519 + - ssh-keyscan -p 4422 vps.noahknegt.com > /root/.ssh/known_hosts - ssh -p 4422 vps.noahknegt.com "echo 'SSH connection established'" environment: SSH_KEY: from_secret: ssh_key volumes: - name: ssh_key - path: $HOME/.ssh + path: /root/.ssh - name: ansible apply image: cytopia/ansible:latest-tools @@ -35,7 +35,7 @@ steps: - ansible-playbook -i inventory/hosts.yml site.yml volumes: - name: ssh_key - path: $HOME/.ssh + path: /root/.ssh when: event: - push -- 2.49.1 From b55522d6885df64b0c9821876a91f3bc044618c9 Mon Sep 17 00:00:00 2001 From: Noah Knegt Date: Fri, 31 Mar 2023 10:24:40 +0200 Subject: [PATCH 4/7] Use the debian image for ssh keys Signed-off-by: Noah Knegt --- .drone.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.drone.yml b/.drone.yml index 3027653..9c6f222 100644 --- a/.drone.yml +++ b/.drone.yml @@ -15,7 +15,7 @@ steps: - ansible-lint . - name: setup ssh key - image: alpine:latest + image: debian:latest commands: - mkdir -p /root/.ssh - echo "$SSH_KEY" > /root/.ssh/id_ed25519 -- 2.49.1 From aefd6d74a445e286e0cee01b7dbc51413a83712e Mon Sep 17 00:00:00 2001 From: Noah Knegt Date: Fri, 31 Mar 2023 10:26:43 +0200 Subject: [PATCH 5/7] Use the right image with all ssh tools Signed-off-by: Noah Knegt --- .drone.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.drone.yml b/.drone.yml index 9c6f222..e70329b 100644 --- a/.drone.yml +++ b/.drone.yml @@ -15,7 +15,7 @@ steps: - ansible-lint . - name: setup ssh key - image: debian:latest + image: cytopia/ansible:latest-tools commands: - mkdir -p /root/.ssh - echo "$SSH_KEY" > /root/.ssh/id_ed25519 -- 2.49.1 From 3ab5c7236acbbd5fae342486f5bf0f66df405c6e Mon Sep 17 00:00:00 2001 From: Noah Knegt Date: Fri, 31 Mar 2023 10:27:35 +0200 Subject: [PATCH 6/7] Test ssh with the correct user Signed-off-by: Noah Knegt --- .drone.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.drone.yml b/.drone.yml index e70329b..250cc85 100644 --- a/.drone.yml +++ b/.drone.yml @@ -21,7 +21,7 @@ steps: - echo "$SSH_KEY" > /root/.ssh/id_ed25519 - chmod 600 /root/.ssh/id_ed25519 - ssh-keyscan -p 4422 vps.noahknegt.com > /root/.ssh/known_hosts - - ssh -p 4422 vps.noahknegt.com "echo 'SSH connection established'" + - ssh -p 4422 noahk@vps.noahknegt.com "echo 'SSH connection established'" environment: SSH_KEY: from_secret: ssh_key -- 2.49.1 From f786109c5e026601b9564910191da2eeb3cdb59c Mon Sep 17 00:00:00 2001 From: Noah Knegt Date: Fri, 31 Mar 2023 10:28:59 +0200 Subject: [PATCH 7/7] Only do ssh keys on master Signed-off-by: Noah Knegt --- .drone.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.drone.yml b/.drone.yml index 250cc85..d02a7f2 100644 --- a/.drone.yml +++ b/.drone.yml @@ -21,13 +21,17 @@ steps: - echo "$SSH_KEY" > /root/.ssh/id_ed25519 - chmod 600 /root/.ssh/id_ed25519 - ssh-keyscan -p 4422 vps.noahknegt.com > /root/.ssh/known_hosts - - ssh -p 4422 noahk@vps.noahknegt.com "echo 'SSH connection established'" environment: SSH_KEY: from_secret: ssh_key volumes: - name: ssh_key path: /root/.ssh + when: + event: + - push + branch: + - master - name: ansible apply image: cytopia/ansible:latest-tools -- 2.49.1