Skip to content

Commit 840b1e0

Browse files
committed
working version
1 parent 42a016f commit 840b1e0

File tree

3 files changed

+10
-51
lines changed

3 files changed

+10
-51
lines changed

.github/workflows/gcp-vm.yaml

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,11 @@ jobs:
2727
ansible --version
2828
ansible-galaxy collection install google.cloud
2929
30-
# - name: Save SSH key for ansible
31-
# run: |
32-
# echo "${{ secrets.GCP_SSH_PRIVATE_KEY }}" > ~/.ssh/id_ed25519
33-
# chmod 600 ~/id_ed25519
30+
# Had to do it outside Ansible because the builtin copy module breaks the ssh file somehow
31+
- name: Save SSH key for ansible
32+
run: |
33+
echo "${{ secrets.GCP_SSH_PRIVATE_KEY }}" > ${{ env.SSH_PATH }}
34+
chmod 600 ${{ env.SSH_PATH }}
3435
3536
- name: Extract branch/tag name
3637
id: extract
@@ -53,20 +54,16 @@ jobs:
5354
OWNER_LABEL: ${{ env.OWNER_LABEL }}
5455
TEAM_LABEL: ${{ env.TEAM_LABEL }}
5556
SSH_USER: ${{ env.SSH_USER }}
57+
SSH_PATH: ${{ env.SSH_PATH }}
5658
TSB_SYNC_PASS: ${{ secrets.TSB_SYNC_PASS }}
5759
TSB_SYNC_USR: ${{ secrets.TSB_SYNC_USR }}
5860
run: |
5961
ansible-playbook -i "localhost ansible_connection=local", ansible/playbook-gcp-vm-create.yaml
6062
61-
- name: Check ssh file
62-
run: |
63-
ssh-keygen -l -f ~/id_ed25519
64-
6563
- name: Run Ansible playbook on the VM
6664
run: |
6765
ansible-playbook -i /tmp/inventory.ini ansible/playbook.yaml
6866
69-
7067
- name: Always delete VM after failure
7168
if: failure()
7269
env:

ansible/playbook-gcp-vm-create.yaml

Lines changed: 2 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
ssh_private_key: "{{ lookup('env', 'GCP_SSH_PRIVATE_KEY') }}"
1313
ssh_public_key: "{{ lookup('env', 'GCP_SSH_PUBLIC_KEY') }}"
1414
ansible_user: "{{ ssh_user }}"
15-
ssh_path: "~/id_ed25519"
15+
ssh_path: "{{ lookup('env', 'SSH_PATH') }}"
1616
tasks:
1717
- name: Create GCP Auth file
1818
ansible.builtin.copy:
@@ -26,41 +26,6 @@
2626
cmd: "{{ ansible_playbook_python }} -m pip install requests google-auth google-cloud-storage"
2727
changed_when: true
2828

29-
# - name: Ensure ~/.ssh directory exists
30-
# file:
31-
# path: /home/runner/.ssh
32-
# state: directory
33-
34-
- name: Save SSH private key
35-
copy:
36-
content: "{{ lookup('env', 'GCP_SSH_PRIVATE_KEY') }}"
37-
dest: "{{ ssh_path }}"
38-
mode: '0600'
39-
40-
# - name: Configure SSH client
41-
# copy:
42-
# content: |
43-
# Host *
44-
# StrictHostKeyChecking no
45-
# UserKnownHostsFile=/dev/null
46-
# dest: "~/.ssh/config"
47-
# mode: 0600
48-
49-
# - name: Who am I
50-
# command: whoami
51-
# register: whoami_out
52-
53-
# - debug:
54-
# var: whoami_out.stdout
55-
56-
- name: Stat SSH private key
57-
stat:
58-
path: "{{ ssh_path }}"
59-
register: key_stat
60-
61-
- debug:
62-
var: key_stat.stat
63-
6429
- name: Create GCP VM instance
6530
google.cloud.gcp_compute_instance:
6631
state: present
@@ -89,7 +54,7 @@
8954
debug:
9055
var: vm_result.name
9156

92-
- name: Get external IP of the VM
57+
- name: Get VM's external IP
9358
set_fact:
9459
external_ip: "{{ vm_result.networkInterfaces[0].accessConfigs[0].natIP }}"
9560

@@ -104,7 +69,3 @@
10469
import_tasks: tasks/task-vm-check-ready.yaml
10570
vars:
10671
wait_for_ssh_on: "{{ external_ip }}"
107-
108-
- name: DEBUG print ssh_private_key
109-
debug:
110-
msg: "{{ ssh_private_key.split('\n') }}"

github-deploy.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ IMAGE_NAME: tsb-1-12-0
33
OWNER_LABEL: ric
44
TEAM_LABEL: eng_cre
55
SSH_USER: ubuntu
6+
SSH_PATH: ~/.ssh/id_ed25519
67
GCP_PROJECT_ID: tsb-vm-images-repo
78
GCP_ZONE: europe-west9-a
89
TSB_SCENARIO: main
910
TSB_TOPOLOGY: tsb-training
1011
TSB_INSTALL_METHOD: tctl
11-
TSB_VERSION: 1.12.2
12+
TSB_VERSION: 1.12.2

0 commit comments

Comments
 (0)